Categories
Programming Server Ubuntu

Getting PHP 7.2 to work with NGINX (UBUNTU)

This took a while. I’m much, much more familiar with running apache. I really like how fast and light nginx is, though, and was going to start using it, no matter what.

In the end, it was a combination of all of these things:

  • When I upgrade to nginx 1.17, there is a new “include” line in the nginx.conf file, and suddenly nginx was looking for site config files in this directory (/etc/nginx/conf.d/) instead of the usual one (/etc/nginx/sites-enabled). Had to change that first thing.
  • The nginx process was trying to run under the “nginx” user, instead of “www-data”. Basically, the “user” config in both your php conf files and your nginx conf files must match, or the php-fpm process ignores the requests from nginx.
  • Most tutorials I’ve found on the internet want you to insert specific php-related config into your nginx site config that points php to a certain port, like this:
    • "fastcgi_pass 127.0.0.1:9000;:".
  • However, my php-fpm was configured to run under a unix socket only (you find this via the “listen” param in your php config). So, I had to add the following line to my nginx site config instead in the php section:
    • "fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;"
  • I had to include the following line in my php-specific config in my site conf file for nginx. Even the nginx example conf file is not explicit about this:
    • include snippets/fastcgi-php.conf;

Leave a Reply