1. 安装apache
brew install httpd
2. 安装nginx
brew install nginx
3. 添加php拓展库
brew tap homebrew/homebrew-php
4. 安装php
brew install homebrew/php/php56 --with-httpd --with-fpm
–with-httpd:编译libphp5.so给httpd
–with-fpm:nginx需要php-fpm
5. 配置apche
# httpd.conf 添加这三行
LoadModule php5_module /usr/local/Cellar/php56/5.6.32_8/libexec/apache2/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.php index.htm index.html
6. 配置nginx
# nginx.conf 添加以下内容
server {
listen 80;
server_name www.xxx.cn;
root /Users/Icecream/Web/xxx;
# 文件不存在则重定向到/index.php/xxx(/login.html => /index.php/login.html)
if (!-f $request_filename) {
rewrite ^(.*)$ /index.php$1 break;
}
location / {
#root html;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# nginx配置pathifo
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
7. 其他
7.1. homebrew 替换国内源
7.2. 使用 unlink&link 切换php
当前php为php56,切换至php70
终端执行:
step 1. brew unlink php56
step 2. brew link php70
7.3. 查看homebrew安装的程序
homebrew list
7.4. 查看homebrew安装的服务
brew services list
7.5. 启动homebrew安装的服务
brew services start|stop|restart xxx
例如:
brew start nginxbrew stop nginx
brew restart nginx
P.s. nginx如使用80端口,则需管理员权限,使用sudo运行命令
sudo brew start nginx
7.6. homebrew卸载程序
brew uninstall xxx
例如:
brew uninstall nginx