Mac 下搭建 nginx + mysql + php + fpm
homebrew
安装 homebrew
1
| /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
homebrew 帮助文档 man brew
nginx
安装 nginx
配置 nginx
安装完成后通过 brew info nginx
查看安装信息,nginx 配置文件目录在 /usr/local/etc/nginx/
下,通过 nginx.conf
主配置文件可以知道,nginx 会加载当前目录 servers
下所有的配置文件。现在我们新增配置文件 localhost-700.conf
来监听本地 700 端口的所有请求:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| server { listen 700; server_name localhost; root /Users/your/home/dir/www; index index.html index.htm index.php; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
|
启动并测试 nginx
1 2 3 4 5 6 7 8
| nginx -t sudo nginx sudo nginx -s reload|reopen|stop|quit
|
自启动 nginx
Nginx 监听 1000
以下的端口需要 root
权限执行,所以应当使用 sudo
执行相关操作:
1
| sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
|
取消开机自动启动服务:
1
| sudo launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
|
mysql
安装及配置 mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| brew install mysql mysql.server start mysql_secure_installation mysql -uroot -p CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES;
|
mysql 自启动
1
| sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
|
安装 mysql 图形化工具
Sequel Pro
php 及 php-fpm
配置 php
Mac 自带 php 及 php-fpm,只需要配置一下就行:
1 2 3 4 5 6 7 8 9
| php -i | grep config sudo cp /etc/php.ini.default /etc/php.ini chown <你的用户名> /etc/php.ini chmod u+w /etc/php.ini
|
配置 fpm
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf vi /usr/local/etc/php-fpm.conf pid = /usr/local/var/run/php-fpm.pid error_log = /usr/local/var/log/php-fpm.log php-fpm sudo pkill php-fpm
|
fpm 自启动
在 ~/Library/LaunchAgents/
下新建 fpm 自启动配置文件 org.php.php-fpm.plist
:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>php-fpm</string> <key>Program</key> <string>/usr/sbin/php-fpm</string> </dict> </plist>
|
自启动:launchctl load -w ~/Library/LaunchAgents/org.php.php-fpm.plist
参考