安装版本号:
1 2 3 4 | MAC OS 10.11 Mysql:5.7.9 Nginx:1.8.0 PHP:5.6.16 |
Homebrew安装
1 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ Homebrew/install/master/install)" |
安装php-fpm
1 2 3 4 | // 因为已经安装homebrew 所以可以直接使用homebrew安装php-fpm brew tap homebrew /dupes brew tap homebrew /php brew install --without-apache --with-fpm --with-mysql php56 |
安装完成 现在我们将php-fpm 添加入环境变量中 方便我们通过终端直接进行启动
1 2 3 4 | echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile #If you use bsh echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc #If you use ZSH |
创建文件夹 并启动服务
1 2 3 | mkdir -p ~ /Library/LaunchAgents ln -sfv /usr/local/opt/php56/homebrew .mxcl.php56.plist ~/ Library /LaunchAgents/ launchctl load -w ~ /Library/LaunchAgents/ homebrew.mxcl.php56.plist |
如果没有报出什么bug的话 在终端中键入
1 | lsof -Pni4 | grep LISTEN | grep php |
应该会有下图的显示
1 2 3 4 | php-fpm 44147 magentonotes 6u IPv4 0x1fbca9574e04090b 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 44148 magentonotes 0u IPv4 0x1fbca9574e04090b 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 44149 magentonotes 0u IPv4 0x1fbca9574e04090b 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 44150 magentonotes 0u IPv4 0x1fbca9574e04090b 0t0 TCP 127.0.0.1:9000 (LISTEN) |
安装mysql
1 2 | brew install mysql ln -sfv /usr/local/opt/mysql/ *.plist ~ /Library/LaunchAgents |
添加mysql到环境变量中
1 | launchctl load ~ /Library/LaunchAgents/ homebrew.mxcl.mysql.plist |
进入mysql的初始化环节 去确认一些mysql的缺省选项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | mysql_secure_installation Enter current password for root (enter for none) ##回车 我们并不需要 > Change the root password? [Y /n ] 如不愿意使用root密码缺省mysql的password 输入n 并键入自己想使用的password > Remove anonymous users ? [Y /n ] Yes. 匿名用户我们并不需要 > Disallow root login remotely? [Y /n ] Yes. 我们仅需要127.0.1 > Remove test database and access to it? [Y /n ] Yes. 无需保留冗余的测试文件 > Reload privilege tables now? [Y /n ] Yes.重新加载数据库 |
测试mysql
1 | mysql -uroot -p |
输入root密码
1 2 3 4 5 | Type \'help;\' or \'h\' for help. Type \'c\' to clear the current input statement. mysql> #退出mysql 输入 \q |
安装phpmyadmin
1 | brew install autoconf |
设置$PHP_AUTOCONF 环境变量
1 2 3 4 | #bash环境 echo 'PHP_AUTOCONF="' $( which autoconf) '"' >> ~/.bash_profile && . ~/.bash_profile #zsh环境 echo 'PHP_AUTOCONF="' $( which autoconf) '"' >> ~/.zshrc && . ~/.zshrc |
安装phpmyadmin
1 | brew install phpmyadmin |
安装Nginx
1 | brew install nginx |
必须确保80端口是开启的,因为nginx是基于80端口的
1 2 | sudo cp - v /usr/local/opt/nginx/ *.plist /Library/LaunchDaemons/ sudo chown root:wheel /Library/LaunchDaemons/homebrew .mxcl.nginx.plist |
第一次启动Nginx
1 | sudo launchctl load /Library/LaunchDaemons/homebrew .mxcl.nginx.plist |
默认的配置设置是将监听8080端口而非http默认的80端口
1 | curl -IL http: //127 .0.0.1:8080 |
停止nginx
1 | sudo launchctl unload /Library/LaunchDaemons/homebrew .mxcl.nginx.plist |
配置Nginx
1 2 3 4 5 6 7 8 | mkdir -p /usr/local/etc/nginx/logs 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 /var/www sudo chown :staff /var/www sudo chmod 775 /var/www |
移除默认的nginx配置文件
1 2 | rm /usr/local/etc/nginx/nginx .conf curl -L https: //gist .github.com /frdmn/7853158/raw/nginx .conf -o /usr/local/etc/nginx/nginx .conf |
配置PHP FPM
1 | curl -L https: //gist .github.com /frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf .d /php-fpm |
创建默认虚拟机
1 2 3 | curl -L https: //gist .github.com /frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default curl -L https: //gist .github.com /frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-ssl curl -L https: //gist .github.com /frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin |
使用git clone demo
1 2 | git clone http: //git .frd.mn /frdmn/nginx-virtual-host .git /var/www rm -rf /var/www/ .git |
安装ssl
创建文件夹来存放ssl的证书和私钥
1 | mkdir -p /usr/local/etc/nginx/ssl |
生成4096比特 的RSA秘钥
1 2 | openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \" /C =US /ST =State /L =Town /O =Office /CN =localhost\" -keyout /usr/local/etc/nginx/ssl/localhost .key -out /usr/local/etc/nginx/ssl/localhost .crt openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \" /C =US /ST =State /L =Town /O =Office /CN =phpmyadmin\" -keyout /usr/local/etc/nginx/ssl/phpmyadmin .key -out /usr/local/etc/nginx/ssl/phpmyadmin .crt |
使用虚拟主机
1 2 3 | ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default ln -sfv /usr/local/etc/nginx/sites-available/default-ssl / usr /local/etc/nginx/sites-enabled/default-ssl ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin |
启动nginx
1 | sudo launchctl load /Library/LaunchDaemons/homebrew .mxcl.nginx.plist |
打开下面的这些网站,来确认自己的nginx是否正确安装
1 2 3 4 5 6 7 | http: //localhost → \"Nginx works\" page http: //localhost/info → phpinfo() http: //localhost/nope → \" Not Found\" page https: //localhost :443 → \"Nginx works\" page (SSL) https: //localhost :443 /info → phpinfo() (SSL) https: //localhost :443 /nope → \"Not Found\" page (SSL) https: //localhost :306 → phpMyAdmin (SSL) |
设置服务的别名
1 2 3 4 5 6 | curl -L https: //gist .github.com /frdmn/7853158/raw/bash_aliases -o /tmp/ .bash_aliases cat /tmp/ .bash_aliases >> ~/.bash_aliases // If you use Bash echo \" source ~/.bash_aliases\" >> ~/.bash_profile // If you use ZSH echo \" source ~/.bash_aliases\" >> ~/.zshrc |
更新变量 让设置生效
1 2 3 | source ~/.bash_profile //or source ~/.zshrc` |
1 2 3 4 5 6 7 8 9 10 11 12 | nginx.start nginx.stop nginx.restart #错误或访问日志 nginx.logs.access nginx.logs.default.access nginx.logs.phpmyadmin.access nginx.logs.default-ssl.access nginx.logs.error nginx.logs.phpmyadmin.error #检查配置文件 sudo nginx -t |
参考资料:
https://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/
原创文章,转载请注明:转载自Web开发笔记 | Mac安装配置PHP/Mysql/Nginx/SSL
本文链接地址:https://www.magentonotes.com/mac-os-install-php-mysql-nginx.html
Comments on this entry are closed.