Install WordPress on Ubuntu 16.04 – Beginner Guide [5 Minutes]


Learn How to install WordPress on Ubuntu 16.04.

WordPress is the best and most popular platform for creating websites and blogs. It will let you create websites easily with just drag and drop.

WordPress CMS is flexible and it makes anyone work with it easily. It powers a single page website to million visitor blogs and eCommerce stores.

It works with PHP and MySQL. If you are planning to move your WordPress blog from managed hosting to a server, then this guide will help you.

Nowadays, a lot of cloud service providers giving the small servers at very low cost. It can handle 20-30 times more traffic for the same money.

The problem with many people is they just can’t handle the server by themselves. Here, I am going to make it easier for you today.

In this guide, let us how to install WordPress on Ubuntu 16.04 server. You can use the same method for other versions of Ubuntu also.

Install WordPress on Ubuntu


  • Ubuntu 16.04 server configured according to the following Ubuntu initial server setup guide. If you have not followed this guide, just follow and set up your server as mentioned there.
  • You should have installed, LAMP stack installed on your server. I have covered how to install lamp on ubuntu.

Creating MySQL Database for WordPress

As I have mentioned earlier, WordPress requires MySQL to create and maintain a database to store and retrieve data. Since we are directly installing WordPress on the server, we have to manually create the database and user for it.

To log into the MySQL root, use the below command.

$ mysql -u root -p

Now, we are going to create a database for WordPress. It will be only used by WordPress. To create, use the below command. We will name the database WordPress.

mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

If you are not familiar with the MySQL, then always remember to add “;” at the end of each command in MySQL.

After the database creation, now create a MySQL user account which will be used for handling the database we created for WordPress.

Then, we have to grant permission for that MySQL user to use the WordPress database.

You can create user, password and grant permission using the below command.

mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Make sure, you choose the strong password for the user. Now, the user has access to the database. Execute the below command to MySQL to process the update.


After that, exit from the MySQL using the below command.


Adding More PHP Extensions

If you have followed the LAMP stack tutorial, you might only installed the basic PHP setup.

“You can use this how to install WordPress on ubuntu 16.04 guide for install WordPress on ubuntu localhost in your Ubuntu desktop version.

But, WordPress requires a lot of additional PHP extensions. It is because of the wide range of plugins being used and introduced every day.

You can check the plugin documentation to find out which PHP extension has to be installed.

It is very easy to install those extensions, here we will install some basic extensions which is enough for the basic WordPress setup.

First, update the package index using the below command.

$ sudo apt-get update

Then, follow this command to install the additional PHP extensions.

$ sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

If you install any new Plugins, just restart the apache to make the web server work with the new PHP extensions.

$ sudo systemctl restart apache2

Enabling .htaccess File Usage

Here comes the interesting part. The Apache and WordPress is the best combination.

Do you know why?

It is because of the .htaccess file. You can do many things with the .htaccess file. WordPress and many of its plugins use the .htaccess file for directory tweaks and access control.

Also, another main thing is mod_rewrite. This one is used for enabling the permalink in WordPress.

To enable the .htaccess file, open the Apache configuration file using nano editor.

$ sudo nano /etc/apache2/apache2.conf

Inside the file, find the Directory block. Add the AllowOverride directive as mentioned below.

. . .

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

. . .

Once you are done with that, just save and close the file.

Since we have enabled the .htaccess file, now we can enable the mod_rewrite.

$ sudo a2enmod rewrite

Before restarting the apache, check for the syntax error in the configuration file.

$ sudo apache2ctl configtest

You should see an output like the below one.

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
Syntax OK

Now, restart the Apache web server using the below command.

$ sudo systemctl restart apache2

Download and Install WordPress

First, we have to download WordPress from the official site. Whenever there is an update to WordPress, we can get the latest one from their official site.

First, move to the /tmp directory.

$ cd /tmp

To download WordPress, execute the below command.

$ wget -c

To unpack the archive, follow this one.

$ tar xzvf latest.tar.gz

Create a .htaccess file and change the permission for it inside the directory.

$ touch /tmp/wordpress/.htaccess
$ chmod 660 /tmp/wordpress/.htaccess

Now, copy the WordPress sample file to the original one.

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Here, we will create the upgrade directory to for WordPress. It will be required for WordPress to update itself in the near future.

$ mkdir /tmp/wordpress/wp-content/upgrade

Once the above process is completed, now, it’s time for us to move the entire WordPress setup into the directory from where the WordPress contents will be served by the web server software.

$ sudo cp -a /tmp/wordpress/. /var/www/html

Here -a will maintain the permission level.

WordPress Configuration

The main thing here is file permissions. Some times, we have to manually change the files and some times the web server has to read and write on some files.

If we do not set permission for the web server, it will cause problems later on. Here, we will assign permission to the user. Here is the command for that.

$ sudo chown -R sammy:www-data /var/www/html

When new directories are created, they have to inherit their parent directories. This can be done by executing the below command.

$ sudo find /var/www/html -type d -exec chmod g+s {} \;

After that, we have to enable the group writes access to the wp-content.

$ sudo chmod g+w /var/www/html/wp-content

Here comes the main task. As we have discussed earlier, we should give web server access to write on two main folders.

$ sudo chmod -R g+w /var/www/html/wp-content/themes
$ sudo chmod -R g+w /var/www/html/wp-content/plugins

To install WordPress securely, we have to provide some values. To get that, execute the below command.

$ curl -s

You will get the following output.

define('AUTH_KEY',         '1<g-T0!7ALgg2vFUiacs%i,[email protected]/CJ)^,;)ucIkL4xYuMghd=_w`_[,<?s;osY/L');
define('SECURE_AUTH_KEY',  '-P5c8QQ[Od]BUz2I+o>-_O=i&7&+}3sgW(>=S/&}i2cd*$SR)6>[email protected]@&%v.CCXs');
define('LOGGED_IN_KEY',    'EcUat(|x#c0m,A%qGzZ-^,R07-K^ >W^}?3u9>!y.GRAC$uU$s1qbI8X6A^R-R_:');
define('NONCE_KEY',        'j1z8^) !N2da`oR-B?,oyzWTMc4`wKBM>[N||oEej-HD~BNKci/b9OkYEMF(7/og');
define('AUTH_SALT',        '`R9YwqTCjfv79,D83g(FdCd`/MjJvZ2=L:^&[eSC7|R[Ol~*>DPG+Z[ie,^[email protected]>');
define('SECURE_AUTH_SALT', '[email protected])m8<{O`q.*~wuq>/!uHltTK*ap1zo0H*R3$*5adt.z4');
define('LOGGED_IN_SALT',   '[email protected]*)xEi4M=A-

amp;j$)fkY8i(^L|}X=4S/`deQ>v++aykDrzQfr_sn}Mm#/'); define('NONCE_SALT', 'LZ7)sD2rMV:7GL|F3-)Tt}f:&Hjj!o!1&s71gB*!y(_+ QMOTWY>bv+-E+|PrI,%');

Then open the wp configuration file and paste these value in the appropriate place.

After that, find the below-mentioned values and fill them with the appropriate credentials.

. . .

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

. . .

define('FS_METHOD', 'direct');

Then, save and close the file.


Go to the browser and enter your server IP address. From there, you will be taken to the WordPress setup wizard.

It is an easy one for everyone. Just finish the setup and start with the site.


In this tutorial, you have learned how to set up WordPress on Ubuntu. When you go with a service provider, they will charge you a lot for small resources.


Establishing one the cloud will help you to save resource and gives you more control over the server and WordPress management.


Share on facebook
Share on twitter
Share on linkedin

Leave a Comment