Connection between Nginx and PHP in MacosX

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.