nginx from and php7.1

Hi, I was testing nginx with dynamic modules from but I could not get php7.1-fmp wordking. Nginx works, modules works but not php. I am not to knowledgeable is server management. I followed this tutorial except for nginx that I installed from ppa and mariadb instead of mysql: Something is missing but I don’t know what?

Thank you


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer


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


git clone

Followed by:

cd installers/nginx
chmod +x

And finally:


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


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:


and change listen to use and restart php-fpm and the example I provided will work without any changes other than those for your domain.


If you installed NGINX and then used the auto-installer that I posted without removing the previous install, it’s most likely attempting to use the version that you installed from the OS repositories.

You should be able to run apt-get remove nginx to remove the repository version that was installed. That shouldn’t remove anything that the auto-installer created, though I’d still recommend backing up the /etc/nginx directory.

Something such as:

mkdir -p /usr/local/src/nginx

…and then:

cp -R /etc/nginx/* /usr/local/src/nginx

That way if something doesn’t work, you can copy the files back in to place from the backup directory.

@jtittle From my google search I need to purge and reinstall nginx. Do you see any other options?

@jtittle The error log shows: 2017/05/19 16:46:57 [emerg] 1297#1297: open() “/etc/nginx/nginx.conf” failed (2: No such file or directory)

My nginx conf is in /etc/nginx/config/nginx.conf

Why does it think it is in /etc/nginx/nginx.conf and how do I tell it to go in /etc/nginx/config/nginx.conf

@jtittle Just updated my ubuntu 16.04 droplet and now nginx won’t load. In troubleshooting mode now, if you have any steps that would save me time please tell me.

Thank you

@jtittle Well I feel stupid, I just forgot to run it with sudo. All good.

@jtittle Thank you I have pagespeed and naxsi running. When I run nginx -t I get these:

nginx: [alert] could not open error log file: open() “/etc/nginx/logs/error.log” failed (13: Permission denied) 2017/04/02 19:09:53 [warn] 8021#8021: the “user” directive makes sense only if t he master process runs with super-user privileges, ignored in /etc/nginx/config/ nginx.conf:7 2017/04/02 19:09:53 [info] 8021#8021: [ngx_pagespeed] No threading d etected. Own threads: 1 Rewrite, 1 Expensive Rewrite. 2017/04/02 19:09:53 [info] 8021#8021: pagespeed: rollback gzip, explicit configu ration in /etc/nginx/config/nginx.conf:51 nginx: the configuration file /etc/nginx/config/nginx.conf syntax is ok 2017/04/02 19:09:53 [emerg] 8021#8021: open() “/etc/nginx/pid/” failed (13: Permission denied) nginx: configuration file /etc/nginx/config/nginx.conf test failed

Not sure how to fix.


As a general note, I would recommend commenting out max_input_time. It’s default setting is -1, which means PHP will use max_execution_time instead.

I would then set max_execution_time to something like 60 as setting it to 200 means that a script can run for a little over 3 minutes before it’s killed off. Setting it to 120 is about the max I would recommend unless you’re going to be uploading large files that you know will require more time to complete.

As for cgi.fix_pathinfo=0, the latest versions of PHP should be able to correctly handle what was once an issue, whether you have this set to 1 or 0.

The better option would be to make sure that you have set:

security.limit_extensions = .php

In your PHP-FPM pool file. The default is:


Where [vers] is the PHP version you’re running.

The reason for this setting was to prevent requests, such as:

… from executing image.jpg as a PHP file when file.php isn’t found. What the above setting does is tells PHP-FPM that unless it has a .php extension, it shouldn’t be executed as a PHP file.

Now, that doesn’t stop someone from uploading a PHP file using your uploader and then executing it – keep that in mind. That falls on the application (i.e. such as WordPress) to limit what extensions can be uploaded by an admin/user/etc by configuration options, built-in core options, or a plugin.

@jtittle Thank you!! So many little settings.


Ideally, if your database is more than a few MB’s in size, you want to use MySQL’s CLI interface to do a restore. A web-based interface, such as phpMyAdmin or Adminer should be able to handle it, though it’s not the best tool for the job.

That being said, if you want to use a web-based interface to do the restore, you’ll need to modify one more variable, and that’d be client_max_body_size 50m;, which can be found in:


You’ll need to change the current 50m to match that of your php.ini, or change them all to a value a little over, such as 64m. You’d then want to reload NGINX using:

systemctl reload nginx

If you want to do this using MySQL’s CLI, you’d use:

mysql -u dbuser -p dbname < db.sql

Where dbuser is the database username, -p will prompt you for the password, dbname is the name of the database, and db.sql is the SQL dump file that you created.

To run that command, you’d login as root using SSH, or your sudo user. You don’t need to actually enter the MySQL CLI, just change the placeholders and run the command as-is.

@jtittle Two more questions:

  1. I can not import my database into the new droplet, it give me an connection error, I use adminer. I changed these setting in php.ini
upload_max_filesize 120M
post_max_size 120M
max_execution_time 200
max_input_time 200

Still does not work. Any workaround this? Database in 54mg

  1. I just realize my previous issue was this line in php.ini

This toturial claims it is safer but it seems to conflict with your install, is it safe to just comment it?