5 minute read

Install WordPress on an Ubuntu VPS Specifically on Ubuntu 12.04 or Later

what happened to this house?

Installing WordPress is pretty simple these days.  The WordPress Codex has very good information on the steps that need to be taken to get up and running.  I have done it so many times at this point I thought that I would share some portions of my installation script that might be useful to some people.  This post assumes that you have a newly created Ubuntu 12.04+ VPS and are looking to put WordPress on it.  For the sake of simplicity I am going to assume a DigitalOcean droplet.

OK, so here we go...

1. Create a User

Since you can initially only sign-in to your droplet as root you will immediately want to create a user.  This process is probably familiar to you.  You will also want to add this user to the sudo and the www-data groups.  www-data is the user that WordPress runs as.

$ adduser your-new-user-name
$ adduser your-new-user-name sudo
$ adduser your-new-user-name www-data

Now log out and log back in as your new user.

2. Add Swap

DigitalOcean has a good tutorial on how to add swap to their droplets.  I recommend adding at least 512MB of hard-disk swap.  The reason for adding this swap is to prevent your server from crashing if (and when) it runs out of RAM.

3. Install the WordPress Dependencies

WordPress has some dependencies including Apache, MySQL, etc. The commands below will install a LAMP stack, the PHP libraries that are needed, the correct Apache modules, Git, PHPMyAdmin, Vim, sendmail, and some image optimization libraries. You can adjust the according to your tastes. When tasksel runs please select LAMP server.  You will also need to select a MySQL and PHPMyAdmin password.

$ sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install python-software-properties -y && sudo tasksel && sudo apt-get install php5 php5-gd php5-mysql php5-curl php5-cli php5-cgi php5-dev -y && sudo a2enmod rewrite expires headers mime deflate filter && sudo service apache2 restart && sudo apt-get install phpmyadmin -y && sudo apt-get install vim -y && sudo apt-get install git-core git-gui git-doc -y && sudo apt-get install sendmail -y && sudo apt-get install libjpeg-progs gifsicle optipng imagemagick -y

4. Create a Directory for Your Website

By default, Apache wants to run in the /var/www/ directory.  Personally, I don't like this but you can place your site anywhere you want.  I choose to put it in /home/website-name/. 

$ cd /home/
$ sudo mkdir {site-name}
$ cd {site-name}
$ sudo mkdir public_html && sudo mkdir logs

5. Setup a Virtual Host

Now we need to tell Apache where our sites directory is.  We will create a Virtual Host for this and we will disable the default Virtual Hosts.  For clarity, we will call this file website-name.

$ cd /etc/apache2/sites-available
$ sudo a2dissite default*
$ vim website-name

Now place the code for the Virtual Host in the website-name file.

<VirtualHost *:80>
  ServerAdmin ryan@digitalbrands.com
  ServerName {site-url}
  ServerAlias www.{site-url}
  DocumentRoot /home/{site-url}/public_html
  ErrorLog /home/{site-url}/logs/error.log
  CustomLog /home/{site-url}/logs/access.log combined
</VirtualHost>

Finally, let's enable the Virtual Host and restart Apache.

$ sudo a2ensite website-name && sudo service apache2 restart

6. Install WordPress

OK, now it is time to install WordPress itself. WordPress provides a nice URL to get the latest version so this step becomes very simple.

$ cd /home/website-name/public_html/
$ wget http://wordpress.org/latest.tar.gz && tar -xzvf latest.tar.gz && mv ./wordpress/* ./ && rm -rf ./wordpress && rm latest.tar.gz

7. Set the Permissions

The permissions for WordPress can be a bit of a pain at times.  I use sticky permissions to (usually) set these correctly for the long term.

$ cd /home/website-name/
$ sudo chgrp -R www-data public_html/ && sudo chmod -R g+w public_html/ && sudo find public_html/ -type d -exec sudo chmod g+s {} \; && sudo chown -R www-data public_html/

8. Create a Database

There are many ways to create a database but I find it easiest to just use PHPMyAdmin.  For this step you will need to not only create a database but also create a user specific to that database that has all of the permissions.

Go to your-website.com/phpmyadmin and login with the information you provided in step 3.  Your username is probably currently set to root.

Next, select Databases in the top left corner and then create a database with any name you would like.  I find it easiest to just create a database with a similar name to the website being created.  You could add some random string to the end for added security.

Create a Database with PHPMyAdmin

Your database will be created.  Select the database you just created on the left side of the screen and then select Privileges. Now select Add New User.

Create a New User in PHPMyAdmin

Pick a User Name that will be for this database.  Also, Set the Host to Local and hit the Generate password button.  This will create a very secure password for your user.  Please copy this password for reference in the next step.  Lastly, make sure that Grant all privileges on database "your-website" is selected and hit the Go button at the bottom of the screen.

9. Set up WordPress wp-config.php

WordPress has a nice GUI to help you set up your wp-config.php file.  All you need to do is visit your-website.com and the basic installation page should come up.  Here you will enter information like your Database NameDatabase User Name, and Database User Password.  

WordPress Installation Screen

Click Submit and WordPress will create the wp-config.php file for you.

10. Bask in Your Glory

That is pretty much it.  In the next screen you can enter your WordPress site's name and information, your username, and password and then hit Submit and you should be up and running,

If you have any trouble just leave a comment below.


Leave a Reply

Your email address will not be published.