Installing WordPress on Ubuntu 14.04 LTS – Part 1

WordPress is currently the most popular CMS (Content Management System) on the internet by a long way, in fact it accounts for nearly 50% of all websites if the statistics are to be believed. The reason for this is simplicity combined with power. It’s easy to quickly set up a website or blog and if you are self hosting it costs nothing as all the software is open source. In this guide I’ll walk you though installing WordPress on Ubuntu 14.04 LTS (Long Term Support) server. I’m going to be working against the most current the LTS version of Ubuntu which is 14.04.2 but these instructions will almost certainly work fine for any version of Ubuntu close to this.

Prerequisites for Installing WordPress on Ubuntu

Before you install WordPress on Ubuntu you’ll need to meet a few simple prerequisites:

  • L – Ubuntu is installed, configured and running correctly.
  • A – Apache is installed and running.
  • M – MySQL is installed, I’m currently using version 5.5.
  • P – PHP is installed.

As you can probably guess this is the basis of a LAMP server. While the details of installing and configuring the above software is outside the scope of this document the process is essentially just a matter of apt-get install X where X is apache, mysql or php.

Additionally you will need to be able to shell into the server with a user that has sudo privileged. If you are the server administrator this is probably true of your normal account but it can vary. You can complete all of this set up by preceding (appropriate) commands with sudo or you or you can switch to the super user by issuing sudo su – at the start. If you do switch to super user be careful!

Create an Empty MySQL Database and Dedicated User for WordPress

WordPress needs a database to store settings and content for your site and it needs to be created ahead of time. There are numerous ways to achieve this, I typically use the MySQL Workbench application as it’s typically open on my desktop but I’m going to show you how to do it using by issuing SQL commands as that requires no additional software or configuration. However you do it the end result will be the same a new empty database.

Once you have your new database you need to assign a user privileges to access the database. My preferred method is to create a new user specifically for the new database and let WordPress use that. This is good from a security point of view as it limits the amount of damage that can be done should something go wrong it also makes management of the users slightly easier. An alternative option is to use one user for all your WordPress sites but I’m not keen on that arrangement. What you should never do is give WordPress the credentials for your root account!

Start by logging into MySQL using your root account or another account with DBA privileges:

mysql -u root -p

After entering your password you’ll be presented with a mysql command prompt. Create a new database by issuing the command:

CREATE DATABASE `example-wp` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

This will create the database example-wp. I like to append wp to the database name to indicate what the database is for, this helps if there are other databases associated with the domain. Note that the – (dash) character is permitted in MySQL identifiers but it does mean the identifier needs to be quoted with back quotes. If I was sensible I’d probably use an _ (underscore) instead as then it wouldn’t need quoting.

Now create a new user for this database. MySQL usernames are limited to 16 characters so including the full domain name is usually a non-starter. In this example I’m going to call the user wp-example. I prefix my WordPress users with wp- so that they all sort together. Run the query:

CREATE USER 'wp-example'@'localhost' IDENTIFIED By 'password';

Obviously you are going to want to pick a password that is a bit harder to guess. If, like me, your WordPress install lives on a different machine to your database simply change localhost to be the IP address (or name if you have DNS resolution) of your web server.

Next you need to grant the new user privileges on the WordPress database like this:

GRANT ALL PRIVILEGES ON `example-wp`.* TO 'wp-example'@'10.0.0.11';

Note the use of quotes and back ticks where required. Finally flush the privileges so that MySQL picks up the changes and then exit.

FLUSH PRIVILEGES;
exit

You should now be back to the regular command prompt. If your database server is a different machine to your web server you can now log out completely as all the database modifications are complete.

In part two I’ll cover the next steps of installing WordPress on Ubuntu by downloading and performing the initial configuration of WordPress.