查看现有php版本和apache版本
$ httpd -v
Server version: Apache/2.4.23 (Unix)
Server built: Aug 8 2016 18:10:45
$ php --version
PHP 5.6.29 (cli) (built: Dec 9 2016 07:03:56)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
因为我们要自己动手来安装 Nginx,因此首先来关闭系统自带的apache:
sudo apachectl stop //关闭apache,如果事先没开启过,可以忽略报错信息
如果你的apache已经加入了launchctl,使用下面的命令来关闭:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
为什么选择关闭apache?因为mac os x系统自带的apache是没有优雅的remove/uninstall 的方式的... 对于“洁癖”比较严重的童鞋,可以选择直接删除相关的文件!(千万不要手抖删错目录...)
建议最好别删除,我删除后安装PHP56时总是安装不成功,如果存储足够的话建议不必删除
sudo rm /usr/sbin/apachectl
sudo rm /usr/sbin/httpd
sudo rm -r /etc/apache2/
删除自带的PHP--建议最好别删除,我删除后安装PHP56时总是安装不成功,如果存储足够的话建议不必删除
sudo rm -r /usr/bin/php
安装nginx
brew install nginx
修改配置文件
sudo nano /usr/local/etc/nginx/nginx.conf
//修改默认的8080端口为80
给予管理员权限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
运行nginx
sudo nginx //打开 nginx
sudo nginx -s reload|reopen|stop|quit //重新加载配置|重启|停止|退出 nginx
sudo nginx -t //测试配置是否有语法错误
安装mysql
brew install mysql
cd /usr/local/opt/mysql/
修改配置文件
sudo nano my.cnf
如果出现无法启动mysql,rm my.cnf
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
取消启动
//launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
初始化 mysql
./bin/mysql_install_db
//执行安全设置脚本,设置root账号密码
./bin/mysql_secure_installation
命令行连接mysql
mysql -uroot -p
//关闭mysql
\q
php的安装与配置
brew 默认没有 php 安装包:
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
现在可以安装php了:
brew install --without-apache --with-fpm --with-mysql php56
将php路径加入PATH
sudo nano ~/.bash_profile
//添加下面这行
export PATH="$(brew --prefix php56)/bin:$PATH"
source ~/.bash_profile
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
配置路径
/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/5.6/php-fpm.conf
配置 Nginx 支持 PHP-FPM
sudo nano /usr/local/etc/nginx/nginx.conf
添加默认首页 php
index index.php index.html index.htm;
取消以下内容的注释,并做修改
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/Cellar/nginx/1.10.2_1/html$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
sudo nano /usr/local/Cellar/nginx/1.10.2_1/html/index.php
//添加测试代码
<?php
phpinfo();
?>
本文只做记录供自己使用,摘抄原文