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下添加如下内容: alias mysql /usr/local/mysql/bin/mysql alias mysqladmin /usr/local/mysql/bin/mysqladmin bash下添加如下内容: 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) 修改为如下内容即可 # 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/"为什么把Apache的网站根目录放在/usr/local/www/这里? 答:不需要修改权限,不需要折腾。 把这行的注释去掉 #LoadModule php5_module libexec/apache2/libphp5.so
The multi-site configuration file is/etc/apache2/extra/httpd-vhosts. conf
## 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 # 里面有2个例子,复制一个修改如下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 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 现在apache多站点配置好了。
Modify the /etc/hosts file
sudo vi /etc/hosts 修改如下内容, ## # 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 现在可以通过在浏览器中输入:localhost/WordPress01 访问 WordPress01 的内容了 重启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
Copy after login