I created this blog not too long ago in an effort to help developers, system administrators, and even bloggers. As many of you know, I’m using Digital Ocean to host this WordPress blog because it gives me the performance I need for the amount of traffic I receive.
In case anyone wants to follow in my footsteps, I’m going to walk you through getting WordPress up and running on a Digital Ocean Virtual Private Server (VPS) Droplet. However, this tutorial will work on any VPS that meets the operating system requirements I set, not just Digital Ocean.
Now I could point you here and tell you to set it up with the server image that Digital Ocean has on file for WordPress, but there are a few things I don’t like about this:
Before going any further you should already have the LAMP (Linux, Apache, MySQL, PHP) stack running on your VPS. If you’re not sure how, check out the tutorial I wrote regarding how to install the LAMP stack in Debian Linux. You don’t need to be using Debian though. You just need to be running some flavor of Debian (Debian, Ubuntu, Mint, etc.) with the LAMP stack.
We’re going to assume that WordPress will be the only website running on your server. Using a Terminal (Mac or Linux) or PuTTY (Windows), sign into your Digital Ocean Droplet. It will look something like this:
You probably won’t be using the
root user and you definitely won’t be using
127.0.0.1 because this isn’t a server local to your machine. Fix it as appropriate.
When signed into your server, navigate to the /var/www directory using your Terminal or appropriate application. For the remainder of this guide I’m going to reference the Terminal because I’m on a Mac. Navigation will look like this:
This directory may require access from a privileged user account such as root or a user that can use the
sudo command. Remember this if you get permission denied problems when executing any commands from this directory.
From the /var/www directory, download the latest version of WordPress using WGET like so:
This will download a the latest version, but you still need to extract it. Before we extract WordPress, go ahead and remove the html directory that already exists in the /var/www directory as it is no longer needed:
rm -Rf html
With that directory gone, you can extract WordPress and prepare it for use:
tar -xzvf latest.tar.gz && mv wordpress html
In the above you can see that we’ve extracted the latest version of WordPress to a directory called wordpress then immediately moved (renamed) it to html.
Now that the WordPress files are in place we need to configure the database.
Assuming you never made a privileged non-root MySQL user, go ahead and sign into the root user account for MySQL:
mysql -u root -p
We need to do four things when it comes to our WordPress database:
Let’s start with creating the database:
CREATE DATABASE wordpress;
With the database created it is time to create a new local user:
CREATE USER wordpress@localhost;
Notice I chose to use @localhost. This is because I don’t want database connections remotely from the server. If the database connection is not from the same server as MySQL, it should be rejected.
Time to change the password for this wordpress user:
SET PASSWORD FOR wordpress@localhost= PASSWORD("password");
Finally we can give the wordpress user permission for full access on all tables of the wordpress database:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost IDENTIFIED BY 'password';
The database should be good to go.
With the database ready to go, from the /var/www/html directory first make a copy of the base WordPress configuration file:
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
We did this in case we make mistakes in the future. Open the wp-config.php file because we need to add the database information to it:
define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpress'); define('DB_PASSWORD', 'password');
Those definitions will already exist, you just need to find them in the file and put the correct information. If you’re using vi or vim as your editor, just type
/DB_NAME or similar to jump to the line that contains it. Save the file and you should be good to go!
From your web browser navigate to your server IP, or if you configured a domain name with Digital Ocean, navigate to that. You should be presented with a WordPress UI configuration page. Follow the directions and you’ll be ready to start using WordPress.
If you’ve been playing around with your setup you may have noticed you cannot install any themes or plugins. This is because you don’t have FTP installed on your server (or at least you shouldn’t). I don’t recommend installing FTP on your server. It is just one more resource to be wasted, not to mention it could potentially create holes (risks) in your server.
Instead we want to set up the WordPress CLI tool. Navigate to your /opt directory and run the following command to download the CLI tool:
Go ahead and give it execute permissions like so:
chmod +x wp-cli.phar
If you want to run this file by typing
wp into the Terminal, you have two options. You can either add it to your
PATH from the /opt directory or move the file to a directory that already exists in your path. Let’s go with the second option since it is easier to do:
mv wp-cli.phar /usr/local/bin/wp
You are now able to do all kinds of cool stuff with WordPress including installing, updating, and removing themes or plugins.
Say you’ve found a cool theme or plugin for WordPress and you’d like to install it using the CLI. Navigate to your WordPress installation and execute one of the following commands:
wp theme install spacious
The above command will install the Spacious theme to your WordPress instance. If you want to install a plugin you can run the following similar command:
wp plugin install wordpress-seo
The above command will install the WordPress SEO plugin to your instance.
Depending on how many themes and plugins you have installed, you will get update notifications frequently. You’ve locked down your WordPress instance so you cannot install things or run updates via the dashboard. From the WordPress CLI, run the following command:
wp plugin update --all wp theme update --all
Remember, the Terminal must be in your /var/www/html directory. The above command will update all themes and plugins.
You’ve just set up WordPress on a virtual private server (VPS). You should feel good about yourself! If you’re not already a Digital Ocean user and are planning to sign up, please use one of the links I provided because I’ll get affiliate credit which will help fund my blog. Not to mention that you’ll get free credits if you use my links.
A video version of this article can be seen below.