First, Homebrew installation

Homebrew is a great package manager for MAC that automatically installs dependencies, freeing you from the hassle of installing software dependencies.

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

Homebrew common commands:

brew update # Update the latest information about installable packages. It is recommended to run them before each installation
brew search pkg_name Search for relevant package information
brew install pkg_name # the installation package
Copy the code

Second, PHP installation

Mac OSX 10.9 and later comes with PHP and php-fpm, eliminating the need to install php-fpm.

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
vim /private/etc/php-fpm.conf
Copy the code

Error_log = /usr/local/var/log/php-pm.log; error_log = /usr/local/var/log/php-pm.log; If the value is not changed, an error message will be displayed indicating that the output path of the log file does not exist when phP-fpm is run.

After modification, enter:

sudo php-fpm
# kill PHP process ()/pkill forcibly remove PHP
sudo pkill php-fpm
sudo php-fpm 
Copy the code

Nginx installation

brew search nginx
brew install nginx
Copy the code

Nginx related commands

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

Nginx configuration

cd /usr/local/etc/nginx/
mkdir conf.d
vim nginx.conf
vim ./conf.d/default.conf
Copy the code

nginx.conf

worker_processes 1; 
 
error_log    /usr/local/var/log/nginx/error.log;
 
pid    /usr/local/var/run/nginx.pid;
 
events {
  worker_connections 1024;
}
 
http {
  include    mime.types;
  default_type application/octet-stream;
 
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';
 
  access_log   /usr/local/var/log/nginx/access.log main;
  port_in_redirect off;
  sendfile    on; 
  keepalive_timeout 65; 
 
  include /usr/local/etc/nginx/conf.d/*.conf;
}
Copy the code

The following error may occur during the restart of the nginx configuration file:

Nginx: [error] invalid PID number ""in"/ usr /localThe/var/run/nginx/nginx. Pid"Copy the code

Solutions:

sudo nginx -c /usr/local/etc/nginx/nginx.conf
sudo nginx -s reload
Copy the code

default.conf

server { listen 80; server_name www.myweb.com; Root project address; access_log /usr/local/var/log/nginx/access.log  main;

    location / {
        index  index.html index.htm index.php;
        autoindex   on;
    try_files $uri /app_dev.php$is_args$args;
        include     /usr/local/etc/nginx/conf.d/php-fpm; } location = /info {allow 127.0.0.1; deny all; rewrite (.*) /.info.php; } error_page 404 /404.html; error_page 403 /403.html; }Copy the code

php-fpm

#proxy the php scripts to php-fpm
location ~ \.php$ {
    try_files                   $uri = 404;
    fastcgi_pass                127.0.0.1:9000;
    fastcgi_index               index.php;
    fastcgi_intercept_errors    on;
    include /usr/local/etc/nginx/fastcgi.conf;
}
Copy the code

4, MySQL installation

Brew Search mysql brew install [email protected]Copy the code

Other commands

Get the list of services
brew services list
Restart the mysql service
brew services restart mysql
# stop mysql service
brew services stop mysql
Copy the code

Configure to the environment

echo 'the export PATH = "/ usr/local/opt/[email protected] / bin: $PATH"' >> ~/.bash_profile
source ~/.bash_profile 
Copy the code

PS: If the following error occurs:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'(2)Copy the code

Execute the following command

mysql.server start
Copy the code

Set MySQL to start automatically upon startup

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Copy the code

Enable the MySQL security mechanism

mysql_secure_installation
Copy the code
jianghehedeMacBook-Pro:~ comet
$ mysql_secure_installation
 
Securing the MySQL server deployment.
 
Connecting to MySQL using a blank password.
 
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
 
Press y|Y for Yes, any other key forNo: N // If yes is selected, the password length must be at least 8 digits, but I only want 6 digits of Pleaseset the password forRoot here. New password: // set the password re-enter New password: By default, a MySQL installation has an anonymous user, causing anyone to happen easilylog into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
 
Remove anonymous users? (Press y|Y for Yes, any other key forNo) : Y // Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at
the root password from the network.
 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
 
 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
 
 
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.
 
 - Removing privileges on test database...
Success.
 
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
 
All done!
Copy the code

Five, installation completed…

Six, dozen of the reward

I thought I could buy my little brother a bottle of mineral water. Xi xi xi