Question

Can't figure out Nginx PHP

I’ve been scouring through all the nginx, Wordpress, PHP threads but I can’t seem to get what I need. I have a Ghost blog installed (working fine) and am trying to add a Wordpress along side it. The Wordpress block looks like:

server {                                                     
        listen 80;                                           
        listen [::]:80;                                      
                                                             
        root /var/www/html;                                  
        index index.php index.html index.htm;                
                                                             
        server_name wpdomain.com;                        
                                                             
        location / {                                         
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }                                                    
                                                             
        error_page 404 /404.html;                            
        error_page 500 502 503 504 /50x.html;                
                                                             
        location = /50x.html {                               
                root /usr/share/nginx/html;                  
        }                                                    
                                                             
        location ~ \.php$ {                                  
                try_files $uri =404;                         
                fastcgi_split_path_info ^(.+\.php)(/.+)$;    
                fastcgi_pass 127.0.0.1:9000;                 
                fastcgi_index index.php;                   
                include fastcgi_params;                      
        }                                                    
                                                             
}                                                            

I’ve tried the alternative:

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

with the appropriate listen adjustment to no avail.

The status looks 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 Thu 2018-02-22 00:22:56 UTC; 6min ago
     Docs: man:php-fpm7.2(8)
 Main PID: 22063 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 6, slow: 0, Traffic: 0req/sec"
    Tasks: 3
   Memory: 11.4M
      CPU: 68ms
   CGroup: /system.slice/php7.2-fpm.service
           ├─22063 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─22066 php-fpm: pool www
           └─22067 php-fpm: pool www

and I can access the non-php files just fine, but I can’t setup Wordpress until I can actually access the PHP. I’m not seeing errors in /var/log/nginx/error.log either, I’m not sure what else to check at this point…


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

server {                                                     
        listen 80;                                           
        # listen [::]:80; ## only need this directive if you are using ipv6

        root /var/www/html;                                  
        index index.php index.html index.htm;                

        server_name wpdomain.com;                        

        location / {                                         
                try_files $uri $uri/ /index.html /index.php$args; #removed unneeded args 
        }                                                    

        # remove these for now until WP is up and running
        # error_page 404 /404.html;                            
        # error_page 500 502 503 504 /50x.html;                

        # location = /50x.html {                               
        #       root /usr/share/nginx/html;                  
        #}                                                    

        location ~ \.php$ {                                  
                try_files $uri =404;                         
                fastcgi_split_path_info ^(.+\.php)(/.+)$;    
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;                 
                fastcgi_index index.php;                   
                include fastcgi_params;                      
        }                                                    
}

ensure the WP directory has the right permissions:

find /var/www/html -type d -exec chmod 755 {} \;

find /var/www/html -type f -exec chmod 644 {} \;


You may want to look into a configuration similar to this : https://www.digitalocean.com/community/tutorials/how-to-host-multiple-websites-securely-with-nginx-and-php-fpm-on-ubuntu-14-04