1、安装homebrew
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1
2、安装nginx
sudo brew install nginx
3、安装mysql
sudo brew install mysql
4、由于mac默认安装了Apache和php,所以卸载掉Apache和php
sudo apachectl stop
sudo rm -rf /etc/apache2/
sudo rm -rf /usr/libexec/apache2/
sudo rm -rf /usr/php
sudo rm -rf /usr/bin/php
sudo rm -rf /usr/bin/php-config
sudo rm -rf /usr/bin/phpize
sudo rm -rf /usr/share/man/man*/php*
5、添加php源
sudo brew tap homebrew/dupes
sudo brew tap josegonzalez/homebrew-php
6、安装php
sudo brew install php55 --with-debug --with-fpm --with-gmp --with-homebrew-openssl --with-imap --with-intl --with-libmysql --without-bz2 --without-mysql --without-pcntl --without-pear php5 --with-cli --with-curl --with-fpm --with-intl --with-mcrypt --with-mysqlnd_ms --with-gd
验证php是否安装成功:php -v
验证php-fpm是否成功:php-fpm -t,结果报错“ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory”
php.ini.defalut和php-fpm.conf.default在/private/etc目录和/etc目录下都有
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
sudo chmod 777 /private/etc/php-fpm.conf
sudo php-fpm
报错“ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory”
sudo mkdir /usr/var
sudo mkdir /usr/var/log
sudo chmod 777 /usr/var/log
sudo php-fpm
到此php正常启动,接下来配置php.ini文件
sudo cp /etc/php.ini.default /etc/php.ini
sudo chmod 777 /etc/php.ini
sudo killall php-fpm
php-fpm
有两个notice,暂时不管
NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
7、配置nginx
sudo vi /usr/local/etc/nginx/nginx.conf
修改监听端口为80
加上以下内容使nginx可以处理php
location ~ \.php$ {
root /path/to/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /path/to/wwwroot$fastcgi_script_name;
}
启动nginx
sudo nginx
8、编辑mysql配置文件
检查mysql的运行状态
ps -ef | grep mysql
/usr/local/Cellar/mysql/5.6.25
/usr/local/opt/mysql/my.cnf
/usr/local/opt/mysql/bin/mysqld