Question

Issues i've been having with a new droplet here on DigitalOcean

Posted December 9, 2019 288 views
NginxPHP

Hello,

So after conducting a long research and not being able to find an answer to my problems, i’ve decided to ask for help.
I recently joined DigitalOcean as a client and created my first droplet, with the intention of migrating from another service.
It runs on Ubuntu 18.04, it has Nginx and PHP 7.2 installed.
I’ve been knocking my head trying to figure out why wouldn’t it run any php files in the /var/www/html folder, instead i get the “This site can’t be reached” for a simple <?php phpinfo(); >? .
It runs html files just fine so it must have something to do with the php setup.

It almost always is something simple, this time however i cannot seem to find out what it is, would someone be able to help?

Here is my default config for nginx:

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        # With php-cgi (or other tcp sockets):
        #fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

    location ~ /\.ht {
        deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

And PHP seems to be running fine:

php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-12-09 13:26:59 UTC; 30min ago
     Docs: man:php-fpm7.2(8)
 Main PID: 14842 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 2, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 4704)
   CGroup: /system.slice/php7.2-fpm.service
           ├─14842 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─14866 php-fpm: pool www
           └─14867 php-fpm: pool www

Dec 09 13:26:59 ubuntu-s-2vcpu-4gb-fra1-01 systemd[1]: Starting The PHP 7.2 FastCGI Process Manager...
Dec 09 13:26:59 ubuntu-s-2vcpu-4gb-fra1-01 systemd[1]: Started The PHP 7.2 FastCGI Process Manager.

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.

×
1 answer

Hello,

It looks like that Nginx is unable to connect to the PHP-FPM socket. I would recommend checking your Nginx for some more information about the exact problem:

tail -100 /var/log/nginx/error.log

But what I think that the problem might be is the path to the PHP-FPM socket file, what you could do is check if the socket exists at the folder that you’ve specified:

ls -l /var/run/php/php7.2-fpm.sock

If you get No such file or directory, then I would recommend checking your PHP-FPM config file to see the correct path to the socket. To do that open the /etc/php/7.2/fpm/pool.d/www.conf file with your favourite text editor and look for a listen line, it should look something like this:

listen = /run/php/php7.2-fpm.sock

Make sure that the path in your Nginx config is the same as the one from the PHP-FPM config.

Hope that this helps!
Regards,
Bobby

Submit an Answer