Home  >  Article  >  Backend Development  >  Connection problem between Nginx and PHP under Mac os X

Connection problem between Nginx and PHP under Mac os X

WBOY
WBOYOriginal
2016-07-29 09:03:29790browse

Install Nginx

Use brew package management tool to install Nginx

http://brew.sh/

The official website is clear at a glance, and it is very simple to use.

After the installation is successful, just execute brew install nginx directly in the terminal.

After installation, you can see the installed nginx package under /usr/local/Cellar/. The Cellar directory is specially used to store the packages installed by brew. , all related configuration files are under /usr/local/etc/nginx/.

Configuring Nginx

The initial Nginx listen port is 8080. Just change it to port 80 as usual. Be careful to turn off the built-in Apache.

Execute the nginx command at this time. You can see welcome in localhost in the browser, but you cannot execute the PHP file because the connection with PHP is not configured at all. You need to use php-fpm here. First, you need to configure nginx Add fastcgi configuration to the 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;
        }
can refer to the above configuration to make corresponding modifications.

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.log
pid = /usr/local/var/run/php-fpm.pid
refer to the corresponding Modifications.

Open php-fpm:

sudo /usr/sbin/php-fpm

Restart nginx

nginx -s reload

Test the PHP file in the server root directory.


The most intuitive difference between Nginx and Apache is that Apache can use PHP as a sub-module to directly parse PHP, but Nginx cannot do this and can only connect to PHP through fastcgi mode. Of course, Apache can also use fastcgi mode. . And php-fpm (process manager) is a tool for managing fastcgi. After PHP5.3 version, PHP will come with it.

fastcgi and php-fpm related knowledge reference:

What are fastcgi and php-fpm in php

The above introduces the connection issues between using Nginx and PHP under Mac os

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:sublime opens php promptNext article:sublime opens php prompt