: This article describes how to connect Nginx to PHP in MacosX. For more information about PHP tutorials, see. Install Nginx
Use brew package management tool to install Nginx
Http://brew.sh/
The official website is clear and easy to use.
After the installation is successful, run brew install nginx in terminal.
After installation, you can see the installed nginx package under/usr/local/Cellar/. the Cellar directory is specially used to release the brew installation package, all related configuration files are stored in/usr/local/etc/nginx.
Configure Nginx
The initial Nginx listen port is port 8080, which can be changed to port 80 by convention. Note that the built-in Apache is disabled.
At this time, if you run the nginx command, you can see the welcome in the localhost in the browser, but you still cannot execute the PHP file, because the connection to php is not configured at all, so you need to use PHP-fpm here, add the fastcgi configuration in the 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; }
You can modify the configuration according to the preceding configuration.
Configure php-fpm
Then, modify the error_log and pid configuration in the php-fpm configuration file:
Enter the configuration file, sudo vim/private/etc/php-fpm.conf
error_log = /usr/local/var/log/php-fpm.logpid = /usr/local/var/run/php-fpm.pid
Make corresponding modifications with reference.
Open php-fpm:
Sudo/usr/sbin/php-fpm
Restart nginx
Nginx-s reload
Test the php file in the root directory of the server.
The most intuitive difference between Nginx and Apache is that Apache can use PHP as a sub-module to directly parse PHP. Nginx cannot do this and can only connect to PHP in fastcgi mode, of course, Apache can also use fastcgi mode. Php-fpm (process manager) is a tool for managing fastcgi. PHP will come with it after PHP5.3.
For more information about fastcgi and php-fpm, see:
What are fastcgi and php-fpm in php?
The above describes how to use Nginx to connect to PHP in Mac OS X, including some content, and hope to help those who are interested in PHP tutorials.