Installing WordPress Locally with Ubuntu 12.04


This tutorial will teach you how to install and configure Apache, MySQL and PHP on Ubuntu, and then cover installing WordPress

Ubuntu is easily the most popular Linux distro, in fact, with even Steam soon to be supported. This tutorial will cover the need-to-know details, including the packages you require.

I’ve run this on a fresh install of Ubuntu 12.04, and a lot of this is getting taken care of through the command line. If you’re not comfortable with the CLI, you can still follow these steps and shouldn’t have too much trouble. That said, I highly recommend becoming familiar with the CLI, because it’s a very powerful tool.

Server Install

Naturally, your browser can read HTML files, but is unable to handle PHP files. These need to be first parsed by a server, so we’re going to install the LAMP—Linux, Apache, MySQL and PHP—stack to take care of this for us.

To install the required, open a Terminal window, a system wide shortcut is Control + Alt + t, and run this at the prompt.

$ sudo -i

You’ll need to enter your root password here, the benefit of using the -i parameter is that you wont have to add sudo before the following commands. Though, if you’re uncomfortable with doing this, then you can simply add sudo to the beginning of each command. And moving right along;

$ apt-get update && apt-get upgrade

These two will update your packages and your system as fast as they can, if you’ve never used && before, it’s used to chain commands together, a great timesaver. Our next step is installing the necessary components to get this all happening. The command you can use is

$ apt-get install lamp-server^

And it’s really that easy. You can choose to install them one by one, but there’s hardly any reason to do that. Almost all of this is automatic, though when MySQL installs it will ask you for a root password, enter one of your choosing and carry on.

When you do that, you can sit there and watch the terminal window scroll by at quite the pace or you can go make a drink, it’ll take a few minutes.

When installation is complete, open up a browser and cruise to http://localhost and you should see this.

Type exit at the command prompt to end the root user session.

Configuring Apache

Creating a new Virtual Host is the first order of the day. To save some hassle, we are going to copy the first config with this command.

$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

We need to create a folder that we are going to have WordPress live in. I’ve created mine at /home/user/sites/wp. If you haven’t done so yet, download WordPress, and extract the contents into the wp folder.

Next run the command as we need to make some changes to the configuration.

$ gksudo gedit /etc/apache2/sites-available/mysite

First up, change the document root to where WordPress is living, /home/user/sites/wp for me, and the directory, too, to the same thing

Save the modified file. Now, we need to instruct Apache to use the new file we’ve created with the following two commands, so lets chain them together to keep it easy

$ sudo a2dissite default && sudo a2ensite mysite

Restart Apache with this command before moving on.

$ sudo /etc/init.d/apache2 restart

Check for WordPress

Browse back to http://localhost and you should see this.

So now WordPress needs to be provided with configuration of a Database name and user, and that user’s password, but we don’t have any of those things right now. So it’s time for some more command line fun.

MySQL at the Command Line

Important: MySQL queries end in a semicolon. Do not forget this!

SQL is a little odd compared to most other things you’ll have come across, and perhaps may come across in the future. These instructions must be followed very carefully, so take the time to make sure it’s done right. Open up your terminal and follow these steps

$ mysql -u root -p

This will open the MySQL Admin Console as the user root, and it will prompt you for a password before it lets you in. When you are in, the prompt will look like this mysql>.

The following commands need to be issued one at a time, they are all very self explanatory, but should you have any questions, just ask!

Further, make sure you see “Query OK” before executing the next command.

mysql> CREATE DATABASE yypwordpress;
mysql> CREATE USER wordpressuser;
mysql> SET PASSWORD FOR wordpressuser= PASSWORD(“lepassword”);
mysql> GRANT ALL PRIVILEGES ON yypwordpress.* TO wordpressuser IDENTIFIED BY ‘lepassword′;

When you’ve done this, you can type exit to leave the MySQL console.

Back to WordPress Config

Head back into your browser and click “Create a Configuration File” – To do this, we need to have the Database name, user, and password we have just created.

Hit Let’s Go, fill in the blanks, and run the install. If it has worked, you should see the following and be able to run the install

And then follow it up with some site information.

And that should have your WordPress on Ubuntu installed and ready to go!

In Summary

Congratulations on setting your machine up, particularly if it’s your first time. The command line can be a little daunting at first, but hopefully it has only increased your curiosity. If you’re looking for more information on a command, there’s man. So for instance, you can run man mysql and it’ll bring up a manual for you.

XAMPP is available for Ubuntu, but after testing XAMPP and this, the more manual method, this was the easier and less troublesome route to take.

Share on Facebook Back to Top

Speak up! Let us know what you think.