mac wordpress php7,Mac 下基于 wordpress 搭建个人博客系统
一、前言
這里說的是自己從 wordpress 源碼開始搭建一個個人博客系統。當然,很多云端已經直接提供了在線安裝的方式,這個就不在本文的討論范圍之內了。
二、關于 wordpress
wordpress是一款個人博客系統,并逐步演化成一款內容管理系統軟件,它是使用PHP語言和MySQL數據庫開發的,用戶可以在支持 PHP 和 MySQL數據庫的服務器上使用自己的博客。
總之是為眾多的開源博客系統之一,也絕對是一部良心之作。在這里向作者以及貢獻者致敬。本文主要講述的是從 wordpress 源碼進行安裝,當然是要從 wordpress 官網這里去將其下載下來的。下載下來的是一個壓約縮包,需要我們自己將其解壓出來。
三、安裝 wordpress
1.確認基礎設施
wordpress 雖然只是一個個人博客系統,但其也是一個服務端系統。要安裝 wordpress 就需要先安裝相應的基礎設施,php,mysql 以及 apache。不過這些在 Mac 上已經安裝好了。我們要做的是執行相應的命令行查看一下版本是否符合。
查看Apache版本
$ apachectl -version
Server version: Apache/2.4.34 (Unix)
Server built: Feb 22 2019 19:30:04
相看php版本
$ php -v
PHP 7.1.23 (cli) (built: Feb 22 2019 22:08:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
2.配置并啟動相應服務
2.1 開啟 Apache 服務
啟動 Apache
$ sudo apachectl start
關閉 Apache
$ sudo apachectl stop
重啟 Apache
$ sudo apachectl restart
2.2 起用 php
起用 php
開啟PHP,需要修改Apache配置文件,終端下(當然,你也可以直接在 Finder 中找到路徑并用文本編輯器進行):
sudo vim /etc/apache2/httpd.conf
去掉如下配置的注釋即為起動 php。
LoadModule php7_module libexec/apache2/libphp7.so
結果如下圖
2.3 修改 Apache 的目錄
默認情況下 Apache 的目錄為 /Library/WebServer/Documents,我們當然希望 wordpress 應該工作在自己的獨立目錄下。假設我們已經把面下載并解壓好的 wordpress 目錄拷貝到 /Library/WebServer/Documents。那我們只要在 /etc/apache2/httpd.conf 再修改 DocumentRoot 的配置。
DocumentRoot "/Library/WebServer/Documents/wordpress"
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
如上,我們在 /Library/WebServer/Documents 后面添加自己的目錄 wordpress。然后再重啟一下 Apache 服務。
apachectl restart
重啟服務后,在瀏覽器的地址欄輸入:
localhost
即可出現如下頁面,就代表已經配置成功了。
注意,此響應的其實是
http://localhost/index.php
并且它會自動跳轉到/wp-admin/setup-config.php。
http://localhost/wp-admin/setup-config.php
2.4 開啟 Mysql
上面圖中,告訴了我們要安裝 wordpress ,所需要的 Mysql 服務及相關的配置
Database name
Database username
Database password
Database host
Table prefix (if you want to run more than one WordPress in a single database)
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查看一下Mysql
$ mysql --version
mysql Ver 14.14 Distrib 5.7.20, for osx10.13 (x86_64) using EditLine wrapper
但這個并不是 Mysql 的服務端,這是客戶端。我們應該這樣來看是否已經安裝了服務端。
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如果你不能進入到 Mysql 的控制臺,說明你還沒有安裝好Mysql,那如果沒有安裝好的話就請去Mysql的官網下載吧。下載免費的社區版即可滿足需求。如果已經安裝就通過“系統偏好設置”來啟動Mysql服務。當然要啟動了該服務,才能進入到上面所說的Mysql控制臺。
新建并配置數據庫
新建數據庫這個就不在這里講述了,假設我們創建了一個數據庫為 wordpress,空的就行。然后用 subline 等純文本編輯工具打開之前存放在/Library/WebServer/Documents下面的 wordpress/wp-config-sample.php。并修改如下內容。
Database name
Database username
Database password
Database host
樣例如下:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpress' );
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress123456' );
/** MySQL hostname */
define( 'DB_HOST', '127.0.0.1:/var/run/mysqld/mysqld.sock' );
注意上面的 DB_HOST 最好和作者改成一樣的,不要直接用 localhost ,不然可能會連接不上。
然后將修改后的文件另存為 wp-config.php。這就完成了數據庫的配置。
2.5 安裝WordPress
前面啰嗦了一大堆,終于把要準備的環境準備好了,接下就在瀏覽器的地址欄輸入http://localhost/wp-admin/install.php ,然后按照向導完成安裝即可大功告成了。
四、總結
WordPress 是一款非常優秀的個人博客系統,并且還是開源的,可謂是非常良心了。而其實其安裝也是非常簡單的,總結下來就是:
1.安裝好 php。
2.安裝好 Mysql,當然,主要是指服務端。建立一個空的數據庫,如 wordpress。
3.安裝一個 HTTP 服務器,如 Apache。
文章非常簡單,希望能給有需要的同學一些幫助,謝謝。
總結
以上是生活随笔為你收集整理的mac wordpress php7,Mac 下基于 wordpress 搭建个人博客系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linkerd mysql_Linker
- 下一篇: php多人访问抽奖倒计时一致,Javas