Run PHP using nginx

Run php script using Nginx:

Prerequisites:

  • fastcgi: is a protocol like http for transfering binary data. fastcgi binary protocol is used for interfacing interactive programs with a web server.
  • php fpm: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites.
#install php fpm
apt-get install php-fpm
#find php fpm, default location: /run/php/php*-fpm.sock
find / -name *fpm.sock
#find nginx fastcgi, default locations: /usr/local/vesta/nginx/conf/fastcgi.conf or /etc/nginx/fastcgi.conf
find / -name fastcgi.conf

Nginx configuration:

server{
	#...
	location ~ \.php{
        root /path/to/php/files;
        include /usr/local/vesta/nginx/conf/fastcgi.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
}