Install wordpress on Ubuntu 16.04

WordPress is one of our most popular Website builders. It allows you to build sites with a MySQL backend and PHP processing. We’re going to focus on getting this installed on Ubuntu 16.04 using the terminal. Before we begin, there’s a few other things that need to be taken care of.

Prerequisites:

Alright, now that you gotten the pre-work out of the way, you should be a bit more familiar with the terminal interface. There’s still a few more steps before we actually start installing wordpress, but lets take care of those now.

Step 1: Create a MySQL database and User for wordpress.

First, we’re going to login to MySQL as the root user. Run this command to log in as the root MySQL user:

This will prompt you for the password created during the MySQL setup.

Next, we’re going to create a database named WordPress. You can call it whatever you want, but I’ll be using wordpress to keep it simple.

All mysql commands MUST end in a ;

Next, we’re going to create a user named wordpressuser (feel free to change this if you want). We going to create the account, set the password, and grant access to the wordpress database we created using this command.

Lastly, we need to flush the privileges so that MySQL knows about the new information.

then type the exit command.

Step 2: Install Common PHP Extensions

 

First, we’re going to make sure our software is up to date and grab some of the more popular wordpress PHP extensions with the following commands:

Wordpress plugins have a variety of requirements. You need to check your plugin documentation to determine those. You can use the apt-get command above to get these.

Now we just need to restart apache.

 

Step 3: Configure Apache to allow for .htaccess Overrides and Rewrites.

Before installing wordpress, we need to make some adjustments to apache’s configuration. By default, the use of .htaccess files are disabled. WordPress uses these for in-directory changes to the server’s behavior. We’re also going to be enabling mod_rewrite, which is needed for permalinks to work correctly.

First, we need to open Apache’s primary config file with the following command:

We’re going to add some code to the bottom of this file that will allow .htaccess files in the document root directory.

Save and close the file.

Finally, restart apache using the same code as before.

Step 4: Downloading WordPress

Now that we’ve changed the server configuration as needed, we can actually install wordpress. You’re in the home stretch!
Change to a writable directory. We suggest to make a directory named tmp in the root folder. In the examples below, replace that with whatever directory you use instead.

Then download the wordpress zipfile. For security reasons, its always advisable to download wordpress from the official site.

Extract the file to our writeable directory:

We’re going to be moving these to the wordpress directory in a few steps, but for now, lets create a .htaccess file and set its permissions using the following commands:

We’re also going to use WordPress’s default configuration by running the following command:

Lets also go ahead and create a directory for our wordpress upgrades, to avoid permissions issues later on

Now that we’ve got all our permissions and directories set, we’re going to copy everything over to our wordpress primary directory:

 

Step 5: Configuring the WordPress Directory.

 

Before we move to the wp-admin page, we need to make some final adjustments to our Primary WordPress Directory.
We’ll start with ownership of all the files in the wordpress directory to our sudo user. I’ll be using HWUSER, but you should use the sudo account you set up during the Prerequisite setup.

Next, we’re going to set it so that new files in this directory will inherit permissions.

Lets then give group write access to the wp-content directory. This will allow the web app to make theme and plugin adjustments

Lets make sure we have all the permissions for plugins and themes by also running

Step 6: Setting up the configuration file

WordPress uses secure keys to authenticate each install, and provides a key generator to ensure key complexity. Lets use that generator now by running the following command:

You’ll get back a list of secure values that look similar to this. Be sure to have them accessible for the next step.

Make sure to generate your own. You want these to be private

Now open the wordpress config file:

Find the section that contains the dummy values. It’ll look something like this:

You’ll want to plug in those values generated earlier into this file, replacing the dummy ones.

Next, we’ll need to tell WordPress to use the username and password we set up in MySQL.

Inside the same file you put those secure values in, you’ll want to add these lines. If you used a user other than wordpressuser in that step, you’ll replace those values here:

Finally, save and close.

WordPress is now installed on your server! Simply navigate to http://YOUR_SERVER_IP and follow the onscreen prompts.


Share:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.