Install nginx php7 under linux

  
        

Before installing, understand the relationship between nginx and php. nginx is like a messaging officer, forwarding requests to php-fpm. This requires knowing the php-fpm contact method. The value of listen is the phone number of php-fpm. When the request comes, nginx calls php-fpm, saying that someone is looking for you, php-fpm sends someone to pick up the guest, and the person who sent it is a php process. Seeing that you believe in cleverness here, you understand that php-fpm is responsible for managing the scheduling of php processes.

Getting started with the configuration

Because it is a personal computer, you can use the apt command directly.

sudo install nginxsudo apt-get install php7.0-fpm php7. 0-mysql php7.0-common php7.0-curl php7.0-cli php7.0-mcrypt php7.0-mbstring php7.0-dom

More php module is not bad, save the time to report error, back If the component is missing, you can continue to install it, which is very convenient. If the downloaded source package is compiled by itself, it is more troublesome. You need to install some class libraries first. Everything here is simple, mainly to introduce how nginx and php7 work together. After executing the above two commands, the software is done. First, let's take a look at the php-fpm configuration /etc/php/7.0/fpm/pool.d/www.conf (if it is centos or compile and install, the address of the configuration file will be different), find it in the configuration file. Br>

listen=/run/php/php7.0-fpm.sock# It is also possible that listen=127.0.01:9000

No matter what, anyway, remember that listen=what, this is very important, this explains What is fpm listening to? Look at nginx's configuration /etc/nginx/sites-enabled/default, (if it is centos or compile and install, the address of the configuration file will be different), find server{} in the configuration file, this represents you Web hosting. Find

location ~ \\.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: ​​# fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: Fastcgi_pass unix:/run/php/php7.0-fpm.sock; }

See fastcgi_pass, who will forward the request to whom. Who is it for? You are sure to be smart, that is, the one we listened to in php-fpm above. If php-fpm is listen=/run/php/php7.0-fpm.sock then use fastcgi_pass unix:/run/php/php7.0-fpm.sock in nginx; if php-fpm is listen=127.0 .01:9000 Then use fastcgi_pass 127.0.0.1:9000 in nginx;

Copyright © Windows knowledge All Rights Reserved