Tutorial

How To Install WordPress on Ubuntu 12.04

Published on June 28, 2012
How To Install WordPress on Ubuntu 12.04
Not using Ubuntu 12.04?Choose a different version or distribution.
Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

What the Highlighting Means

The lines that the user needs to enter or customize will be highlighted in this tutorial! The rest should mostly be copy-and-pastable.

About WordPress

WordPress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality.

Setup

The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup.

Before working with wordpress, you need to have LAMP installed on your virtual private server. If you don't have the Linux, Apache, MySQL, PHP stack on your VPS, you can find the tutorial for setting it up in the Ubuntu LAMP tutorial.

Once you have the user and required software, you can start installing WordPress!

Step One—Download WordPress

We can download WordPress straight from their website:

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

This command will download the zipped WordPress package straight to your user's home directory. You can unzip it the the next line:

tar -xzvf latest.tar.gz 

Step Two—Create the WordPress Database and User

After we unzip the WordPress files, they will be in a directory called WordPress in the home directory.

Now we need to switch gears for a moment and create a new MySQL directory for WordPress.

Go ahead and log into the MySQL Shell:

mysql -u root -p

Login using your MySQL root password, and then we need to create a WordPress database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon.

First, let's make the database (I'm calling mine `wordpress` for simplicity's sake; feel free to give it whatever name you choose):

CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:

CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

Set the password for your new user:

SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)

Finish up by granting all privileges to the new user. Without this command, the WordPress installer will not be able to start up:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Then refresh MySQL:

FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Exit out of the MySQL shell:

exit

Step Three—Setup the WordPress Configuration

The first step to is to copy the sample WordPress configuration file, located in the WordPress directory, into a new file which we will edit, creating a new usable WordPress config:

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Then open the wordpress config:

sudo nano ~/wordpress/wp-config.php

Find the section that contains the field below and substitute in the correct name for your database, username, and password:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and Exit.

Step Four—Copy the Files

We are almost done uploading WordPress to the virtual private server. The final move that remains is to transfer the unzipped WordPress files to the website's root directory.

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

Finally we need to set the permissions on the installation. First, switch in to the web directory:

cd /var/www/

Give ownership of the directory to the apache user.

sudo chown username:www-data /var/www -R 
sudo chmod g+w /var/www -R 

From here, WordPress has its own easy to follow installation form online.

However, the form does require a specific php module to run. If it is not yet installed on your server, download php-gd:

sudo apt-get install php5-gd

Step Five—RESULTS: Access the WordPress Installation

Once that is all done, the WordPress online installation page is up and waiting for you:

Access the page by adding /wp-admin/install.php to your site's domain or IP address (eg. example.com/wp-admin/install.php) and fill out the short online form (it should look like this).

See More

Once WordPress is installed, you have a strong base for building your site.

If you want to encrypt the information on your site, you can Install an SSL Certificate

By Etel Sverdlov

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)

Etel Sverdlov
Etel Sverdlov
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!

Excellent tutorial. You may need to change the DirectoryIndex when installing Wordpress on a fresh LAMP box so that the index.php file will load. If you point your web browser to your server IP / domain and you only see the “It works” Apache page after installing/configuring Wordpress then you will need to edit the DirectoryIndex so Apache will load index.php as the default webpage. To do this, follow these steps:

  1. Go to /etc/apache2/mods-enabled/ directory. To do this, type “cd /etc/apache2/mods-enabled/” without the quotes.
  2. Open the dir.conf file so you can edit it. To do this, type “sudo nano dir.conf” without the quotes.
  3. You will see a line of index files (index.html, index.php, index.cgi, etc) under the DirectoryIndex setting. Add index.php as the first item in the list. Doing so will tell Apache to first look for and load an index.php file before looking for the other index file extensions.
  4. Press Ctrl+X to save your changes and then press Enter to exit the editor.
  5. Restart Apache by typing “sudo /etc/init.d/apache2 restart” without the quotes.

I followed the above tutorial and found that mysite.com was still showing “It works” after installing Wordpress. I could still access the admin control panel but I was unable to view the blog. Adding index.php as the first file to load in the dir.conf file fixed this issue for me. Hope this helps others as well!

I’ve Just run through this and now getting the error when trying to start up mysql and DB connection error when tryign to access the website. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111) Any ideas what could be causing this

Not sure what to do… :-S

ben
DigitalOcean Employee
DigitalOcean Employee badge
November 16, 2012

It sounds like MySQL server isn’t running, hence a connection can not be made.

Make sure to install a valid LAMP environment first as detailed in: https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

(L)inux (A)pache (M)ySQL (P)HP

If MySQL is properly installed you can start it with: sudo service mysql start

If it fails you can review the error log for more details /var/log/mysql.err or /var/log/mysql/error.log

Really a fantastic tutorial. I did have to modify dir.conf as suggested above by James Tansley (thanks for that James BTW!!) Can’t recommend this enough. Thanks for the hard word!

Etel Sverdlov
DigitalOcean Employee
DigitalOcean Employee badge
November 21, 2012

Thank you, and thank you, James! Please let me know if there are any further topics you would like to see covered in our community.

Thank You, James Tansley :)))

I tried to install new plugins but it needs ftp connection, of which is possible only through SSH, correct me if Im wrong. However I tried using Filezilla and managed to transfer the plugins folder to /wp-content/plugins. When I checked them on wordpress, the plugins are not there. Any idea whats the problem.

Etel Sverdlov
DigitalOcean Employee
DigitalOcean Employee badge
December 26, 2012

You may be able to install the plugins by temporarily changing the permissions of your web directory to 777 until the plugin is installed. As soon as the plug in has finished installing, the permissions should then be scaled back down to 755.

What is the ‘username’ referred in “sudo usermod -a -G www-data username” line? I’m trying to set up Wordpress on a virtual host so my WP home directory is “/var/www/example.com/public_html”. I’m guessing it might be the “demo” user equivalent or maybe something like “www-data” ? I’m lost, I don’t want to screw up. :)

I also wonder this. I used “root” for the “username” there, but then after I used this tutorial I’ve got following error when using Import plugin:

Before you can upload your import file, you will need to fix the following error:

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

I keep getting the “usermod : user ‘demo’ does not exist”

i can’t get the Virtual Host on Apache to parse the .php files.

HELP!!!

This is an awesome guide. Most people have you use apt-get, but the permissions end up all wonky and this was so much more straight forward.

WordPress automatic updates + FTP:

For anyone that has followed this tutorial to enable automatic WordPress updates by chown-ing the public folder to www-data, if you’ve setup FTP (i.e. vsftpd), you will notice you will not be able to upload files to that directory by FTP.

To have both automatic updates and FTP uploads working, like all us new-comers are used to with a shared host, run this instead (code adapted to this tutorial):

sudo chown -R www-data:username /var/www

Everything will work as on your ex-shared host: automatic updates, FTP uploads and live file editing, file uploads in WordPress. Maybe this can be added to the tutorial.

I had an issue with permalinks.

Solution :::

  1. Enable Mod Rewrite : sudo a2enmod rewrite
  2. Change AllowOverride None to AllowOverride All : sudo nano /etc/apache2/sites-enabled/000-default
  3. Restart Apache : sudo /etc/init.d/apache2 restart

I trust this will help others.

How can I undo this install?

I was running multiple websites using virtual hosts and now it has overwritten so that only the wordpress site is working. I copied the files to the /var/www directory and probably should have created another folder within the www folder. I would like to keep wordpress if possible to use it and learn it but need to have the virtual hosts working. For now until I get some help I copied the new files that this install put in the www folder to a new folder within the www folder called wordpress. /var/www/wordpress, my virtual hosts are working but word press is not. any help would be appreciated.

@James Tansley - thanks for the comment on enabling the index.php. After the wordpress install the home page was getting downloaded rather than rendering in the browser. A simple phpinfo() tag in a file by itself worked fine though. So, your trick did make the wordpress site work fine.

@Michael - thanks for that comment about enabling the rewrite on apache. If your Permalinks are not working this should do the trick.

I followed the initial set up guide to create a user and then the LAMP set up and then finally this wordpress set up guide. I logged into wordpress and clicked on the sample post link and the page loaded fine. Went to alter my permalinks and got the message about manually adding the permalinks… Tried to install a plug in and got the ftp information message.

Followed cosmin’s advice as we as Michael’s and now I can update permalinks and install plugins through the dash board but now any other page than my homepage throws up a 404. “The requested URL /2013/05/13/hello-world/ was not found on this server.”

Any thoughts? I’ve been pulling my hair out with this, previously I’d dived straight into virtual hosts and was getting these issues. Scaled back to just a simple install and still have the problems.

I seem to have it working for the root site now. About to embark on making it work with virtual hosts. This guide could really do with the additional steps adding.

Also wondering - what would be the changes for wordpress on a server with virtual hosts?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
May 16, 2013

@mik.howard: Instead of copying ~/wordpress/* to /var/www, copy it to your virtual host’s DocumentRoot (sudo cp -r ~/wordpress/* /var/www/).

Could someone please include easy to follow instructions like the ones about for setting up WordPress’ notification email system?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
May 20, 2013

@Adam Heward: You need to install an MTA so you can send mail from your droplet - I suggest postfix as it is easy to set up:

apt-get install postfix

Once you have installed it, mail should automatically work.

WordPress automatic updates + FTP:

Wow, all this time and messing with VSFTPD with no success. Thanks for the simple tip. I didn’t need to mess with secure FTP at all. Unfortunately, that was never shown in the WordPress admin screen in one of my old installations, especially when you have multiple locations of WordPress installs for different development projects. This easily helps WordPress update without FTP servers:

sudo chown -R www-data:[user_name] [location_of_WordPress]

If I want to install Wordpress into a sub directory such as ‘wordpress’ what steps do i need to change?

Hi, I follow your tutorial, all works really good, but when I change the permanlink into post name, the server didn’t work, like 404 error :(

I install apache and config like you guys said :), but i cannot fix that :(

please help

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 1, 2013

@jacarve run “cp -r ~/wordpress/.* /var/www” - does that fix it? I’ve also updated the article so you don’t have to do this anymore.

Hey @Kamal, since you changed the article to “cp -r ~/wordpress/.* /var/www” can you please help me understand how to give WordPress the write permissions it will need to upload media files etc. Thanks.

Nice tutorial!!

Just one problem, what’s the “username” in step 4. I installed LNMP, so it should be Nignx user, but how to tell my nignx user name?

"Give ownership of the directory to the apache user. sudo usermod -a -G www-data username "

Much thanks!

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 28, 2013

@jimingkui nginx runs as www-data as well so the command would be the same.

Thanks for the guide but I’m running into an issue. When attempting to set the password for my new user with “SET PASSWORD FOR wordpressuser@localhost= PASSWORD(“password”); " my shell returns “”>” instead of “Query OK, 0 rows affected (0.00 sec)”. Not sure what to do.

Never mind. I just realized I made a typo and fixed it. Wish I could edit or delete the previous comment.

Im migrating a wordpress install from another VPS to my droplet and putting it in a directory /var/www/myblog and then with apache virtual hosts pointing a subdomain like myblog.mydomain.com to the document root /var/www/myblog but for some reason I cant get wordpress to connect to the DB. I keep getting the “Error establishing a database connection” wordpress page. I know the DB (root) credentials in wp-config are correct because I can connect to mysql via the command line.

If i change the DB_HOST from localhost to ip-address I get different error messages but both messages say that I cant connect to the DB. 1 message is just a simple PHP output while the other is a nicely formatted Wordpress HTML page.

I am running Ubuntu 12.04, PHP 5.3.10, MySQL 5.5.31, and Wordpress 3.3.2. Any ideas what I might be doing wrong?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 17, 2013

@aat.rutten: Try creating a user for wordpress instead of using the root credentials - See "Step Two—Create the WordPress Database and User:

Took just <10 mins from start to finish. Never had such a smooth LAMP install before and all kudos goes to your article. Another happy customer. Keep up the good work!!!

It would be good idea to remind people doing the installs to also set the Authentication Unique Key and Salts at the same time they set up the database configuration in the wp-config.php file.

Just got “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.” Error. Tell me how I can fix it. Thanks!

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 22, 2013

@Leo: Run “sudo apt-get install php5-mysql”.

@Kamal, great, thanks

Thanks it was perfect tutorial!

GREAT TUTORIAL!!! I went through the tutorial and changed my dir.conf file, but when I go to view my site it is still only showing the IT WORKS!!! screen. I cannot view my page. Any suggestions?

Please disregard my previous post. I got it all figured out. GREAT WORK EVERYONE!!! THANK YOU!!!

The moment when you change permission sudo chown www-data:www-data * -R Yes, you can update the plugins via wordpress admin, but now the problem is i cannot create new folder, upload files via SFTP?

Is there any way where i can upload files/create folder via SFTP and also update plugins via Wordpress admin?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 31, 2013

@Dzulhelmi: You shouldn’t chown everything to www-data:www-data. You should chown youruser:www-data and chmod 775 the directories you want to be able to write to.

@Kamal you wrote “@mik.howard: Instead of copying ~/wordpress/* to /var/www, copy it to your virtual host’s DocumentRoot (sudo cp -r ~/wordpress/* /var/www/).”

I don’t understand the command for installing wordpress on a virtual host - which part of this line contains the virtual hosts name do I replace the * or does the virtual host name come after the www/?

sudo cp -r ~/wordpress/* /var/www/

@Kamal, then the tutorial should be update, including the chmod 775 the directories we want to be able to write to

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
August 1, 2013

@postcreative: You would set up the virtual host as usual and have the wordpress files copied to its DocumentRoot:

https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
August 1, 2013

@Dzulhelmi: Sorry, in this case it would be okay for wordpress to be able to write to the /var/www directory since that is how it does its updates/installs themes/etc.

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.