1. Environment requirements
-
PHP 5.2.4 or newer version
MySQL 5.0 or newer version
WebServer (you can choose Apache, nginx, etc. that support PHP, here I choose Apache)
2. Software installation
1. Install PHP
Mac OSX comes with PHP, no need to install it.
It is not recommended to upgrade PHP7 through brew, source code installation, etc. Test in a virtual machine if necessary.
2. Install MySQL
MySQL download
Visit MySQL’s official website http://www.mysql.com/downloads/ You will see “MySQL Community Server” on the page "There is a "download" button below, click the button.
Enter the MySQL download interface http://www.mysql.com/downloads/mysql/. Listed below are the versions of MySQL that can be used on Mac OS. Select the required version and click to download.
Then it will jump to another interface. This interface prompts you whether you need to register or not. Just select "No thanks, just take me to downloads!" at the bottom, and then this will actually jump to it. Download interface, this interface lists many servers for downloading, just select a server to download.
MySQL installation
Double-click the downloaded file. Generally, there will be several files in it. There is no MySQL.prefPane file in the package above 5.6, but it will be installed by default; below 5.6, you need to manually Install.
After the installation is completed, the MySQL management button will appear in the system (Preferences), through which you can start and stop MySQL.
??Note: When the MySQL installation is completed, the initial password will be displayed in a pop-up window, please save the password! ! !
MySQL configuration
Open the command line
Edit .bash_profile and add the following content
vi?.bash_profile?? tcsh下添加如下內(nèi)容: alias?mysql?/usr/local/mysql/bin/mysql alias?mysqladmin?/usr/local/mysql/bin/mysqladmin bash下添加如下內(nèi)容: alias?mysql=/usr/local/mysql/bin/mysql alias?mysqladmin=/usr/local/mysql/bin/mysqladmin
Save and exit, and enable the configuration
source?.bash_profile
First time When using MySQL, you need to change the password, which is manifested as the following error
ERROR?1820?(HY000):?You?must?reset?your?password?using?ALTER?USER?statement?before?executing?this?statement.
Please refer to the official website for examples
http://dev.mysql.com/doc/refman/5.7/en/alter-user. html
http://dev.mysql.com/doc/refman/5.6/en/alter-user.html
The following is my solution
mysql>?SELECT?1; ERROR?1820?(HY000):?You?must?SET?PASSWORD?before?executing?this?statement mysql>?SET?PASSWORD?=?PASSWORD('new_password'); Query?OK,?0?rows?affected?(0.01?sec)?? ?? mysql>?quit;
You can use it now Log in to the database again with a new password
Create database
mysql>create?database??database-name;
2. Install Apache
Mac OSX comes with Apache, no need to install it.
Apache configuration
The root directory configuration file is/etc/apache2/httpd.conf
sudo?vi?/etc/apache2/httpd.conf 搜索DocumentRoot(操作按ESC?+?shift?+?:+?/DocumentRoot) 修改為如下內(nèi)容即可 #?DocumentRoot:?The?directory?out?of?which?you?will?serve?your #?documents.?By?default,?all?requests?are?taken?from?this?directory,?but #?symbolic?links?and?aliases?may?be?used?to?point?to?other?locations. DocumentRoot?"/usr/local/www/" <Directory "/usr/local/www/"> 為什么把Apache的網(wǎng)站根目錄放在/usr/local/www/這里??? 答:不需要修改權(quán)限,不需要折騰。 把這行的注釋去掉 #LoadModule?php5_module?libexec/apache2/libphp5.so
The multi-site configuration file is/etc/apache2/extra/httpd-vhosts. conf
#<VirtualHost *:80> #????ServerAdmin?webmaster@dummy-host2.example.com #????DocumentRoot?"/usr/docs/dummy-host2.example.com" #????ServerName?dummy-host2.example.com #????ErrorLog?"/private/var/log/apache2/dummy-host2.example.com-error_log" #????CustomLog?"/private/var/log/apache2/dummy-host2.example.com-access_log"?common #</VirtualHost> 里面有2個例子,復(fù)制一個修改如下 <VirtualHost *:80> ????DocumentRoot?"/usr/local/www/WordPress/WordPress01" ????ServerName?WordPress01 ????ErrorLog?"/private/var/log/apache2/WordPress01-error_log" ????CustomLog?"/private/var/log/apache2/WordPress01-access_log"?common </VirtualHost> <VirtualHost *:80> ????DocumentRoot?"/usr/local/www/WordPress/WordPress02" ????ServerName?WordPress02 ????ErrorLog?"/private/var/log/apache2/WordPress02-error_log" ????CustomLog?"/private/var/log/apache2/WordPress02-access_log"?common </VirtualHost> 現(xiàn)在apache多站點配置好了。
Modify the /etc/hosts file
sudo?vi?/etc/hosts 修改如下內(nèi)容, ## #?Host?Database # #?localhost?is?used?to?configure?the?loopback?interface #?when?the?system?is?booting.??Do?not?change?this?entry. ## 127.0.0.1????????localhost 255.255.255.255??broadcasthost 127.0.0.1????????WordPress01 127.0.0.1????????WordPress02 127.0.0.1????????phpMyAdmin ::1??????????????localhost 啟動Apache: sudo?apachectl?start 現(xiàn)在可以通過在瀏覽器中輸入:localhost/WordPress01?訪問?WordPress01?的內(nèi)容了 重啟Apache: sudo?apachectl?restart 停止Apache: sudo?apachectl?stop
3. Install WordPress
Go to the WordPress official website
https://cn.wordpress.org/
Download the installation package, unzip it and rename it to WordPress01, and put it under the /usr/local/www/WordPress directory.
Modify the content of wp-config-example.conf in WordPress01 as follows and rename it to wp-config.conf
<?php /** ?*?WordPress基礎(chǔ)配置文件。 ?* ?*?這個文件被安裝程序用于自動生成wp-config.php配置文件, ?*?您可以不使用網(wǎng)站,您需要手動復(fù)制這個文件, ?*?并重命名為“wp-config.php”,然后填入相關(guān)信息。 ?* ?*?本文件包含以下配置選項: ?* ?*?*?MySQL設(shè)置 ?*?*?密鑰 ?*?*?數(shù)據(jù)庫表名前綴 ?*?*?ABSPATH ?* ?*?@link?https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php ?* ?*?@package?WordPress ?*/ //?**?MySQL?設(shè)置?-?具體信息來自您正在使用的主機?**?// /**?WordPress數(shù)據(jù)庫的名稱?*/ define('DB_NAME',?'WordPress'); /**?MySQL數(shù)據(jù)庫用戶名?*/ define('DB_USER',?'root'); /**?MySQL數(shù)據(jù)庫密碼?*/ define('DB_PASSWORD',?'123456'); /**?MySQL主機?*/ define('DB_HOST',?'localhost'); /**?創(chuàng)建數(shù)據(jù)表時默認(rèn)的文字編碼?*/ define('DB_CHARSET',?'utf8'); /**?數(shù)據(jù)庫整理類型。如不確定請勿更改?*/ define('DB_COLLATE',?''); /**#@+ ?*?身份認(rèn)證密鑰與鹽。 ?* ?*?修改為任意獨一無二的字串! ?*?或者直接訪問{@link?https://api.wordpress.org/secret-key/1.1/salt/ ?*?WordPress.org密鑰生成服務(wù)} ?*?任何修改都會導(dǎo)致所有cookies失效,所有用戶將必須重新登錄。 ?* ?*?@since?2.6.0 ?*/ define('AUTH_KEY',????????????'put?your?unique?phrase?here'); define('SECURE_AUTH_KEY',?????'put?your?unique?phrase?here'); define('LOGGED_IN_KEY',???????'put?your?unique?phrase?here'); define('NONCE_KEY',???????????'put?your?unique?phrase?here'); define('AUTH_SALT',???????????'put?your?unique?phrase?here'); define('SECURE_AUTH_SALT',????'put?your?unique?phrase?here'); define('LOGGED_IN_SALT',??????'put?your?unique?phrase?here'); define('NONCE_SALT',??????????'put?your?unique?phrase?here'); /**#@-*/ /** ?*?WordPress數(shù)據(jù)表前綴。 ?* ?*?如果您有在同一數(shù)據(jù)庫內(nèi)安裝多個WordPress的需求,請為每個WordPress設(shè)置 ?*?不同的數(shù)據(jù)表前綴。前綴名只能為數(shù)字、字母加下劃線。 ?*/ $table_prefix??=?'wp_'; /** ?*?開發(fā)者專用:WordPress調(diào)試模式。 ?* ?*?將這個值改為true,WordPress將顯示所有用于開發(fā)的提示。 ?*?強烈建議插件開發(fā)者在開發(fā)環(huán)境中啟用WP_DEBUG。 ?* ?*?要獲取其他能用于調(diào)試的信息,請訪問Codex。 ?* ?*?@link?https://codex.wordpress.org/Debugging_in_WordPress ?*/ define('WP_DEBUG',?true); /** ?*?zh_CN本地化設(shè)置:啟用ICP備案號顯示 ?* ?*?可在設(shè)置→常規(guī)中修改。 ?*?如需禁用,請移除或注釋掉本行。 ?*/ define('WP_ZH_CN_ICP_NUM',?true); /*?好了!請不要再繼續(xù)編輯。請保存本文件。使用愉快!?*/ /**?WordPress目錄的絕對路徑。?*/ if?(?!defined('ABSPATH')?) ????define('ABSPATH',?dirname(__FILE__)?.?'/'); /**?設(shè)置WordPress變量和包含文件。?*/ require_once(ABSPATH?.?'wp-settings.php'); 現(xiàn)在可以通過在瀏覽器中輸入:localhost/WordPress01?安裝WordPress了。 ??注意:這里很有可能會在瀏覽器中看到“鏈接數(shù)據(jù)庫發(fā)生錯誤”,需要確認(rèn)以下內(nèi)容: *?數(shù)據(jù)庫用戶名和密碼正確。 *?數(shù)據(jù)庫已經(jīng)啟動并能訪問。 如果以上無誤,請修改wp-config.conf文件中的?? /**?MySQL主機?*/ define('DB_HOST',?'localhost'); 改為: /**?MySQL主機?*/ define('DB_HOST',?'127.0.0.1'); 或者是?MySQL主機的IP 接下來正常安裝即可。