WordPress is by far the most used blogging platform on the Web. Open source, and highly customizable, it is a blogger’s dream (as well as the very platform I run this blog on). Today, I’m going to walk you through the steps needed to install this great blogging platform on Ubuntu.
You may be asking why install on Ubuntu…after all, WordPress belongs on a web server! There are a host of reasons why WordPress on Ubuntu makes sense. They include:
- Testing the nightly/beta builds
- Trying out new themes or plugins
- Creating a WordPress blog locally before moving to a web server
- Setting up a home server
Matt Hartley recently posted an interesting use of WordPress as a home recipe server. You can read the post here.
For the video tutorial, I installed WordPress on Ubuntu Gnome 14.04, but any version of Ubuntu (or really any Linux distribution for that matter) will work. I’m not sure of the exact version of PHP, Apache, and MySQL (needed to install WordPress) available to pre-14.04 versions of Ubuntu, so those running 12.04 may need a few ppas installed to update those respective softwares.
Installing the LAMP Stack
Before installing WordPress, we need to install three pieces of software that collectively are known as the LAMP stack. LAMP is an acronym that stands for Linux (which we already have with Ubuntu), Apache HTTP server, MySQL relational database management system (RDBMS), and the PHP programming language.
The first component of the stack we’ll install is MySQL. Both MySQL 5.5 and 5.6 are available on Ubuntu 14.04; we want version 5.6. Depending on what “flavor” of Ubuntu 14.04 is used MySQL 5.5 may already be installed. To remedy this, we will first purge 5.5 and then install 5.6. To do this, open a terminal and enter:
sudo apt-get purge mysql-server-5.5 mysql-client-5.5
sudo apt-get autoremove
sudo apt-get install mysql-server-5.6 mysql-client-5.6
During installation, you will be prompted to create a password for the MySQL root user. Create and confirm the password. I recommend you write this password down; you will need this later.
With the database taken care of, installing Apache is next. From the terminal, enter:
sudo apt-get install apache2
Finally, we will install PHP. The terminal command for this is:
sudo apt-get install php5 libapache2-mod-php5
After installing PHP, we need to restart Apache, Enter the following into the terminal:
sudo service apache2 restart
To check to see that everything has installed correctly thus far, open a web browser and type localhost in the address bar. If everything installed correctly, you should see the Apache2 Debian Default page.
Configure Directories and Databases
The next step involves modifying two Apache text files found in the etc folder. While this can be done in the terminal, many people are hesitant to do more than basic commands through the terminal, so I will explain how to do this with file manager and text editor. We will need to open our file manager with root privileges; to do this, open the terminal and type sudo nautilus (or nemo, or whatever file manager is installed on your system). Navigate to the following folder:
Once in that folder, open the file named:
Once this file is opened in the text editor, navigate to the section that lists the Document Root. Change this from DocumentRoot /var/www/html to DocumentRoot /var/www. Save the file and close the text editor.
Back in our file manager, we will now go to the apache2.conf file, which is located at etc/apache2. Open the file in a text editor and scroll down to the line that lists the /var directory, and set it to match the Document Root in the 000-default.conf file. When finished, the line should look like this:
In my case, the directory already pointed to the correct location; this may not be true in all cases. After making any changes, save the file, close the text editor and file manager. The webserver also needs to be restarted, so open a terminal end enter:
sudo service apache2 restart
Download and Install WordPress
The Wordpress Download page is located at https://wordpress.org/download/. Beside the current stable versions, you can also find testing versions (beta and nightly builds) listed here. Download the tar.gz file. After downloading, the file needs moved to the /var/www folder for extraction. Once again, open the file manager with root privileges (sudo nautilus) and move the file from the downloads folder to /var/www folder. Once there, right click on the file and select extract here.
With WordPress extracted, we can set up the WordPress database. From the terminal, enter:
mysql -u root -p
You will be asked to provide the MySQL password we setup earlier; enter it end press enter. To create the database, enter the following in the terminal:
CREATE DATABASE ubuntu_wp;
This creates a database named ubuntu_wp. Change the database name to whatever you prefer. Write down the name of this database; you’ll need it later. Next, enter the following in the terminal:
Which sets database privileges. Finally, exit out of MySQL by entering exit in the terminal.
Open a web browser and navigate to localhost/wordpress; you will be greeted with the WordPress database setup dialog. Enter the Database name (in this case, ubuntu_wp), the user name (root), and the database password created. Database host remains localhost, and unless you’re running multiple instances of WordPress from a single database, you might as well leave wp_ as the table prefix. After entering all of this information, press submit.
The next dialog box to open will inform the user that WordPress can’t write the wp-config.php file. However, a textbox with all of the information needed for the file is provided. Open a text editor with root privileges (sudo gedit if you’re using gedit) and copy the everything from the text box to the editor. Save the file as wp-config.php in the following folder:
After closing the text editor, reload the localhost/wordpress page in the web browser. The WordPress Welcome Installer will open, and you can enter your site title, create a username and password, and enter your email. Press the Install WordPress button, and you’re done!
I hope this tutorial proves useful. As always, leave comments and questions below.