@stephgiguere
Generally this section:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
… would look something like:
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
The difference being we’re swapping snippets/fastcgi-php.conf
with fastcgi_params
.
Not all NGINX repositories have a snippets
directory that contains blocks of code. Even if they do, not all of them contain everything that’s needed (at least, that has been my experience).
…
If you don’t mind trying something different, and you have a few extra minutes, I wrote and installer for NGINX that handles a source installation hands-free.
It includes HTTP2, Brotli, a few modules, and multiple example configurations with it.
If you run:
cd /opt
Then:
git clone https://github.com/serveradminsh/installers.git
Followed by:
cd installers/nginx
chmod +x installer.sh
And finally:
./installer.sh
You’ll have a fully configured and optimized NGINX setup with a working PHP configuration that you can copy from the ./installers/nginx/examples
directory.
Within this directory there’s a php
directory which contains a php.conf
file. That’s the one you need and to set it up, all you’d do is:
cp installers/nginx/examples/php/php.conf /etc/nginx/sites/yourdomain.conf
Then:
nano /etc/nginx/sites/yourdomain.conf
… and configure it to your liking. There’s also examples on how to setup SSL, Load Balancing, Proxy, and others.
The installer will take about 20-30 minutes as this is a source compile, not a stock repo package. It’s detailed and sets up everything you’d have to do a source compile to setup. A systemd
service is also included, so NGINX is controlled using:
systemctl start nginx
systemctl restart nginx
systemctl stop nginx
The only thing I’d recommend doing is:
1). Run the installer on a fresh Ubuntu 16.04 droplet, or;
2). Run:
apt-get -y remove nginx
apt-get -y purge nginx
rm -rf /etc/nginx
This wipes your current NGINX installation, so if you need to backup anything, do it before the above commands. That said, the installer has all the examples you need to get things working and I will be more than happy to help should you have any questions.
As for the examples
directory, most are setup so that you only need to change the server_name
directive. The only other thing you may need to modify is the fastcgi_pass
directive since you’re using sockets instead of TCP, or you can modify:
/etc/php/7.1/fpm/pool.d/www.conf
and change listen
to use 127.0.0.1:9000
and restart php-fpm
and the example I provided will work without any changes other than those for your domain.