Installing Nginx
Use the Brew Package management tool to install Nginx
http://brew.sh/
Official online at a glance, the use is very simple.
After successful installation, execute the brew install Nginx directly in the terminal.
After installation, under/usr/local/cellar/can see the installation of Nginx package, Cellar directory is dedicated to put the brew installed package, all the relevant configuration files under/usr/local/etc/nginx/.
Configure Nginx
The initial nginx listen is the 8080 port, according to the Convention changed to 80 port, pay attention to bring your own Apache off.
At this time to execute the nginx command, the browser localhost can see the welcome, but still cannot execute PHP files, because there is no configuration with PHP connection, here will use PHP-FPM, First to add fastcgi configuration in Nginx configuration file:
Location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename /usr/local/cellar/nginx/1.8.0/html$fastcgi_script_name; Include fastcgi_params; }
The corresponding modifications can be made by reference to the above configuration.
Configure PHP-FPM
Then modify the configuration of the Error_log and PID in the PHP-FPM configuration file:
Go to config file, sudo vim/private/etc/php-fpm.conf
Error_log =/usr/local/var/log/php-fpm.logpid =/usr/local/var/run/php-fpm.pid
Refer to the corresponding modifications.
Open PHP-FPM:
sudo/usr/sbin/php-fpm
Re-start Nginx
Nginx-s Reload
Test the PHP file in the server root directory.
Nginx and Apache The most intuitive difference is that Apache can be PHP as a sub-module, thus directly parsing PHP, and nginx can not do, only through the fastcgi mode with PHP connection, of course, Apache can also use fastcgi mode. The PHP-FPM (Process Manager) is the tool that manages fastcgi, and after the PHP5.3 version, PHP comes with it.
FastCGI and PHP-FPM related knowledge Reference:
What is fastcgi and php-fpm in PHP?
The above describes the Mac OS X using Nginx and PHP connection issues, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.