首页 > 代码库 > mac下安装配置nginx,php环境
mac下安装配置nginx,php环境
1、安装nginx
在mac系统下我们使用brew来安装nginx,使用brew来安装,它会自动安装相应的依赖库。
brew install nginx
在安装完毕后,终端会输出配置信息:
Docroot is: /usr/local/var/www ( 服务文档根路径)
The default port has been set in /usr/local/etc/nginx/nginx.conf (配置文件路径)to 8080 (默认端口)so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx (后台运行)
Or, if you don‘t want/need a background service you can just run:
nginx
这时通过localhost:8080就能访问默认的欢迎页面了。
2、修改默认端口
修改/usr/local/etc/nginx/nginx.conf 配置文件
server {
listen : 80 #改为希望使用的端口
}
3、安装php
mac下默认已经安装好php了。
只需修改php-fpm配置文件即可
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
打开PHP-fpm文件
找到error_log这行将其修改为:
error_log = /usr/local/var/log/php-fpm.log
不然会报错
ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
3、修改nginx配置文件加入php配置信息
3.1 打开 /usr/local/etc/nginx/nginx.conf
3.2 找到 server 的 location 配置,给 index 加一个 index.php
location / { root html; index index.html index.htm index.php; }
3.3 找到 server 下被注释的 location ~.php$(删除‘#’),如下:
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
将fastcgi_param 修改为
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
4、启动相应服务
sudo nginx
sudo php-fpm
mac下安装配置nginx,php环境