mac下配置php、nginx
PHP升級(jí)
解除原php
brew unlink php70
刪除原配置
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
安裝php7.1
brew install homebrew/php/php71
brew install homebrew/php/php71-mcrypt
安裝完了之后它會(huì)自帶PHP-FPM
啟動(dòng)PHP-FPM
加一個(gè)symlink先
ln -s /usr/local/opt/php71/sbin/php-fpm /usr/local/bin/php-fpm
還需要設(shè)置開機(jī)啟動(dòng)
ln -sfv /usr/local/opt/php71/*.plist ~/Library/LaunchAgents
啟動(dòng)
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
強(qiáng)殺
sudo pkill -INT -o php-fpm
確保它正常運(yùn)行監(jiān)聽9000端口
sudo lsof -Pni4 | grep LISTEN | grep php
或者通過端口查看
sudo lsof -i tcp:9000
安裝nginx
卸載
brew remove nginx
清除配置
sudo rm -rf /usr/local/etc/nginx/
安裝
brew install nginx --with-http_geoip_module
開機(jī)啟動(dòng)
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
啟動(dòng)
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
監(jiān)聽80端口需要root權(quán)限執(zhí)行,因此:
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
配置
配置nginx.conf
創(chuàng)建需要用到的目錄:
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 /jacklin
sudo chown :staff /jacklin
sudo chmod 777 /jacklin
這里的文件夾給777,方便平時(shí)開發(fā)
vim /usr/local/etc/nginx/nginx.conf 輸入以下內(nèi)容:
user root wheel; #默認(rèn)的是nobody會(huì)導(dǎo)致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/*;
}
設(shè)置nginx php-fpm配置文件
vim /usr/local/etc/nginx/conf.d/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;
}
創(chuàng)建默認(rèn)虛擬主機(jī)default
vim /usr/local/etc/nginx/sites-available/default輸入:
server {
listen 80;
server_name jacklin.test.com admin.test.com;
root /jacklin;
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;
}
}
重要
為了方便開發(fā),將網(wǎng)站代碼所在目錄修改為 777權(quán)限
安裝MySQL
brew install mysql
brew link mysql
brew unlink mysql && brew link mysql(如果提示這樣的命令你就輸入以下這個(gè)命令)
brew info mysql
brew services start mysql
查看一下MySQL運(yùn)行情況
ps aux | grep mysql
測(cè)試連接MySQL
mysql -uroot -p
設(shè)置快捷服務(wù)控制命令
為了后面管理方便,將命令 alias 下,vim ~/.bash_aliases 輸入一下內(nèi)容:
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'
讓快捷命令生效
echo "[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases" >> ~/.bash_profile
source ~/.bash_profile
注意:考慮到部分服務(wù)不用開機(jī)啟動(dòng),所以這里啟動(dòng)的路徑都是程序目錄。如果需要開機(jī)啟動(dòng),將plist文件軟連接到~/Library/LaunchAgents下。
比如:ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
創(chuàng)建站點(diǎn)目錄到主目錄,方便快捷訪問
ln -sfv /var/www ~/htdocs