How to Install WordPress on Ubuntu 17.10 with Apache, MariaDB, PHP7.1

This tutorial is going to show you how to install WordPress on Ubuntu 17.10 with Apache, MariaDB and PHP7.1. WordPress is the most popular content management system (CMS) in the world. It is estimated that more than a quarter of websites today are powered by WordPress.

PHP7.1 made into the Ubuntu 17.10 repository and WordPress runs perfectly with it. This tutorial assumes that you have already set up a LAMP stack on Ubuntu 17.10. If not, please check out the following tutorial.

Step 1: Download WordPress

Next, go to wordpress.org download page and download the zip archive. You can acquire the direct download link by right-clicking the download button and select copy link location.

Then at the command line, type in wget followed by the direct download link to download WordPress to your Ubuntu 17.10 server.

wget https://wordpress.org/latest.zip

Next, extract the zip archive using the command below.

sudo apt install unzip
sudo unzip latest.zip

A new directory named wordpress will be created in the current working directory. Now We move this directory and all its content to Apache web root. Replace example.com with you real domain name.

sudo mv wordpress/ /var/www/example.com

Step 2: Create a Database and User for WordPress Site

Log into MariaDB shell as root with the following command.

sudo mariadb -u root

Once you are logged in, create a database for WordPress using the following command. I named it wordpress, but you can use whatever name you like such as you site name. (Don’t leave out the semicolon.)

create database wordpress;

Then enter the command below to create a database user for WordPress. This command also grant all privileges of WordPress database to the user.

grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';

Flush the privileges table for the changes to take effect and then exit out of MariaDB shell.

flush privileges;
exit;

Step 3: Configure WordPress

Go to your WordPress directory.

cd /var/www/example.com/

Copy the sample configuration file.

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

Now edit the new config file.

sudo nano wp-config.php

Find the following lines and replace the red texts with the database name, username and password you created in the previous step.

How to Redirect www to non-www

The Apache configuration we created allows site visitors to access the website via both www and non-www domain. You can redirect one version to another by going to WordPress Dashboard > Settings > General. Then set WordPress Address and Site Address to your preferred version.