Tutorial

How To Install WordPress with Nginx on Ubuntu 14.04

Published on May 15, 2014
How To Install WordPress with Nginx on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04

Introduction

WordPress is the most popular CMS (content management system) in the world. It allows you to easily get your site or blog up and running. After installation, you can manage almost everything in an easy web interface.

In this guide, we will go over how to install WordPress on an Ubuntu 14.04 server. For the web server component, we will use nginx, a powerful and efficient web server that has seen wide adoption due to its performance capabilities.

Prerequisites

Before you begin with this guide, there are a few procedures that you should undertake.

First, you will need a non-root user with sudo privileges. You can run through steps 1-4 in the Ubuntu 14.04 initial server setup guide to create this account.

You will also need a LEMP (Linux operating system, Nginx web server, MySQL database, and PHP processing) stack installed and configured on your server. You can learn how to install and set up the necessary components by following our guide on installing a LEMP stack on Ubuntu 14.04 here.

When you have finished with the steps above, you can continue.

Step One — Create a MySQL Database and User for WordPress

The first thing that we need to do to get started with WordPress is to prepare our database.

We have the MySQL database software installed, but we have not created a database for our WordPress information. We also need to create an account that WordPress can use to access the database we will be creating.

We should begin by logging into an interactive session with our MySQL administrative account like this:

mysql -u root -p

You will be prompted for the password that you chose for the MySQL root account when you installed the software. You will be given a MySQL command prompt.

Now, we can create a separate database that will be used exclusively by our WordPress application. The name is not important, but it should probably be descriptive so that you can easily recognize it. In this guide, we will call our database wordpress:

<pre> CREATE DATABASE <span class=“highlight”>wordpress</span>; </pre>

Note the semi-colon (;) that ends the MySQL statement. Each MySQL statement must end with one, so double-check that if you are running into issues.

We have a database now, so we are ready to create a user account. We will then hand over control of the database to this new user so that our application can interact with the database. This system of creating a separate database and user for each application helps keep our data separate from other data being stored by MySQL, which is good for security and data management.

For this guide, we’ll pick wordpressuser for our account name. We’ll assign it a password of password to authenticate with. When you are setting up your own configuration, you should select a more secure password:

<pre> CREATE USER <span class=“highlight”>wordpressuser</span>@localhost IDENTIFIED BY ‘<span class=“highlight”>password</span>’; </pre>

Now, we have a database and a user, but we haven’t established a relationship between the two yet. We need to tell MySQL that our new user can access and control the database. You can do that with this command:

<pre> GRANT ALL PRIVILEGES ON <span class=“highlight”>wordpress</span>.* TO <span class=“highlight”>wordpressuser</span>@localhost; </pre>

Everything should be configured correctly now. We need to flush the privileges to disk so that our current instance of MySQL knows about the privilege changes we have made:

FLUSH PRIVILEGES;

Now, exit the MySQL prompt:

exit

Now we are back in our command prompt, ready to move on.

Step Two — Download WordPress to your Server

Next, we need to download the actual WordPress content onto our server. This is available on the WordPress website.

The latest stable version of the application is always given the same URL, which makes this part easy. We want to download the file to our user’s home directory:

cd ~
wget http://wordpress.org/latest.tar.gz

Our application files have been downloaded as a compressed, archived directory structure stored in a file called latest.tar.gz. We can extract the contents by typing:

tar xzvf latest.tar.gz

This will create a directory called wordpress that contains the site files.

We should take this opportunity to download some additional components that our WordPress instance will need. We can get these directly from Ubuntu’s software repositories using apt:

sudo apt-get update
sudo apt-get install php5-gd libssh2-php

These two packages allow you to work with images and install/update plugins and components using SSH respectively.

Step Three — Configure WordPress

We have the files now, so we can start to configure our WordPress instance.

We need to modify the main configuration file located in our new directory. Move into the directory that you extracted in the last section:

cd ~/wordpress

Inside of this directory, we have a sample configuration file called wp-config-sample.php. This has most of the configuration details correct, so we can copy that to use as the base of our config file:

cp wp-config-sample.php wp-config.php

When we open the file, our first order of business will be to adjust some secret keys to provide some security for our installation. WordPress provides a secure generator for these values so that you do not have to try to come up with good values on your own. These are only used internally, so it won’t hurt usability to have complex, secure values here.

To grab secure values from the WordPress secret key generator, type:

  1. curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get back unique values that look something like this:

Warning

It is important that you request unique values each time. Do NOT copy the values shown below!

Output
define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H'); define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3'); define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88'); define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g'); define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-'); define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|'); define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

These are configuration lines that we can paste directly in our configuration file to set secure keys. Copy the output you received now.

Now, open the WordPress configuration file:

nano wp-config.php

Find the section that contains the dummy values for those settings. It will look something like this:

/var/www/html/wp-config.php
. . .

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

. . .

Delete those lines and paste in the values you copied from the command line:

/var/www/html/wp-config.php
. . .

define('AUTH_KEY',         'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_KEY',  'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_KEY',    'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_KEY',        'VALUES COPIED FROM THE COMMAND LINE');
define('AUTH_SALT',        'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_SALT',   'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_SALT',       'VALUES COPIED FROM THE COMMAND LINE');

. . .

The file is now suitable for our needs; it is just lacking the information to connect to the database we created. The parameters we need to set are DB_NAME, DB_USER, and DB_PASSWORD.

We can find these parameters in this file and set them up to use the database and user details that we created. My file looks like this:

<pre> . . . // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define(‘DB_NAME’, ‘<span class=“highlight”>wordpress</span>’);

/** MySQL database username */ define(‘DB_USER’, ‘<span class=“highlight”>wordpressuser</span>’);

/** MySQL database password */ define(‘DB_PASSWORD’, ‘<span class=“highlight”>password</span>’); . . . </pre>

When you have made the changes above, save and close the file.

Step Four — Copy the Files to the Document Root

We have our changes to our config files. The next step is to copy them over to our document root so that our web server can find and serve them.

We will use the rsync utility to do the transfer. This has the advantage of preserving permissions, ownership, and ensuring data integrity.

The location of the default document root of nginx on Ubuntu 14.04 is /usr/share/nginx/html/.

However, we are going to set up our document root in /var/www/html/ to avoid modifying a directory location that is controlled by the nginx package. We will change this in our nginx configuration a bit later.

We can create the new document root directory by typing:

sudo mkdir -p /var/www/html

Now, we can copy the files to this location by typing:

sudo rsync -avP ~/wordpress/ /var/www/html/

This will recursively copy the contents of our ~/wordpress directory into our document root.

Next, let’s move over to the document root so that we can adjust some permissions:

cd /var/www/html/

The issue with the directory structure as it stands now is that all of our files have user and group ownership assigned to our regular user. This is fine, except that our web server needs to be able to modify certain directories and files.

We can give this permission without exposing too much of our system by giving the group that our web server runs under group ownership of the files. We can then open up group permissions slightly as needed.

The group that nginx operates under is www-data. For the user portion, enter your user account name. We will demonstrate with an account called demo here:

<pre> sudo chown -R <span class=“highlight”>demo</span>:www-data /var/www/html/* </pre>

This will give our files the necessary ownership.

Before we move on, we should create a new directory for user uploads:

mkdir wp-content/uploads

The new directory should have group writing set already, but the new directory isn’t assigned with www-data group ownership yet. Let’s fix that:

sudo chown -R :www-data /var/www/html/wp-content/uploads

Step Five — Modify Nginx Server Blocks

We have our files and directories configured. Now we need to modify our nginx configuration to serve the content correctly.

We can use the default nginx server block as a base for our new server block. Copy it over like this:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress

Open the new file we made so that we can make some changes:

sudo nano /etc/nginx/sites-available/wordpress

We will want to make the following changes:

<pre> server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;

    root <span class="highlight">/var/www/html</span>;
    index <span class="highlight">index.php</span> index.html index.htm;

    server_name <span class="highlight">your_domain.com</span>;

    location / {
            <span class="highlight">#</span> try_files $uri $uri/ =404;
            try_files $uri $uri/ <span class="highlight">/index.php?q=$uri&$args</span>;
    }

    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:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

} </pre>

A summary of changes that you should be making are:

  • Change the value of the root directive to point to our new document root at /var/www/html.
  • Modify the index parameter to look for an index.php file before the other files.
  • Change the value of the server_name directive to point to your server’s domain name or IP address.
  • Adjust the try_files within the location / block to send requests to PHP when they do not exactly match.

Some of these might already be set from your LEMP installation. When you are finished with these changes, save and close the file.

We need to link our new file to the sites-enabled directory in order to activate it. We can do that like this:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

The file we just linked conflicts with our old default file, since it borrowed so much from it. We need to disable the old file:

sudo rm /etc/nginx/sites-enabled/default

Now, restart the web server and PHP processor to enable our changes:

sudo service nginx restart
sudo service php5-fpm restart

Step Six — Complete the Installation through the Web Interface

Now, our WordPress is ready to go and we can finish the installation through our web browser.

Point your browser to your server’s domain name or IP address, like this:

<pre> http://<span class=“highlight”>your_domain.com</span> </pre>

If this shows your old default nginx page, you may have to refresh the page without the cache.

You will see the basic WordPress welcome stage. Choose your options (Site name, username, password, and email) and then click the “Install WordPress” button:

WordPress install screen

You will have to log in with the account you just created:

WordPress login

You will be presented with your WordPress dashboard, where you can begin customizing your setup and creating content:

WordPress dashboard

Conclusion

You should now have your WordPress instance up and running on an nginx web server in Ubuntu 14.04. WordPress is a fairly flexible platform that you can use to customize your site. Experiment with some different plugins, themes, etc. to find out what works best for you.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Justin Ellingwood
Justin Ellingwood
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
50 Comments
Leave a comment...

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!

This part confuses me:

sudo chown -R demo:www-data *

If I’m developing in a vagrant environment do I need to have this setup as vagrant:www-data and why is that important? I tried just using www-data as in the next command and that seems to work but my install is a bit buggy.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 20, 2014

@Jean-Pierre: If you’re using Vagrant, depending on your setup, I think you’d be fine using something like:

<pre> config.vm.synced_folder “wordpress/”, “/var/www/html/”, :owner => “www-data”, :extra => ‘dmode=775,fmode=774’ </pre>

where “wordpress/” is the local folder that should be installed on the VM. Alternatively, there’s a pretty active project that provides a default WordPress configuration using Vagrant that you might want to base your work on:

https://github.com/Varying-Vagrant-Vagrants/VVV

Thanks for a great writeup, I am not able to automatically download plug-ins via the WordPress admin pages. Something is fishy with the permissions. Suggestions?

@yooakim, redo the chown permissions after you’ve installed your WP. Usually works for me just fine.

I can’t delete or install plugins after following this tutorial. Then I press delete on a plugin I get a screen that say to me that I need to enter FTO/SSH2 username/password and keys.

Please help me!

Is it possible to run a WordPress and a Ghost blog on the same server? I don’t want to set up more than one Droplet, plus the experience should be fun.

It is possible. Wordpress and Ghost will each have their own db in mysql. You need nginx to send proper URL to the wordpress blog and the ghost blog.

Have fun!

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 27, 2014

@carlos_medina: It’s certainly possible. What you’d need to do is set up a new server block for Ghost that contains a reverse proxy. By default Ghost serves it’s content on port 2368. So you just need to set up the for where you want it accessible. If you were going to use a separate subdomain, it would looks something like:

<pre> server { listen 0.0.0.0:80; server_name ghost.your-domain.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://127.0.0.1:2368;
    proxy_redirect off;
}

} </pre>

This article should point you in the right direction for getting to know server blocks:

https://www.digitalocean.com/community/articles/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

while this one will show you how to install Ghost from source:

https://www.digitalocean.com/community/articles/how-to-host-ghost-with-nginx-on-digitalocean

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
May 28, 2014

@dan: @yooakim: You can run the following command to fix that: <pre>sudo chgrp -R www-data /var/www/html sudo chmod g+w /var/www/html</pre>

Er…nginx now fails to restart and I cannot see its page at my url (unbullshit.com), any suggestions?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 5, 2014

@infinitelink: What’s the output of <code>nginx -t</code>?

Additional info for those who might have a clue,

all these tests commands fail

  • sudo service nginx restart
  • sudo service nginx force-reload
  • sudo service nginx configtest

these commands still work as yesterday

  • sudo service nginx stop
  • sudo service nginx start

And who do I suggest comment editing (maybe with approval of moderators) to? xD (You konw, reduce the # of additional posts).

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 6, 2014

@infinitelink: What do you see when you run <code>sudo service nginx configtest</code>? Editing comments and a bunch of other awesome features are coming <strong>soon</strong>! Stay tuned :)

I am having the same problem as infinitelink nginx -t outputs

nginx: [alert] could not open error log file: open() “/var/log/nginx/error.log” failed (13: Permission denied) 2014/07/07 16:42:56 [warn] 1970#0: the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 2014/07/07 16:42:56 [emerg] 1970#0: unexpected “;” in /etc/nginx/sites-enabled/wordpress:28 nginx: configuration file /etc/nginx/nginx.conf test failed

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 8, 2014

@jcc4:

2014/07/07 16:42:56 [emerg] 1970#0: unexpected ";" in /etc/nginx/sites-enabled/wordpress:28

Can you pastebin the contents of /etc/nginx/sites-enabled/wordpress?

I ran through the steps, I am receiving this message “Error establishing a database connection”

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 9, 2014

@ganzuelo: Check nginx’s error log: sudo tail /var/log/nginx/error.log Make sure your MySQL are correct and that MySQL is running: sudo ps wwaux | grep mysql | grep -v grep

I run sudo ps wwaux | grep mysql | grep -v grep and return no error. Yet, I’m still getting the “Error establishing a database connection”.

I check my wp-config.php, everything is in order.

What could be the possible cause of it?

Thanks!

Emergency!!!

Hi~ I wonder did you try to upload anything(plugin or pictures) from the wordpress dashboard? Because it didn’t work for me. When I try to install new plugin, my Connection Information were requested…(hostname, password…) When I try to upload photos, it shows:““420x600_1 (1).jpg” has failed to upload due to an error Unable to create directory wp-content/uploads/2014/07. Is its parent directory writable by the server?” I really really need help~ Thanks

Plus: I tried sudo chgrp -R www-data /var/www/html sudo chmod g+w /var/www/html

They didn’t work…

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 20, 2014

@water8815:

sudo chmod g+w /var/www/html

should be

sudo chmod -R g+w /var/www/html

Try running that instead.

Thank you. It worked for me. But i did this on uploads folder only.

Hello @Kamal Nasser,

I managed to install LEMP (with MariaDB+APC cache) and my wordpress site is running at the moment. There are some weird issues though. Some java script depending wordpress plugins such as visual composer are not working properly. Some widgets such as “like and share buttons” are not working properly. In the homepage, if I disable “like and share” widget, the rest of the widgets appear, but if I enable “like and share” widget, then this widget gets loaded incomplete and the rest widgets does not get displayed. Another weird issue again with the widgets, even I enable or disable “like and share” widget, the widgets only get displayeded on main page. I can not manage to display widgets in sub pages, categories, etc… What do you think? Is it something to do with javascript? Or is there a specific “wordpress” configuration for nginx? ps: url rewrite and everything works. permissions and owner is set correctly. everything is fluid except the things I mentioned above.

Kind regards and looking forward to hear from you.

Cagatay

How you resolved this?

~$ ls -lr /var/www/html

total 176
-rwxrwxr-x  1 sam www-data  3032 Feb  9 12:39 xmlrpc.php
-rwxrwxr-x  1 sam www-data  4026 Oct 24  2013 wp-trackback.php
-rwxrwxr-x  1 sam www-data 25665 Nov 12  2013 wp-signup.php
-rwxrwxr-x  1 sam www-data 11070 Apr  7 13:15 wp-settings.php
-rwxrwxr-x  1 sam www-data  8235 Nov 13  2013 wp-mail.php
-rwxrwxr-x  1 sam www-data 32671 Apr 13 09:06 wp-login.php
-rwxrwxr-x  1 sam www-data  2359 Oct 24  2013 wp-load.php
-rwxrwxr-x  1 sam www-data  2380 Oct 24  2013 wp-links-opml.php
drwxrwxr-x 12 sam www-data  4096 May  8 10:45 wp-includes
-rwxrwxr-x  1 sam www-data  2932 Sep 24  2013 wp-cron.php
drwxrwxr-x  5 sam www-data  4096 Jul 22 13:07 wp-content
-rwxrwxr-x  1 sam www-data  3087 Oct 24  2013 wp-config-sample.php
-rwxrwxr-x  1 sam www-data  3073 Jul 22 12:43 wp-config.php
-rwxrwxr-x  1 sam www-data  4818 Feb 18 13:45 wp-comments-post.php
-rwxrwxr-x  1 sam www-data   271 Jan  8  2012 wp-blog-header.php
drwxrwxr-x  9 sam www-data  4096 May  8 10:45 wp-admin
-rwxrwxr-x  1 sam www-data  4896 Dec 24  2013 wp-activate.php
-rwxrwxr-x  1 sam www-data  7194 May  7 13:43 readme.html
-rwxrwxr-x  1 sam www-data 19930 Apr  9 16:50 license.txt
-rwxrwxr-x  1 sam www-data   418 Sep 24  2013 index.php

Still doesn’t let you update plugins or install them without the ftp screen like others have stated. It would be great if someone could figure this out and update the tutorial, I always run into this problem. chown -R www-data:www-data /var/www/html is what I usually end up doing I think and it works. Please help

Hi Folks, I have ran this tutorial to the letter and I get the same issues as ganzuelo and yansusanto. If I try and use my hostname I get error “Error establishing a database connection” If I use the IP I can get in and finish the install. If I then go into the Wordpress and change the general settings and change the ip to hostname it will fail. Ive ran through this entire process using LAMP and I get the same problems. Checked the logs and they are empty, no mysql error and ive restarted the server and mysql.

sudo tail /var/log/nginx/error.log Make sure your MySQL are correct and that MySQL is running: sudo ps wwaux | grep mysql | grep -v grep

I have read a few threads about a swap issue causing this error…Im using 1GB ram. Any help would be great. Thanks

Unable to create directory wp-content/uploads/2014/12. Is its parent directory writable by the server?

How to solve this???

sorry, replied wrongly

Thank you for sharing wordpress installation on nginx. But this post is missing one packages that is php5-fpm. Kindly install it if you are using Ubuntu or Debian

sudo apt-get install php5-fpm

Hello, I was getting the “Error establishing a database connection”, here is what I did to solve:

-> first make sure to copy and paste(ctrl+c, ctrl+v) the wp-config.php section described in the tutorial. It is very easy to have a typo with the " ’ " characters!

  1. Make sure the basic setup is working. Create a file “/var/www/html/test.php”

  2. on this file write

<?php
$db = @mysql_connect('localhost', 'wordpressuser', 'password');
if (!$db) echo "connection failed";
else echo "connection succeeded";
?>
  1. on the browser, type http://<yourdomain-listed-on-nginx>/test.php

  2. if you get fail, one of the three is wrong. In my case, I had to switch “localhost” for ‘127.0.0.1’

  3. This file succeeded, so I changed wp-config.php DB_HOST to ‘127.0.0.1’

  4. Still getting an error! So I went to mysql prompt (mysql -u root -p), and ran the following commands:

CREATE USER wordpressuser@127.0.0.1 IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@127.0.0.1;
flush privileges;
exit
  1. for good measure (shouldnt be necessary, but…) run the following:
sudo service mysql restart
sudo service nginx restart
sudo service php5-fpm restart
  1. Now it works! hope this helps

Hi Stenlo, thank you for this reply. When I try to run your step (7) I get the following error:

ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

Do you have any suggestions on how to get that ‘one’ priviledge? Thank you beforehands.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
July 22, 2014

@SaM5246: The tutorial has instructions to create the uploads directory and give the www-data user permissions to write to it:

sudo chown -R youruser:www-data /var/www/html/*
mkdir /var/www/html/wp-content/uploads
sudo chown -R :www-data /var/www/html/wp-content/uploads

Not following this step is generally the problem when people can not install themes or plugins.

This comment has been deleted

    $ nginx -t

    nginx: [warn] the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1

    $ ps aux | grep [n]ginx

    root 12273 0.0 0.1 85872 1364 ? Ss 12:51 0:00 nginx: master process /usr/sbin/nginx www-data 12275 0.0 0.1 86164 1780 ? S 12:51 0:00 nginx: worker process www-data 12276 0.0 0.2 86508 2720 ? S 12:51 0:00 nginx: worker process www-data 12277 0.0 0.1 86164 1780 ? S 12:51 0:00 nginx: worker process www-data 12278 0.0 0.2 86512 2528 ? S 12:51 0:00 nginx: worker process

    @andrew SB

    $ ls -lr /var/www/html/wp-content

    total 16 drwxrwxr-x 2 sam www-data 4096 Jul 22 12:45 uploads drwxrwxr-x 6 sam www-data 4096 Jul 22 12:56 themes drwxrwxr-x 3 sam www-data 4096 May 8 10:45 plugins -rwxrwxr-x 1 sam www-data 28 Jan 8 2012 index.php

    I did all those steps, otherwise “uploads” would not show above, any other ideas? We should get this resolved and amend the tutorial

    I had the same problem with nginx not being able to write/add/delete files as others have.

    A little research revealed that setting the group to www-data is not enough. At the top of nginx.conf it says “user someusername”. Your files must be owned by someusername.

    I follow your complete tutorial, but in the end when I try to access my website in teh url, it gives a “404-Page not found error.” Any suggestions as to where I might be lacking

    How you resolved this? Please.

    @andrew SB

    "@SaM5246: The tutorial has instructions to create the uploads directory and give the www-data user permissions to write to it:

    sudo chown -R youruser:www-data /var/www/html/* mkdir /var/www/html/wp-content/uploads sudo chown -R :www-data /var/www/html/wp-content/uploads Not following this step is generally the problem when people can not install themes or plugins."

    But I’m pretty sure I did follow these steps, twice, still didn’t allow me to install new plugin without inputing ftp informations. And the worse is that it’s still didn’t work after I input these informations!!

    I feel like this tutorial do need to be updated to make this issue go away. I’m not the only one who ran into this issue, and I hope someone could generously help us fix it!

    Thank you so so much~

    ps: @Kamal Nasser I tried sudo chgrp -R www-data /var/www/html sudo chmod -R g+w /var/www/html

    issue still exists…

    I had the same problem where I was running into WordPress asking for FTP or SSH information, but I was able to find a solution on this site.

    All I had to do was change the ownership of /var/www/html using the following:

    sudo chown -R www-data. /var/www/html
    

    Once that was done, I was able to update plugins and install themes with no issue.

    Now, I am no Linux expert, so please let me know if I did something insecure here or if I will run into issues in the future.

    @gregkmathews thanks bro! I was struggling a bit with the permissions also and the command sudo chown -R www-data. /var/www/html fixed it. I am totally enjoying these guides and the sharing of info. Good stuff and thanks to everyone at Digital Ocean for providing these awesome guides.

    @william

    No problem! Glad to hear that it worked for you too. I have been tinkering with Linux and FOSS for years and the willingness to help and share info is one of the things I love about the community.

    thanks gregkmathews, that step worked for me too

    but can anyone confirm if this is a sercurity risk? i wouldn’t think so, but i’m a total beginner at VPS

    I think that best solution for updates without ftp should be here

    http://www.hongkiat.com/blog/update-wordpress-without-ftp/

    (add define(‘FS_METHOD’,‘direct’); in wp-config.php)

    and simply setting /wp-content ownership/group at www-data

    What do I need to do further so that I can run multiple wordpress websites in 1 vps? I have already created droplet using LEMP on Ubuntu 14.04 and done the Prerequisites.

    Hi,

    Everything went fine. After installing wordpress I am getting this “Error establishing a database connection” error. Any idea how could i resolve it?

    I am not able to access my site without WWW.

    Any solution?

    @belgen77 @kamaln7

    I installed LEMP and I am facing the same issues. Javascript is not working at random places. While creating posts, I am unable to access elements from Wordpress Toolbar because they render at the bottom of page with no clickable links. The visual composer isn’t working here too. Did you find some solution?

    I could really use some help here. Although the site works pretty good, the admin area is messed up.

    On the step to modify the nginx server blocks, it didn’t show a line that was put in from another tutorial to set up LEMP on Ubuntu. The line of code was: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; in the location ~ \.php$ block. So I deleted it. When I went to my IP address to finish the setup in Wordpress, I just got a blank screen. I went back in to that block and put that line back in and it seems to work now. So I have two questions: 1 - what does this line of code do? 2 - please update the tutorial to reflect that this line needs to be in there. (OK, that wasn’t a question)

    Justin Ellingwood
    DigitalOcean Employee
    DigitalOcean Employee badge
    November 17, 2014

    @arnsdorf: Sorry to hear you’re having trouble. I just ran through the tutorial again (including the prerequisites) and I am not having this issue.

    The fastcgi_param SCRIPT_FILENAME... line is sometimes necessary for passing the user’s request to the PHP processor. It indicates the exact file that should be run. However, WordPress does not usually require this line because it can read it directly from the query string. We set the query string with this line:

    try_files $uri $uri/ /index.php?q=$uri&$args;
    

    This is located in the location / block. If you have this line, the other line should not be necessary. Hopefully, this helps a bit.

    I just double checked and I do have the correct code in the location / block as you’ve noted above. Just to test, I commented out the fastcgi_param... line again, refreshed the page, and the browser showed a blank page again. Uncommented, and it works again. Something else must be at play here. Below is my config file:

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
    
            root /var/www/html;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name <IP address removed on purpose>;
    
            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 unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
                    include fastcgi_params;
            }
    }
    
    Justin Ellingwood
    DigitalOcean Employee
    DigitalOcean Employee badge
    November 18, 2014

    @arnsdorf: I’m not sure what the problem is that you’re facing, but I don’t think that it’s related to the SCRIPT_FILENAME fastcgi parameter. In fact, I was actually incorrect about the try_files directive and even less is required for WordPress to handle the connection correctly (apparently, you don’t even need the query string).

    According to Nginx’s “Common Pitfalls” documentation found here, WordPress will function by just passing the request to index.php. It will read the actual query from the REQUEST_URI. So your try_files section could be as simple as this:

    location / {
        try_files $uri $uri/ /index.php;
    }
    

    I can’t see an issue with the file you posted, but I ran through the entire guide again, and this is the configuration that is working for me:

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        root /var/www/html;
        index index.php index.html index.htm;
    
        server_name domain_name;
    
        location / {
            try_files $uri $uri/ /index.php;
        }
    
        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:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }
    

    Are there any entries in the logs that indicate a problem? The Nginx logs are here:

    • Access log: /var/log/nginx/access.log
    • Error log: /var/log/nginx/error.log

    In addition, the PHP processing log may be found here:

    • PHP5-FPM log: /var/log/php5-fpm.log

    I checked the logs and found nothing. the Error log and PHP log are completely empty and the Access log has events but nothing suspicious.

    This issue is this. If I delete the line [as you suggest] fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; I see a blank page when navigating to my Wordpress site. If I put the line back in, I see the Wordpress site as I should. The only thing I change is that one line and it either makes work or not.

    I tried your whole config file above and that didn’t work either. There must be some setting somewhere else that is causing this. This is a fresh install of everything on an Ubuntu 14.10 server and I followed all the tutorials to the letter.

    @jellingwood - I just figured it out from another thread on another tutorial. When you delete the fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; line, you have to add the include fastcgi.conf; line. Thanks for your help.

    Justin Ellingwood
    DigitalOcean Employee
    DigitalOcean Employee badge
    November 19, 2014

    @arnsdorf: I’m glad you got it figured out.

    The file you mention is not present in Ubuntu 14.04, which this tutorial was written for. The maintainers added this in 14.10. In the future, please make sure you mention earlier on if you are deviating from the instructions in the tutorial and we’ll be able to help you more quickly.

    So…I thought everything was working, until I tried to upload a theme. I can upload images (up to 1MB, not the 2MB it states) but I can’t upload a theme. I click Upload Theme -> Choose File -> Install Now and nothing happens…it just sits there. No errors no progress.

    I am running Ubuntu 14.10 and WP 4.0.1 on a freshly built droplet

    Any ideas?

    BTW, everything is owned by www-data.

    john@wp:/var/www/html/wp-content$ ls -alF
    total 28
    drwxrwxr-x 6 www-data www-data 4096 Nov 20 11:59 ./
    drwxrwxr-x 5 www-data www-data 4096 Nov 21 08:42 ../
    -rw-rw-r-- 1 www-data www-data   28 Jan  8  2012 index.php
    drwxrwxr-x 3 www-data www-data 4096 Nov 17 23:54 plugins/
    drwxrwxr-x 5 www-data www-data 4096 Sep  4 09:25 themes/
    drwxrwxr-x 2 www-data www-data 4096 Nov 20 11:59 upgrade/
    drwxrwxr-x 3 www-data www-data 4096 Nov 21 08:32 uploads/
    

    After leaving it for a little bit, the browser did pop up the error “Safari can’t open the page ‘www.studio23bi.com/wp-admin/update.php?action=upload-theme’ because the server unexpectedly dropped the connection.”

    have a small question. now DO have LEMP on 14.04 in application tab. so can i install my wordpress site with this tutorial skipping Prerequisites and starting from this tutorial ater i install LEMP on 14.04 ?

    simply i wanted to say, is Prerequisites are still required if i create droplet using LEMP on 14.04?

    Justin Ellingwood
    DigitalOcean Employee
    DigitalOcean Employee badge
    December 2, 2014

    @newbie: There might be some variations in the one-click LEMP install and the one implemented by this guide. If you are very familiar with the installed components, you can probably start with the one-click and make any necessary adjustments. If not, it’s probably best to use the prerequisite articles as later guides are written with the specified prerequisite configurations in mind.

    Hope that helps!

    413 Request Entity Too Large

    nginx/1.4.6 (Ubuntu)

    Hi. As I’m trying to install a theme after installing Wordpress multisite, this message appears. Any clues?

    Hi, thanks for sharing this, i have successfully installed wordpress.

    But after doing all this, i cannot access phpmyadmin through http://mydomin/phpmyadmin

    It always re-direct to the wordpress. Can you help me with this? Thanks

    Hello,

    I want to know how to set up nginx’s block server like apache’s virtuals host ? In fact, I want to know how to use apache with nginx as " userdir "

    For example on my web server, a site is configured in the following directory ‘/home/$user/www’ and I would like to configure Nginx this way.

    Thanks and Sorry for the quality of my english :(

    This comment has been deleted

      Hi,

      I am still having trouble. Uploading photo’s works fine. However getting a plugin or theme installed seems to not work somehow. I receive the pop-up that I have to enter my ftp credentials or SSH info.

      Also another thing I noticed is. Shouldn’t we remove the wordpress which we downloaded to our user account? Now we basically have two wordpress installs and the zip file on the server. Seems wasted space, but I’m not full expert on it, so should we remove this?

      Thanks in advance!

      Something I ran into while following this guide was the following error:

      2015/01/23 21:24:34 [crit] 6970#0: *1 connect() to unix:/var/logan/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream
      

      After some searching around I can across this site

      When I checked my www.conf configuration it was configured as such:

      listen = 127.0.0.1:9000
      

      I had to change the following line in my server block to get it working:

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

      to

      fastcgi_pass 127.0.0.1:9000;
      

      Not sure if there is a right or wrong way to using this.

      Hi, I have Prosper 202 installed already but want to add wordpress. If I follow the above guide will I overwrite the prosper installation? Do I need to install wordpress to a different location instead of /var/www/html ? I would be happy to access my wordpress site under a subdomain like wp.mysite.com. What should I change in the above tutorial? Thanks

      For those who are having permission issues, especially with wp-content uploads:

      ‘First, you will need a non-root user with sudo privileges’

      Go through the tutorial under that user, and instead of using ‘demo’ use the username that you’re logged in as.

      The writer of the tutorial specified this in the beginning, but some seem to have missed it. Perhaps the writer should edit this document through the proper uses of ‘foo’ so as to further eliminate the confusion.

      I can’t remember, but somewhere in the stack of the LEMP Wordpress server stack, root access is disabled on the front end to prevent magnanimous security breaches. I believe it’s the default settings within nginx.

      Instead of changing the default settings though, save yourself a security nightmare by creating another non-root sudo user. I do most of my command line through ‘su -’ access, despite popular convention, but this is one such convention that you do NOT adopt such a solution.

      TAGS: #“sudo chown -R demo:www-data *” #“Unable to create directory wp-content/”

      I have installed Unbuntu 14.04, nginx, on EC2 AWS. When I navigate to my EC2 IP I get a “Welcome to nginx” message. The problem is that I have installed Wordpress per this tutorial. I have cleared my browser cache which did not work.

      I run the command nginx -t and get this error message:

      nginx: [emerg] unexpected “}” in /etc/nginx/sites-enabled/wordpress:37 nginx: configuration file /etc/nginx/nginx.conf test failed

      Here are the contents in question of /etc/nginx/sites-enabled/wordpress

      
      server {
              listen 80 default_server;
              listen [::]:80 default_server ipv6only=on;
      
              root /var/www/html;
              index index.php index.html index.htm;
      
              # Make site accessible from http://localhost/
              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;
                      try_files $uri $uri/ /index.php?q=$uri&$args
                      # Uncomment to enable naxsi on this location
                      # include /etc/nginx/naxsi.rules
              }
      
      
      

      @jellingwood I made the fixes you mentioned (see below)

      
      server {
              listen 80 default_server;
              listen [::]:80 default_server ipv6only=on;
      
              root /var/www/html;
              index index.php index.html index.htm;
      
              # Make site accessible from http://localhost/
              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;
                      try_files $uri $uri/ /index.php?q=$uri&$args;
                      # Uncomment to enable naxsi on this location
                      # include /etc/nginx/naxsi.rules
              }
      }
      

      I ran nginx -t again and now I get this error:

      nginx: [emerg] “location” directive is not allowed here in /etc/nginx/sites-enabled/wordpress:55 nginx: configuration file /etc/nginx/nginx.conf test failed

      Here is the code in question:

              location ~ \.php$ {
                      fastcgi_split_path_info ^(.+\.php)(/.+)$;
              #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
              #
              #       # With php5-cgi alone:
                      fastcgi_pass 127.0.0.1:9000;
              #       # With php5-fpm:
              #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                      fastcgi_index index.php;
                      include fastcgi_params;
              #}
      

      I followed this tutorial for installing nginx on EC2 ubuntu https://www.youtube.com/watch?v=lxmCcTlMO6A

      I can use this tutorial to a droplet with two wordpress installed?

      Try DigitalOcean for free

      Click below to sign up and get $200 of credit to try our products over 60 days!

      Sign up

      Join the Tech Talk
      Success! Thank you! Please check your email for further details.

      Please complete your information!

      Become a contributor for community

      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

      DigitalOcean Documentation

      Full documentation for every DigitalOcean product.

      Resources for startups and SMBs

      The Wave has everything you need to know about building a business, from raising funding to marketing your product.

      Get our newsletter

      Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

      New accounts only. By submitting your email you agree to our Privacy Policy

      The developer cloud

      Scale up as you grow — whether you're running one virtual machine or ten thousand.

      Get started for free

      Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

      *This promotional offer applies to new accounts only.