Installing WordPress on Ubuntu Desktop

WordPress Logo

WordPress is one of the most popular open-source blogging and content management systems in use today. This article describes the installation and basic configuration of WordPress 3.6.1 on Ubuntu Desktop. Although the steps described in this article will be similar for the installation of WordPress on any GNU/Linux system, I’m assuming that you are following along from prior articles describing the installation of Ubuntu Desktop and an “AMP” stack consisting of Apache, MySQL, and PHP. These articles include:

I also assume you are logged in to the administration account created during installation.

Download and Extract WordPress

The first step is to download the latest and greatest version of WordPress from wordpress.org. At the time of this writing (October 2013) this is version 3.61. Launch your Firefox browser and navigate to wordpress.org. You should see the web page below. Click Download WordPress 3.6.1.

wordpress.org

You can download the latest version of WordPress at wordpress.org.

You should now see the Download WordPress page below. Since we’re installing on Linux we want to download the tarball (.tar.gz) file. Click the link as shown below.

Choose tarball for download

Choose the tarball (.tar.gz) format for download and installation on Linux systems.

In the Opening wordpress-3.6.1.tar.gz dialog box that pops up, choose the Save File radio button and click OK.

Save the file

When prompted by the browser, choose to save the file.

After a few seconds the file should be downloaded to your system. It probably landed in the Downloads folder in your home directory. Open a Terminal window and change to your Downloads folder (or wherever the file was saved). We want to copy the tarball to the Apache DocumentRoot directory (/var/www by default), then change to /var/www. The command sequence is shown below.

$ cd Downloads
$ sudo cp wordpress-3.6.1.tar.gz /var/www
$ cd /var/www
Copy tarball to DocumentRoot

Copy the tarball to Apache’s DocumentRoot (/var/www) directory.

Next, we’ll extract the compressed tar file into the /var/www directory.

$ sudo tar zxvf wordpress-3.6.1.tar.gz
Extract tar file

Extract the tar file into the DocumentRoot. The tar file will extract into a directory called wordpress.

The tar file will extract its contents into a new subdirectory called wordpress. After extraction all of the files and directories will have the owner nobody and the group nogroup. Let’s change the owner to your user ID ($USER) and the group to www-data, Apache’s group, for all of the files and directories in wordpress.

$ sudo chown -R $USER:www-data wordpress
Change owner and group of all extracted files

The distribution contents extract as user nobody and group nogroup. Change the owner to $USER (your administrator user ID) and the group to www-data (the web server’s group) recursively for all files and directories including and within the wordpress directory.

Next, we’ll allow group write access to the wordpress/wp-content directory and its contents so that the web server can create and update files. This allows the WordPress user to perform such activities as uploading content into the Media Library, tweaking the stylesheet, and managing themes and plugins from a web browser.

$ cd wordpress
$ chmod -R g+w wp-content
Add group write access wp-content

Allow the web server’s group (www-data) to write to all directories and files including and within the wp-content directory. This will allow the WordPress user to perform administrative tasks, upload content, etc. from the web browser.

We’re done with the distribution tar file so you can delete it.

$ cd /var/www
$ sudo rm wordpress-3.6.1.tar.gz
Delete the distribution tar file

Delete the distribution tar file. You may want to keep the copy in your home Downloads directory in case you need to install it again.

Create a MySQL Database

WordPress requires a MySQL Database (also called a Schema) in which to store all of its (your) data. We’ll now create a MySQL Database called wordpress with a single user, also called wordpress. You can use any of the tools you installed in the Installing MySQL on Ubuntu Desktop article for this task: MySQL Monitor, phpMyAdmin, or MySQL Workbench. Let’s use phpMyAdmin this time.

In your browser, navigate to http://localhost/phpmyadmin. You should see the login screen as shown below. Select your language from the drop-down list, enter the user name of root and the root user’s password that you set when you installed MySQL. Click Go.

Log in to phpMyAdmin

Log in to phpMyAdmin using your root credentials.

When you see the phpMyAdmin Home screen, click the Users tab at the top of the page and then the Add User link at the bottom of the page as shown below.

Add a new user to MySQL

Add a new user to MySQL. You will also be able to create a database by the same name.

On the Add User dialog, enter the user name wordpress, select Local from the Host drop-down, and type a password for your wordpress user (twice). Select the radio button Create database with same name and grant all privileges. Click Add User.

Name user and database

For this development installation, name the user and database wordpress. In a production install you might want to be a little sneakier about your names.

Note: In this step we created a database (schema) called wordpress and a user called wordpress. We also granted the wordpress user all privileges in the wordpress database. While this is a quick and easy way to set up a development WordPress instance, you probably would not do it this way in a production install.

Install WordPress

Now that we have extracted the software and created a database, we’ll install WordPress. The first step is to create a configuration file in the /www/var/wordpress directory. WordPress has a handy facility to do this for you but it requires that the web server have write access to the directory. We’ll temporarily grant this access and then remove it after the installation.

In a terminal window, change to the /var/www directory and issue the following command:

$ cd /var/www
$ sudo chmod g+w wordpress
Temporarily open the wordpress directory to the web server

During the installation, the WordPress installer needs to create a wp-config.php file. Also, when configuring Permalinks, WordPress will create a .htaccess file. We temporarily give the web server group permission to write to the wordpress directory for this purpose. We’ll take away this access afterward.

From your web browser, navigate to the URL http://localhost/wordpress. You should see a page with a helpful message informing you that there is no configuration file and offering to create one for you. Click the Create a Configuration File button.

Create a configuration file

The WordPress installer offers to create a wp-config.php configuration file for you.

WordPress now gives you a list of information that you will need for the installation. Click the Let’s go! button.

Gather some information

Gather your information and let it rip.

On the next page enter your WordPress database name, user name, and password as you entered in phpMyAdmin earlier. Leave the Database Host as localhost and the Table Prefix as wp_. Click Submit.

Enter information about your MySQL database

Enter information about your MySQL database. This is where the WordPress installer will create its tables.

Note: In the last step we accepted the default table prefix of wp_. Changing this to a slightly more obscure string may make your site more secure by making it harder for an attacker to guess your table names.

On the next page click Run the install.

How does it know my nickname

How does it know my secret nickname is Sparky? Wonder what else it knows…

Next, enter your site’s title, your administration username, password (twice), and email address. Click Install WordPress.

Enter administrative information

Provide the name of your site (this will appear on your home page), the username of your administrative user, your password, and email address. Decide whether to allow search engines to crawl your site.

If the installation was successful you should see the page below. Click Log In.

Click button to log in

The installation is done. Click the button to log in.

Enter your administrator’s username and password and click the Log In button.

Enter administrator username and password

Enter the administrator’s username and password that your entered during the installation.

You should now see the WordPress Dashboard.

WordPress Dashboard

If you see the WordPress Dashboard the installation was successful. It’s time for some configuration steps.

Configure WordPress

Now that WordPress is up and running, there are a couple of configuration settings that you might want to change. First, on the General Settings page, set your timezone. You can select a city in your timezone or select a GMT offset directly. Click Save Changes.

Choose your timezone.

Set the timezone for your location. You can choose a city or a GMT offset from the drop-down list. You might also want to change some of the other settings.

Next, on the Permalink Settings page, set your permalink style. I like Day and name, but each scheme has its advantages. You can also create a custom structure. Click Save Changes.

Permalink configuration

Most WordPress users like to configure Permalinks (aka “pretty URLs”). WordPress offers several different style options or you can customize your own.

Note: The prior step will create a .htaccess file in the /var/www/wordpress directory. This file configures Apache mod_rewrite to use index.php when a request comes in for any URL so that WordPress will take over and find the actual post or page requested.

Now that WordPress has created its wp-config.php and .htaccess files, you can remove group write access from the /var/www/wordpress directory as shown below.

$ sudo chmod g-w wordpress
Revoke group write access from the wordpress directory

Now that the installation and configuration tasks are complete, you can revoke group write access from the wordpress directory.

Note: The wp-config.php and .htaccess files are now owned by www-data with group www-data since they were created by the web server. In a production environment, you might consider changing the ownership to $USER:www-data and permissions to 644 as you did with the other files earlier.

To visit the site, hover your mouse over the site name in the toolbar and click Visit Site. You should see the colorful Twenty Thirteen theme as shown below.

The new Twenty Thirteen theme

The new Twenty Thirteen theme. Nice!

If you click on the Hello world! post you will see the disappointing 404 page below. We’ll fix that next.

Page not found

Oops! The Permalinks aren’t working. We need to enable Apache’s mod_rewrite module to make them work.

Enable Apache mod_rewrite

As you saw in the last section, the link to the Hello world! post could not be found on the server (this would also be true for the Sample Page). This is because WordPress uses Apache’s mod_rewrite module to implement its Permalinks. By default, mod_rewrite is installed but not enabled. To enable mod_rewrite we need to perform a couple of configuration tasks.

First, we need to add a <Directory> directive to /etc/apache2/sites-enabled/000-default to enable the .htaccess file that WordPress created earlier. Edit the file using your favorite editor and add the directives highlighted below.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        <Directory /var/www/wordpress>
                AllowOverride All
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Second, we need to enable mod_rewrite itself. To enable mod_rewrite launch a Terminal window and type the following commands. The first enables the rewrite module and the second bounces Apache so it re-reads its configuration files.

$ sudo a2enmod rewrite
$ sudo /etc/init.d/apache2 restart
Enable mod_rewrite and bounce the web server

Enable mod_rewrite and bounce the web server.

You should now be able to see the sample post and page in WordPress.

In this article we downloaded, installed, and configured WordPress on our Ubuntu LAMP development machine. In the process we extracted the WordPress tarball into our DocumentRoot, adjusted file ownership and permissions, created a new MySQL schema and user, and enabled Apache’s mod_rewrite module for WordPress Permalinks.

Speak Your Mind

*