Environmental information:
Mac OS X 10.11.1
Homebrew 0.9.5
Body
First, install Nginx
- Terminal execution:
Brew Search Nginxbrew Install Nginx
Current version 1.6.2
After installation, you can see some configuration paths in the terminal output information:
/usr/local/etc/nginx/nginx.conf (Profile path)/usr/local/var/www (server default path)/usr/local/cellar/nginx/1.6.2 (seemingly an installation path)
Ii. Visit localhost:8080
Nginx default port 8080, you can already access:
localhost:8080
There will be a default welcome interface.
Third, modify the php-fpm file
1. Execute the command:
sudo cp/private/etc/php-fpm.conf.default/private/etc/php-fpm.conf
2. Locate the php-fpm file in the directory
/private/etc/php-fpm.conf
3. Find 32 lines of error_log, instead (positive line substitution, note '; ' and spaces):
Error_log =/usr/local/var/log/php-fpm.log
Otherwise PHP-FPM will be error:
error:failed to open Error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
Iv. Modification of Nginx configuration
- Open Nginx.config File
/usr/local/etc/nginx/nginx.conf
2. Locate the server location configuration and add a index.php to index
Location/{ root html; Index index.html index.htm index.php;}
3. And open the annotated location ~.php$ under Server (that is, ' # ' in front of the delete code), as follows:
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;}
4. And modify the Fastcgi_param parameters
Fastcgi_param script_filename /scripts$fastcgi_script_name; instead Fastcgi_param script_filename $document _root$fastcgi_script_name;
V. Creation of index.php
In the/usr/local/var/www directory, delete index.html, create index.php, enter
<?php phpinfo ();?>
Vi. launch of related services
sudo nginxsudo php-fpm
Then access the localhost:8080, see the PHP configuration information, the explanation is OK
Vii. Other Orders
After modifying nginx.conf, reload the configuration file
sudo nginx-s reload
Stop Nginx Server
sudo nginx-s stop
Stop PHP-FPM can be stopped directly in Activity Monitor. You can also use scripts to stop.
Viii. problems that may arise
1. Visit index.php 403 Forbidden. View (four. 2) in the step, whether to add index.php after index.
2. Visit index.php File not found. See (four. 4), Fastcgi_param parameter is modified.
Mac under Nginx environment configuration