HowTo: Self Hosted WordPress on Ubuntu 16.04LTS
Self-Hosted WordPress on Ubuntu 16.04LTS
There are a lot of good reasons to use a hosting provider for your website or blog. A hosting provider will give you a platform to host your site without the responsibility of maintaining a server or needing to know the low level configuration details of the server software and WordPress.
But, if you’re a little bit technical, want to learn to be a little bit technical, or just want to get your site off the ground for free, self hosting on a VPS (virtual private server) is a great option. Both Google Cloud Platform (GCP) and Amazon Web Services (AWS) offer free servers for at least a year. Google recently added an Always Free option for a small VPS.
Both the free options are more than powerful enough to start self-hosting a small website. Both are scalable so if your website grows your infrastructure can grow with it, or you can move to a reputable manager service provider.
Both providers offer Ubuntu 16.04LTS virtual servers. In this post we are going to walk through setting up WordPress on Ubuntu 16.04LTS. WordPress requires a few pieces of software. You will need web serving software, PHP, and a database.
In light of you being a little bit technical I’m going to assume you already have a domain (or are comfortable using the IP address to access your server temporarily) and understand how DNS works.
WE WILL USE
- Ubuntu 16.04.2 LTS
- WordPress 4.7.3
- Nginx (web server)
- PHP7.0-FPM (PHP processing)
- MariaDB (MySQL compatible database server)
Installing the Server Software
We need to install and configure Nginx, PHP and MariaDB before we can setup WordPress. To simplify things, we are going to
sudo su - and run all the commands in this post as root.
Install the required software packages
Configure Nginx and php7.0-fpm
Next we have to uncomment a few lines to process PHP scripts properly in the default nginx site configuration.
/etc/nginx/sites-enabled/default with your preferred text editor (#vi4life), add index.php to the index list, and uncomment the following lines.
We also need to enable php7.0-fpm and nginx to run at system start and we’ll go ahead and start both services so we can verify everything is working the way we expect right now.
Enable and start services
At this point you should have nginx and PHP configured to run on your server. We can verify this by using the server’s IP address or your domain name in a web browser.
Before doing that let’s create a PHP file to make sure we’re processing PHP scripts. Change directory into
/var/www/html/ and create a file named test.php with the phpinfo() function as contents.
The phpinfo() function will display some information about your version and configuration of PHP on your system. The details aren’t important right now. What we’re looking to do is verify that your system is processing PHP files properly and displays the phpinfo() page. If you are prompted to download the file test.php there is a problem.
You most likely need to double check your /etc/nginx/sites-enabled/default file.
If you’re on track you should see the phpinfo page.
Configure MariaDB (MySQL)
MariaDB is a fork of MySQL that was created after Oracle took over MySQL. If you prefer to use MySQL these steps should work just fine, but I am not going to test them. If you do and have problems please let us know in the comments.
Alright, first things first. We’ve got MariaDB installed, but we need to configure the root password and clean up the default installation. The easiest way to do this is by using the
mysql_secure_installation script. This is installed as part of MariaDB.
The script will ask for the current MySQL root password and you an hit Enter to continue. The next question will ask if you want to change the root password. Yes, you do. Enter your desired password and then confirm and you can plow through the rest of the script accepting the defaults.
Creating the WordPress database
Next we will create a database and grant wpuser access to the database.
To install WordPress we will need to download it to the server, extract it to the website document root, create our wp-config.php, and run the install.
The easiest way to download the latest version of WordPress to your server is running
cd; wget https://wordpress.org/latest.tar.gz.
Now we’ve got wordpress and we need to extract the files into our document root directory. We’re going to delete the files in
/var/www/html/, extract the WordPress archive, and then copy the files into
Install WordPress files
We will now go open a browser and enter our URL. You will be greeted with the ‘Welcome to WordPress’ page. From here we will setup the database and wp-config.php file.
Enter the database user and password you created earlier in this guide and click Submit.
We are now asked to create the wp-config.php file. You can copy the text and paste it into
/var/www/html/wp-config.php. Once you’ve done that click
Run the install.
One more page to fill out before we can call it complete.
After running the install you should be able to login. Now you’re ready to familiarize yourself with WordPress, select a theme, customize, and start posting.