Configure php, nginx, mysql, redis under mac >
Delete the original configuration
cd /usr/bin/ && sudo rm -rf php php-config phpdoc phpize
cd /usr/include && sudo rm -rf php
cd /usr/lib && sudo rm -rf php
cd /usr/sbin && sudo rm -rf php-fpm
cd /usr/share && sudo rm -rf php
cd /usr/share /man/man1 && sudo rm -rf php-config.1 php.1 phpize.1
cd /usr/share/man/man8 && sudo rm -rf php-fpm.8
cd /usr/bin / && sudo rm -rf php php-config phpdoc phpize
Install php7.1
brew install homebrew/php/php71
brew install homebrew/php/php71-mcrypt
After installation, it will come with PHP-FPM
Start PHP-FPM
Add a symlink first
ln -s /usr/local/opt/php71/sbin/php-fpm /usr/local/bin/php-fpm
It is also necessary to set the boot startup
ln -sfv /usr/local/opt/php71/*.plist ~/Library/LaunchAgents
Start
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
Stop
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
force kill
sudo pkill - INT -o php-fpm
Make sure it is running and listening on port 9000
sudo lsof -Pni4 | grep LISTEN | grep php
Or view through the port
sudo lsof -i tcp:9000
Second, install nginx
Uninstall
brew remove nginx
clear configuration
sudo rm - rf /usr/local/etc/nginx/
Install
brew install nginx –with-http_geoip_module
boot Start
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Start
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Stop
launchctl unload ~/ Library/LaunchAgents/homebrew.mxcl.nginx.plist
Listening to port 80 requires root permission to execute, so:
sudo chown root:wheel /usr/local/Cellar/nginx/1.12.0_1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.12.0_1/bin/nginx
Configuration
Configure nginx.conf
Create the directory you need:
mkdir -p /usr/local/var/logs/nginx
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx /conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 777 /var /www
The folder here is for 777, which is convenient for usual development
vim /usr/local/etc/nginx/ nginx.conf Enter the following content:
user root wheel; #The default is nobody will cause 403
worker_processes 1;
error_log /usr/local/var/logs/nginx/ error.log debug;
pid /usr/local/var/run/nginx.pid;
events {
worker_connections 256;
}
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/logs/access.log main;
sendfile on;
keepalive_timeout 65;
port_in_redirect off;
include /usr/ local/etc/nginx/sites-enabled/*;
}
Set nginx php-fpm configuration file
vim /usr /local/etc/nginx/conf.d/php-fpm
Modify to (create without)
#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;
}
Create a default virtual host default
vim /usr/local/ etc/nginx/sites-available/default input:
server {
listen 80;
server_name www.qilipet.com admin.qilipet.com;
root /var /www/pet/public;
access_log /usr/local/var/logs/nginx/default.access.log main;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
important
for To facilitate development, modify the directory where the website code is located to 777 permissions
Third, install MySQL
brew install mysql
Check the running status of MySQL
ps aux | grep mysql
Test connection to MySQL (the default password is empty)
mysql -uroot -p
Fourth, install redis
brew install redis
The default password is empty
5. Set shortcut service control command
For the convenience of later management, under the command alias, vim ~/.bash_aliases enter the content:
alias nginx.start='launchctl load -w /usr/local/opt/ nginx/homebrew.mxcl.nginx.plist'
alias nginx.stop='launchctl unload -w /usr/local/opt/nginx/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx .stop && nginx.start'
alias php-fpm.start="launchctl load -w /usr/local/opt/php71/homebrew.mxcl.php71.plist"
alias php-fpm.stop=" launchctl unload -w /usr/local/opt/php71/homebrew.mxcl.php71.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql. start="launchctl load -w /usr/local/opt/mysql/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w /usr/local/opt/mysql/homebrew.mxcl. mysql.plist"
alias mysql.restart='mysql.stop && mysql.start'
alias redis.start="launchctl load -w /usr/local/opt/redis/homebrew.mxcl.redis.plist "
alias redis.stop="launchctl unload -w /usr/local/opt/redis/homebrew.mxcl.redis.plist"
alias redis.restart='redis.stop && redis.start'
Make shortcut commands effective
echo "[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases" >> ~/. bash_profile
source ~/.bash_profile
Sometimes the shortcut cannot be used after the terminal is restarted, and the source needs to be re-sourced. The blogger uses the mac terminal preference settings, in Execute source compilation before opening the terminal, set as shown below:
1.jpg
Note:
Considering that some services do not need to be started after booting, the path to start here is the program directory. If it needs to be started at boot, softly link the plist file to ~/Library/LaunchAgents.
For example: ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Six, create a site directory to the main directory, convenient Quick access
ln -sfv /var/www ~/htdocs
Seven, reference
This article refers to Xinge mac environment construction notes.