Note: do not go to delete the system’s own Apache and PHP I began to delete the system’s own Apache, resulting in the PHP has been unable to install successfully after reinstalling Apache, so do not easily delete the system’s own Apache and PHP, master said otherwise.

Install homebrew

Homebrew is a particularly handy package tool for MAC systems and is extremely easy to install.

There are many people on the Internet who directly give homebrew installation commands, but most of the addresses are no longer valid. On the Homebrew web site brew.sh/, there is the homebrew installation command in the middle. Just copy it to your terminal and execute it.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

Now that homebrew is installed, we can use BREW to install Nginx. With BREW, installation is very simple, and you don’t need to make it yourself.

MySql installation

brew install mysql
Copy the code

Mysql > install mysql > install mysql > install mysql > install mysql

1. Run the CD to the mysql directory
cd /usr/local/opt/mysql/
Copy the code
2. Add the launchctl startup control
mkdir -p ~/Library/LaunchAgents/

cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Cancel the startup command
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plis
Copy the code
3. Run the security configuration script to set the password of the root account. If you do not run this step, you cannot log in to the mysql database using the mysql -u root -p command
./bin/mysql_secure_installation
Copy the code

Run the mysql -u root -p command to log in to the mysql database


Navicat Premium 12 & Mysql 8.0.11

If you use Navicat 12 to remotely connect to Mysql 8.0.11, the following error message is displayed: Caching_sha2_password cannot be loaded.

2059 - Authentication plugin 'caching_sha2_password' cannot be loaded
Copy the code

The preceding error occurs because the existing client connection software does not support the Mysql8 new encryption mode caching_sha2_password. Therefore, you need to change the user encryption mode to the old encryption authentication mode.

  • 1) Log in to the host where the Mysql database is installed as user root.
  • 2) Run the following command to view the encryption mode of the current user
use mysql;

select user,plugin from user where user='root';
You can see that the current user is encrypted by caching_sha2_password
Copy the code
  • 3) Run the mysql_native_password command to change the encryption mode to mysql_native_password
alter user 'root'@'localhost' identified with mysql_native_password by 'password';
Copy the code
  • 4) Execute commandsflush privilegesEnable permission configuration items to take effect immediately.

Install nginx

brew install nginx
Copy the code
Configure nginx
1. Set administrator permissions for nginx: If administrator permissions are not set, port 80 cannot be listened on
The default directory is nginx. The only difference is the version number
sudo chown root:wheel /usr/local/ Cellar/nginx / 1.10.1 / bin/nginx sudo chmod u + s/usr /local/ Cellar/nginx / 1.10.1 / bin/nginxCopy the code
2. Add the launchctl startup control
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Copy the code
3. At this point, Nginx is basically done. Running nginx.
sudo nginx # open nginx
nginx -s reload|reopen|stop|quit  # reload exit nginx configuration restart | | | stop
nginx -t   Test the configuration for syntax errors
Copy the code

The default port is 8080. Enter http://localhost:8080/ in the browser to see the nginx server on your computer

8080 is the default site setting port of nginx, now we create a site, set the port and mapping path

Custom site ports
1. Perform vim/usr/local/etc/nginx/nginx. Conf modify nginx configuration file, in the last line to join:
include conf.d/*.conf;
Copy the code
2. Create related files:
Create a new folder
mkdir /usr/local/etc/nginx/conf.d

Create a new file
touch /usr/local/etc/nginx/conf.d/test.conf
vim /usr/local/etc/nginx/conf.d/test.conf
Copy the code
Conf file example
server {
    listen       80;
    server_name  www.test.com;

    location / {
        try_files $uri $uri/ /index.php$is_args$query_string;
    	root "/Users/caishiyin/Sites/huiyu/test";
    	index index.html index.htm index.php;
    }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php$ {
	root           "/Users/caishiyin/Sites/huiyu/test";
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  indx.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; }}Copy the code
4. Bind the custom domain namesudo vim /etc/hostsAdd a line at the end of the file127.0.0.1 Domain name configured in nginx

Installing PHP

1. Install PHP using Homebrew

The installation of PHP is a bit more complicated than nginx and mysql because BREW does not have a PHP package by default

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php

Brew tap homebrew/dupes
git -C "$(brew --repo homebrew/core)" fetch --unshallow
Copy the code

After executing the above command, you can install PHP at this time, but there are many versions of PHP, you can use brew Search PHP to check the specific version. Install version 7.1 here

brew install php71 --with-imap --with-tidy --with-debug --with-mysql --with-fpm
Copy the code
2. PHP configuration

Once installed, PHP is configured, and since the MAC comes with PHP by default, we will add our PHP installation to our environment variables instead of continuing to use MAC’s native PHP

sudo vim ~/.bash_profile
Add the following statement to the end of the file:
export PATH="$(brew --prefix php56)/bin:$PATH"
After saving the file, use the source file to make the environment variables you just added take effect
source ~/.bash_profile
Copy the code

At this point, when you run PHP -v from the command line, you no longer see PHP on your system, but PHP that you just installed

3. Add the launchctl startup control
bashmkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/[email protected]/[email protected] ~/Library/LaunchAgents/ launchctl load -w ~ / Library/LaunchAgents/[email protected]Copy the code

So, PHP is installed

4. Directory for saving the PHP configuration file
/usr/localThe/etc/PHP / 7.1 / PHP. Ini/usr /localThe/etc/PHP / 7.1 / PHP - FPM. Conf# change php-fpm port:
vim /usr/localThe/etc/PHP / 7.1 / PHP - FPM. D/www.confCopy the code

Install the composer

1. Run the CLI for global installation
curl -sS https://getcomposer.org/installer | php 
Copy the code
2. Move the installation package to /usr/local/bin
mv composer.phar /usr/local/bin/composer
Copy the code

over.