Install WordPress Locally on Ubuntu Desktop

Are you new to WordPress? Are you a WordPress theme or plugin developer? Do you need to test things out without having it go live and without having to go through FTP?

WordPress requires a web server with MySQL support, which most bloggers and developers probably don’t have on their own computer. However, WordPress can easily be installed on your own system for private usage and testing.

Why Install Locally Instead of Live to Sandbox?

  • It’s the real deal. Themes. Plugins. Everything.
  • No internet connection required.
  • No FTP needed. Everything is stored on your own hard drive.
  • No need to worry about accidentally sending a ping to online services like Technorati.

The Canonical Team provides many flavors of Ubuntu, such as the Desktop edition and the Server edition. Regular users would probably be running the Desktop edition. How would you go about enabling the Apache HTTP Server, PHP, and MySQL? No, you do not need to fully convert to Ubuntu Server.

Difficulty: Moderate
Time Required: ~30 minutes
Requirements: Basic knowledge of Ubuntu and the Terminal

Install Apache

Apache is the world’s most popular HTTP Web Server and is recommended for use with WordPress. To install Apache, simply run the following command in the Terminal.

sudo apt-get install apache2

Test the installation by browsing to http://localhost in your favorite web browser. You should see a page that says ‘It works!’

Install MySQL

MySQL is the database system that is used by WordPress to store all the posts, settings, users, etc…

To install the MySQL server, run the following command.

sudo apt-get install mysql-server-5.1

You will be asked for a password during installation. Make this secure as the root user is able to access all databases and tables.

MySQL Root

Set the password for the root user of MySQL

Install PHP

PHP is a server side scripting language that WordPress is coded in. Simply run the following commands to install the latest stable ersion, PHP5.

sudo apt-get install php5 libapache2-mod-php5

After installation, you should restart Apache using the following command.

sudo /etc/init.d/apache2 restart

Test the installation by running the following. This will create a file named phpinfo.php and open it in gedit.

sudo gedit /var/www/phpinfo.php

Insert the following line into phpinfo.php. Save the file then close gedit.

<?php phpinfo(); ?>

In your favorite web browser, browse to http://localhost/phpinfo.php or If everything worked properly, you should see a PHP Info listing similar to the following.

PHP Info

PHP Info Listing

Install the MySQL Module for PHP

Run this command.

sudo apt-get install php5-mysql

Congratulations! You have successfully installed the web server software! Now it’s time to start installing WordPress.

Create a WordPress Database

Login to MySQL using the following command. Use the password you created earlier when asked.

mysql -u root –p

You should now find yourself in the mysql> client.

Your names can be anything you like. For the purpose of this tutorial, the database name of ‘wordpress’, the user of ‘wordpress_user’, and a password of ‘blogairlines12345′ is used. Do not use this as your password as it is very unsecure.

Let’s start by creating a new database. Please remember that all commands must end in a semicolon or it won’t work.


Now create a database user.

CREATE USER wordpress_user;

Now let’s set a password to the database user.

SET PASSWORD FOR wordpress_user = PASSWORD(“blogairlines12345”);

Replace blogairlines12345 with your desired password. Be sure not to remove the quotations. Password is case sensitive.

MySQL Client

Set password for the database user

Now we must grant the database user all privileges to access the database. Again, replace blogairlines12345 with the password you just created.

GRANT ALL PRIVILEGES ON wordpress.* TO  wordpress_user@localhost  IDENTIFIED BY ‘password’;

Congratulations! You have successfully created a database!

Optional: phpMyAdmin

You may wish to install phpMyAdmin, something most web hosts offer, for easier database management, however this step is completely optional. Follow instructions on the Ubuntu Documentation.

Install WordPress

Now to actually install WordPress.

Download the latest version of WordPress (or a development build if you choose) from the official website.

Create a new directory at /var/www/wordpress. You can change the name ‘wordpress’ to  whatever you like but for the purpose of this tutorial, ‘wordpress’ is used. You can use the following command to do this. If you plan on using a command to extract the WordPress files straight from the archive, this step can be skipped as the archive contains the wordpress folder inside.

mkdir /var/www/wordpress

Change the permission of that folder to 777 so WordPress can read and write to it. Otherwise, you will be asked for an FTP password inside WordPress and we aren’t setting up FTP servers here.

chmod -c 777 -R /var/www/wordpress/

Extract all the WordPress files into this directory. You can use this command. Change the file directories to match where your downloaded archive is.

sudo tar xzvf '/home/brian/Downloads/wordpress-3.0.tar.gz' -C /var/www/

Use the command ‘exit’ to quit the MySQL Client or start a new terminal process. Use the following command to open the wp-config-sample.php file. Edit this like you would for a regular WordPress installation on a web server.

sudo gedit /var/www/wordpress/wp-config-sample.php

Edit the sections about MySQL database settings. If you followed all the names in this tutorial, it would look something like the following. The only modifications you need to make are in the lines highlighted.

// ** 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', 'wordpress_user');

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

/** MySQL hostname */
define('DB_HOST', 'localhost'); ?>

Save the file under the name wp-config.php. Close gedit.

Using your favorite web browser, browse to and follow the instructions provided. You can also use localhost instead of If you get a message reading Error Establishing a Database Connection, it means you have done something wrong.

Local WordPress Installation

Installing WordPress

After the quick installation, you are all done. You can find your new installation at

WordPress Local Installation

WordPress Installation is complete!

Congratulations! A WordPress installation has been successfully completed at (localhost).

Liked this article? Share it with your friends.

Brian is the co-founder of TechAirlines. He is a developer currently focusing on mobile and web development. He is currently a sophomore at Stony Brook University, majoring in Computer Science.

  • Chris Quinn

    Actually this is a lot more simple then setting up a pseudo webserver for this purpose. I have just finished the tutorial, and let me tell you it is spot on. This is well written and definitely easier then installing a virtual os in order for a fake wordpress test site. Thanks again!

    • Brian

      Hi Chris,

      You’re very welcome and I’m glad you were able to follow the tutorial to install a test WordPress site.

      Enjoy your week,

  • Shawn

    Just a quick comment for people that will use this to install and setup WP 3.0.1.

    I had to ‘uncomment’ the:

    in the php.ini file and then restart apache. This tutorial worked great with just this small addition.

    You can find out where your php.ini file is by looking through the phpinfo.php page that you gedit in this tutorial.

    Thanks for this – made it really easy so I can start learning about wordpress instead of having to spend a day learning how to install the platform. Saved me tons of time. Was still able to install all and fix in about 30 minutes.

  • Coen

    First of all; thanks for the tutorial. It worked perfectly!

    But I’ve got a small question. What do I use as a hostname when I want to install a plugin or theme? Thanks in advance.

    Coen (Netherlands)

    • Coen

      And also uploading themes and plugins to the local install of wordpress via wordpress is giving me trouble..

    • Brian Yang

      Hi Coen,

      For the hostname, you would use localhost.

      When you try to upload themes and plugins, are you getting an error message? If so, what’s the error?

      Best regards,

  • classer

    I successfully set apache, mysql, and wordpress but is there a way to setup an FTP account so that one can download plugins and themes? Whenever I try to add a new plugin I get:

    Connection Information

    To perform the requested action, WordPress needs to access to your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

    FTP Username
    FTP Password
    Connection Type Connection Type FTP FTPS (SSL)

    How do I setup a FTP account and make this work?

  • chamberlain 7th

    how do you really create an FTP account in wordpress? DAMN! im using UBUNTU 10.10 and its always requesting for FTP ACCOUNT when i upload a theme!

  • Brian Yang

    Hello everyone. I think I may have missed something in the tutorial. You need to set your folder permissions to 777:

    chmod -c 777 -R /var/www/wordpress/

    • topic

      This helped me a bit. But i solved the problem.
      When you get error that you need connection to local FTP, type in these forms: localhost, your current linux account login and password to that account and choose FTP instead sFTP. I’ve also allowed traffic IN and OUT for ports 21 and 80 in my firewall.
      For me it worked.

  • Kalyan

    I have installed localhost successfully on my Ubuntu Desktop…thanks so much for the help. Now how to host the site. I am quite new! Can my Ubuntu desktop host my website? That would be really great!

    • Brian Yang

      Yes, it is possible, but you would basically be converting the desktop Ubuntu into a server edition. Since you have already installed LAMP, you just need to make a bit more configurations.

  • Pingback: Developing a Wordpress Plugin in Ubuntu | Middle Of Tech()

  • Chandra Kant

    An extremely well written article. 2 points.

    The instructions ‘set password’ and ‘grant all privileges’ have the user name ‘wordpressuser’ which should be ‘wordpress_user’ – the underscore is missing.

    How do I move my actual blog to the development server and what happens to the mysql user name passwords etc?

    • Brian Yang

      You can download a SQL backup of your existing blog and then try the following command line:

      -u username -p -h localhost databasenamehere < (path to file)/backupfile.sql

      Replace the username, database name, path, and file name as needed.

      If you chose to install phpMyAdmin, you can just use the import function provided.

      Thanks for the correction about the underscore! I have now fixed it in the article.

  • kerem

    Thank you for the tutorial Brian. It helped me perfectly.

  • zrem

    Thanks a lot !
    It worked fine, even now in 2012. Just one thing : in the mysql commands SET PASSWORD and GRANT ALL… the password needs to be surrounded by

    …. ‘ …. and not …. ” …. or something else.

  • Pingback: How to install WordPress on ubuntu 12.04 | dungvochi()