WordPress

Install WordPress on Ubuntu 16.04

In this article I’m going to show you how to install WordPress on Ubuntu 16.04, using MariaDB and Nginx.

Before we begin, I’ll assume that you already know how to install the Ubuntu server and use the Linux command line.

Throughout this article I use apt in place of apt-get . It should work with Ubuntu, if not use apt-get in place of apt

If you are installing on Ubuntu 17, then replace all instances of 7.0 with 7.1 . Be sure to change every single instance.

Check for updates and upgrade, if necessary:

First type: sudo apt update -y
Then type: sudo apt upgrade -y

Adding the -y is optional, it simply answers Yes to any prompts.

Install Nginx:

Type: sudo apt install nginx -y

Edit Nginx default config:

Type: sudo nano /etc/nginx/sites-available/default

Delete everything in that file and replace it with the following server block (CTRL + K to delete line by line):

Change domain.com and www.domain.com to your actual domain name.
Save the file and continue. For Nano press CTRL + X , then type the letter Y and press ENTER.

Install PHP and the essential modules:

Type: sudo apt install php7.0-fpm php7.0-mysql php7.0-mcrypt php-mbstring php-gettext php-curl php7.0-gd -y

Enable Mbstring and MCrypt (multi-byte support and encryption):

Type: sudo phpenmod mcrypt mbstring

Install MariaDB:

Type: sudo apt install mariadb-client mariadb-server -y
Then type: sudo mysql_secure_installation

Below is a list of prompts you’re going to get, with the necessary key actions:

Enter current password for root (enter for none): [ENTER] Set root password? [Y/n] Y
New password: new_password
Re-enter new password: new_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Create database and database user:

Use the same password you created above.
There is no space after -p

Type: sudo mysql -u root -pnew_password

This will log you into the mariaDB monitor:

Replace the green text with a database name , username and password of your choosing.
user and database_name will be the same for each instance. Do not edit localhost.
You’re going to need your database_name, user and userpass at the end of this article.

Download and Install WordPress:

We’re almost done. This next lot of commands I’m going to put into a script, to save time.

First, we need to create a file to copy our commands into:

Type: touch wp_install.s
Then type: nano wp_install.s

wp_install.s can be whatever you want to name it.
You don’t need the .s at the end, I only add that for reference later on, so I know it’s a script.

Cut and paste the following block of code into the file.

Save the file and continue. For Nano press CTRL + X , then type the letter Y and press ENTER.

We need to make wp_install.s executable.
You shouldn’t need to use sudo if you’re doing this from your home directory.

Type: chmod +x wp_install.s

Now we will run the script, which does require sudo.

Type: sudo ./wp_install.s

Don’t panic when everything starts scrolling “loony toons” fast. It’s meant to!

You’re almost done. Now we need to update the WordPress wp-config.php with the details you created earlier.
But first, we also need to generate a secret-key (for your eyes only, never share it).

Type: curl -s api.wordpress.org/secret-key/1.1/salt/

Copy the entire contents of that output and continue:

Type: sudo nano /var/www/html/wp-config.php

Scroll to the bottom of the wp-config.php file and look for this block of code:

Replace that entire block of code with the code you just copied. Try not to delete anything else, or you will get errors.
You can delete lines of code in Nano by pressing CTRL + K on each line you want to delete.

With the document still open, find and replace the username, database and password with the ones you created earlier (in green). Beneath is the chunk of code you need to be editing. When you’ve done that, CTRL + X , type YES then press ENTER.

Now all you need to do is visit your WordPress url and follow the prompts.

Good job. Have fun with your new website.

Install phpMyAdmin (Optional):

Type: sudo apt install phpmyadmin
Type: sudo ln -s /usr/share/phpmyadmin/ /var/www/html/phpmyadmin
Type: sudo service nginx restart

Url: https://yourdomain.com/phpmyadmin