How to Install WordPress on Ubuntu 16

Try it in our public cloud & Get $5 Credit

WordPress (WP) is ubiquitous in the hosting world and with thousands of plug-ins and customization, it pretty much allows you to do anything you want.  It is not only easy to use but easy to install as well.  By the end of this tutorial you will have your own Ubuntu server running WP.

Getting Started

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) with Ubuntu 16.04 and a LAMP setup previously installed.

If you need to learn how to install LAMP on Ubuntu 16 visit our tutorial on it. Because of Ubuntu 16, PHP7 is now the standard version and is reflected in this tutorial.

If you don't want to go through the whole installation of WordPress on your CentOS 7 server, you can always try our One-Click Apps and get a new WordPress in seconds.

Let’s Start with MySQL

First we’ll create WordPress’ database. In these examples we’ll use “wordpress” as the database name, “wpuser” for the user and “wppassword” as the password. We recommend that you change the username and password to something unique and strong.  We will need to access MySQL with your database root credentials:

mysql -u root -p

Now, create the database where your WP will store its content.


We now need a user and password for the database. These credentials are for MySQL only, and are not how you will access your site in later steps.

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';

The created credentials now need the privileges necessary to update the database. We’ll assign those here.
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';

We’ve created the privileges, but they must now be confirmed and saved to the database in order to take effect.

Great, you’ve successfully set up the database. Let’s exit MySQL and begin setting up WordPress’ PHP scripts.

Installing WordPress

We will start by downloading the latest WordPress packages which ensure you will have the latest code, security updates or goodies. Fortunately, the latest download is stored at a permanent URL that is easy to retrieve.

cd /root
wget http://wordpress.org/latest.tar.gz

When complete, we can unzip the file. This will create a directory in which we’ll need to perform a few steps.

tar -zxvf latest.tar.gz

WordPress requires some extra PHP modules to be install on your ubuntu 16 server. Let’s install and activate them.

apt-get install php-gd php-ssh2 -y

All necessary PHP modules are now available and active. We will need to restart Apache to apply the changes.

systemctl restart httpd.service

We’re now ready to start setting up WordPress’ scripts to run under Apache. Let’s place them in Apache’s document root so it knows where to find them.

cd wordpress
cp * -R /var/www/html/

Next we need an uploads directory, where any content uploaded by users and administrators is stored.

mkdir /var/www/html/wp-content/uploads
chmod 775 /var/www/html/wp-content/uploads

Make sure to give  Apache permission to read and write to its document root. This will enable plugin installation and upgrades.

chown -R apache. /var/www/html/*

The WP files are now in place, so next we’ll need to tell it how to connect to the database. We’ll do that by entering the root directory.

cd /var/www/html/

Take a backup of the default configuration in case you make any mistakes.

cp wp-config-sample.php wp-config.php

It’s now time to set the database credentials. Do so by editing the wp-config.php file, replacing “wpuser” and “wppassword” with the database user and password set up in previous steps.

nano wp-config.php

Edit the file as following:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wpuser');
/** MySQL database password */
define('DB_PASSWORD', 'wppassword');

Save the file. You’ve just recorded database access credentials in a file that can be accessed over the web. To prevent that, let’s edit the .htaccess file to block this plus a few other common attacks.

nano /var/www/html/.htaccess

Edit the file as following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

We’re almost done. Save the file, and continue the installation by accessing the web-based installer. Visit http://your_main_ip to start the process.

First, select your default language. Next, set a site title. Set an administrative username, a strong password and enter your email address. Don’t choose usernames like “admin,” “webmaster” or “root” that an attacker might guess.

Always be sure to use a strong password.

You can now access your site with the username and password you just entered. Simply visit http://your_main_ip and start adding content!


You are now running WordPress on the latest LTS version of Ubuntu! Make sure to upkeep your server and your WP in the future and you will be able to enjoy all the current and new WordPress. If this guide was helpful to you, kindly share it with others who may also be interested.