Ask your WordPress questions! Pay money and get answers fast! (more info)

Need help with Nginx virtual host setup WordPress

  • SOLVED

I've always used LAMP and I now have a LEMP server, and I can't get it to load PHP files on the browser. They simply want to download.

This is a fresh LEMP install using Debian 8.x. I need someone to configure Nginx to serve up PHP files so I can setup WordPress.

I can provide SSH access.

Here's a current sample config:


server {
listen 80;
listen [::]:80;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/thatoilylife.com/public_html;

# Add index.php to the list if you are using PHP
index index.php index.html;

server_name www.thatoilylife.com thatoilylife.com;

#location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

Answers (1)

2015-09-23

dimadin answers:

Since this is the first time that you are using LEMP, I suggest you to try EasyEngine (https://rtcamp.com/easyengine/). It is simple open source script that configures your fresh server, you can literally have WordPress site in several minutes with just few simple commands.

In your case, have you tried uncommenting fist two 'location' blocks? Uncommenting means removing # from the begging of first character on the line that you want to uncomment.

It means that your code would look something like:


location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

try_files $uri $uri/ =404;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

include snippets/fastcgi-php.conf;

#

# # With php5-cgi alone:

fastcgi_pass 127.0.0.1:9000;

# # With php5-fpm:

fastcgi_pass unix:/var/run/php5-fpm.sock;

}


I don't know if this would work or it just an example that needs to be configured. What I do know that when you setup server with EasyEngine you get this part slightly modified so it looks like this:


location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
}


This works for me. Please note that this needs to be placed inside you


server {
}


block but not at the begging of it, in your example it is best to put it before your last closing bracket }.

Also don't forget to reload nginx whenever you made changes to this file (you might want to reload it before continuing if you made changes to default value but you have not reloaded). Command for reloading nginx is

service nginx reload