wordpress is as simple as riding a bike

How to Install WordPress on Ubuntu 14.04

This post is part 7 of 11 in the series: Simple Guide To Planning & Developing A Website Project

This tutorial will install WordPress on a local development server using Ubuntu 14.04 and Vagrant. This process is also applicable to Ubuntu 16.04.

This step assumes you have already followed these steps:
How to Install VirtualBox, Vagrant and Ubuntu for Local Development
How to Install LAMP stack on Ubuntu

1. Create a new database

If you followed the tutorial on How to Install LAMP stack on Ubuntu, you can log in to phpmyadmin and create a new database for this WordPress install – or we can do it via the command line (using Git or Putty) following the steps below:

1.1 Log in to MySQL:

$ mysql -u root -p

1.2 Create a new database (name ‘mydbname’ it whatever you want):

mysql> CREATE DATABASE mydbname;

1.3 Create a new user (replace username with whatever you want) and password (replace password with something strong, keep apostrophes in place). Note that you can also bypass this step and use the default ‘root’ username for database access if you are the only user:

mysql> CREATE USER [email protected] IDENTIFIED BY 'password';

1.4 Grant user access to the database (replace mydbname with the database name you created above and username with the name you added above):

mysql> GRANT ALL PRIVILEGES ON mydbname.* TO [email protected];

1.5 Flush privileges:

mysql> FLUSH PRIVILEGES;

1.6 Now exit:

mysql> exit

2. Download & install WordPress

2.1 Change into the root directory and download the latest version of WordPress:

$ cd ~
$ wget http://wordpress.org/latest.tar.gz

2.2 Extract the files, this will create a directory called ‘wordpress’ in the home directory.:

$ tar xzvf latest.tar.gz

2.3 Install dependencies:

$ sudo apt-get install php5-gd libssh2-php

2.4 Change into the ‘wordpress’ directory and edit the ‘wp-config.php file:

$ cd ~/wordpress
$ cp wp-config-sample.php wp-config.php
$ sudo nano wp-config.php

Fill in the values for ‘DB_NAME’, ‘DB_USER’ and ‘DB_PASSWORD’ with values from the database you created earlier.

Ctrl-x, ‘Y’ to save and ENTER to exit.

2.5 After closing the file, we create another directory to copy files to a subdirectory. This will allow us to create as many sites as we want later (replace ‘site’ with whatever name you want), for example ‘/var/www/html/site’, ‘/var/www/html/site2’, etc.:

$ sudo mkdir /var/www/html/site

2.6 Copy the files to the document root:

$ sudo rsync -avP ~/wordpress/ /var/www/html/site/

2.7 Move into the directory (you will now see a folder of your site name with WordPress files in it if you look in your local ‘sites’ directory or whatever name you called it when you setup Vagrant):

$ cd /var/www/html/site

2.8 Change ownership properties, where user below is the user (e.g. root):

$ sudo chown -R user:www-data *

If necessary (you can check your local folder but chances are you will need to create it with the code below), manually create the uploads folder beneath the wp-content directory:

$ mkdir /var/www/html/site/wp-content/uploads

Then,

$ sudo chown -R :www-data /var/www/html/site/wp-content/uploads

2.9 Now you can complete the installation by going to the ip address of the install and entering the necessary information…
http://127.0.0.1/site (or http://localhost/site)

3. Modify Apache to allow URL rewrites

3.1 After WordPress is installed, we modify apache to allow URL rewrites:

$ sudo nano /etc/apache2/sites-available/000-default.conf

3.2 (1) Uncomment and set the ServerName to localhost and (2) create a directory section underneath where we allow overrides. It should look like the code below (it’s not necessary to set ServerAdmin to your email address):

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName localhost

<Directory /var/www/html/>
AllowOverride All
</Directory>
. . .

Ctrl-X, ‘Y’ and ‘ENTER’ to save and exit.

3.3 Next:

$ sudo a2enmod rewrite
$ sudo service apache2 restart

if there is not one already, create an .htaccess file (WordPress will probably already have created one for you. You can check in your local folder):

$ touch /var/www/html/site/.htaccess
$ sudo chown :www-data /var/www/html/site/.htaccess
$ chmod 664 /var/www/html/site/.htaccess

3.4 Now in WordPress settings, we can got to ‘Settings’ > ‘Permalinks’ and choose settings as necessary.

4. How to install folder sync using Vagrant

If you followed the tutorial on How to Install VirtualBox, Vagrant and Ubuntu, you will have already synced folders with Vagrant so skip this section because you are DONE. This allows Vagrant to process everything stored in our local folder so we always have our local files available for when we want to push any development changes to our production server [later]. If you want to sync folders now:
Open Vagrantfile in your project folder and find this line:

# config.vm.synced_folder "../data", "/vagrant_data"

Uncomment the line and edit it to look like the code below, replacing ‘sites’ with the name of the folder that you installed WordPress to:

config.vm.synced_folder "sites", "/var/www/html"

Now, back to the Git command line enter:

$ vagrant reload

This will reload your new Vagrant settings. Now when you go to your project folder > ‘sites’ (or whatever name you chose), you will see your new WordPress installation folder (’site’). Whatever edits you make in the local WordPress folder will be reflected and processed by Vagrant.

Note that now that we have this folder sync set up, when we can add other WordPress sites and we don’t have to use the Git command line to make changes to our ‘wp-config.php’ file. We can just do it in our local directory.

DONE

In the next part of this series, we will walk through how to setup a production server using Ubuntu 16.04.

REFERENCES

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04

If you don’t have an account already, sign up to DigitalOcean using this link which will give you a $10 credit (2 months FREE using a $5/mo droplet!) which also helps support this site.

Series Navigation<< How to Install LAMP Stack on UbuntuHow to Setup a Ubuntu 16.04 Production Server >>

Ken Favors is an Information Systems and Technology professional, an astute investor - and a history, music, arts and design enthusiast.

2 comments On How to Install WordPress on Ubuntu 14.04

  • Can you write a tutorial on how to install nginx on a local server instead of apache?

    • Yes I will. Actually, if you will be working with nginx on your production site, you should also do the same for your local dev environment (Both local and production servers should be identical). I used this install for 14.04 before 16.04 was released and have yet to update it. I will update this post soon to reflect nginx and ubuntu 16.04. Note that after you have done these steps a few times, it will probably become somewhat tedious to have to type in all of these commands each time you want to spin up a new local server. I will eventually post a tutorial on how to create a vagrant base box where everything is already installed – and you can even share the boxes to others so everyone is working in the same environment.

Leave a reply:

Your email address will not be published.

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

Site Footer