废话
用了Mac有一阵了,之前一直使用的Mamp Pro的集成环境,非常强大。可以自由切换php版本、更换Apache 和 Nginx、自定义站点 —破解MAmp pro 链接
安装Brew
需要Homebrew,更换中国镜像。有很多帖子这里就不说了
安装php
安装
brew install php56 --with-debug --with-homebrew-libressl --with-homebrew-curl --with-gmp --with-libmysql --with-imap
加入启动项,进行配置
# 加入开机启动
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
sudo aunchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
# 将php和php-fpm 加入环境变量
echo 'export PATH="$(brew --prefix php56)/bin:$PATH"' >> ~/.zshrc #for php
echo 'export PATH="$(brew --prefix php56)/sbin:$PATH"' >> ~/.zshrc #for php-fpm
测试安装
php-fpm -v
可能会出现如下报错:
Cannot load Xdebug - it was built with configuration API220131226,NTS, whereas running engine is API220131226,NTS,debug
PHP Warning: PHP Startup: igbinary: Unable to initialize module
Module compiled with build ID=API20131226,NTS
PHP compiled with build ID=API20131226,NTS,debug
解决办法: 将上面的报错的扩展重新安装编译一下。(注意。一定要看你的报错有几个)
brew reinstall php56-xdebug --build-from-source php56-igbinary --build-from-source
情况分析: 我在第一次安装的时候出现了。报错,但是第二次装的时候没出现。 分析是因为之前用mamp集成环境,已经存在了对应的扩展。参考这个 链接
安装Nginx
brew install nginx
安装完成之后,会提示一些信息:
1、nginx 的配置文件: /usr/local/etc/nginx/nginx.conf
2、可以在这个目录下新建自己的虚拟主机: /usr/local/etc/nginx/servers/
修改Nginx配置文件
1、 新建php-fpm配置,用于解析php脚本
mkdir /usr/local/etc/nginx/conf.d
vim /usr/local/etc/nginx/conf.d/php-fpm
## 将如下内容粘贴保存
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include fastcgi.conf;
}
## 修改nginx.conf
vim /usr/local/etc/nginx/nginx.conf
2、修改nginx。conf
vim /usr/local/etc/nginx/nginx.conf
user thanatos staff; ###指定用户
worker_processes 1;
#pid logs/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 logs/access.log main;
sendfile on;
#tcp_nopush on;
autoindex on; # 开启目录结构
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/thanatos/Web;
index index.html index.htm index.php;
autoindex on;
include conf.d/php-fpm; # include 刚才创建的脚本
}
}
include servers/*;
}
3、将nginx加入开机开机启动
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
保存退出,重新起nginx (要使用管理员权限,不然不能使用80端口)
sudo brew services restart nginx
修改php-fpm 配置文件 (为了不修改目录权限)
/usr/local/etc/php/5.6
主要修改运行的用户
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr/local/Cellar/php56/5.6.30_6) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = 你的用户
group = 用户组
保存重启php-fpm
sudo brew services restart php56
安装mysql
1、安装mysql比较简单,主要是配置mysql的登陆
brew install mysql
2、加入开机启动
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
3、修改root密码 具体就不写了。
因为,记录的有点乱,就是自己做一个备忘,有遇到同样问题的老哥,或者我落了那一步,欢迎纠正