Install WordPress on Ubuntu 17.04 with Nginx, MariaDB and PHP Support

This brief tutorial shows students and new users a step by step guide to running WordPress on Ubuntu 17.04 (Zesty Zapus) with Nginx, MariaDB and PHP support. After this setup, users be able to run and manage dynamic and powerful websites using WordPress.

For those who don’t know WordPress, it’s a free content management system (CMS) that powers a lot of dynamic websites online. It allows anyone to easily create and design powerful websites using free tools and templates provided by the WordPress community.

Without wasting anymore of your time, let’s get started with installing WordPress on Ubuntu 17.04

Step 1: Install / Update Ubuntu

This post assumes you’re going to be running Ubuntu 17.04 and that you have root or administrative access to the system. Before you can begin installing supported packages in Ubuntu, you must first update the system. To do that, run the commands below.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After updating Ubuntu, you may want to restart your system. Continue below to install Nginx

Step 2: Install Nginx Web Server

Nginx is a powerful webserver. WordPress requires a webserver to serve pages. Since Nginx is easy to manage, lets install it. To do that, run the commands below

sudo apt-get install nginx

After installing Nginx, run the commands below to learn how to stop, start and enable Nginx service

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

After that, continue below to install MariaDB.

Step 3: Installing MariaDB Database Server

MariaDB is a quickly becoming the default database server for Linux systems. It’s rapidly overtaking MySQL which has been the default for a very long time for all Linux distributions. WordPress also requires a database server to function.

To install MariaDB, run the commands below

sudo apt-get install mariadb-server mariadb-client

After installing the database server, run the commands below to secure it.

sudo mysql_secure_installation

You’ll be prompted to answer series of questions.. use the example below to guide you.

Enter current password for root (enter for none): PRESS ENTER

Set root password? [Y/n] Y
CREATE YOUR 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

After securing the database server, run the command below to learn how to stop, start, and enable MariaDB service

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Continue below to create WordPress database.

Step 4 Create WordPress Database and User

Now that MariaDB Database server is installed.. your next task is to create a database for WordPress to use. You’ll also create a database user to manage the database.

Run the commands below to logon unto the database server

sudo mysql -u root -p

When prompted for the root password, type the one your created above.

Then run the commands below to create a new database called wpdb.

CREATE DATABASE wpdb;

Run the commands below to create a new database user called wpuser and grant the account full access to the wpdb database.

GRANT ALL ON wpdb.*  TO 'wpuser'@'localhost'  IDENTIFIED BY 'type_new_password_here';

Finally, run the commands below to save your changes and exit.

FLUSH PRIVILEGES;
exit

Continue below to install PHP

Step 5: Install PHP and Modules

Finally, the last require package for WordPress are PHP and its modules. To install these packages run the commands below

sudo apt-get install php-fpm php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc

After installing all the require packages, continue below to download WordPress content and configure it.

Step 6: Configuring WordPress

Now that WordPress database and user are created, go and download WordPress latest content. To do that, run the commands below

cd /tmp/ && wget http://wordpress.org/latest.tar.gz

Next, extract the downloaded content and copy it to Apache2 default root directory on Ubuntu.

tar -xzvf latest.tar.gz
sudo cp -R wordpress/* /var/www/html

Make sure to remove Ubuntu default index.html test file from default root directory. This can cause issues for new users.

sudo rm -rf /var/www/html/index.html

After that, create WordPress configuration file from its sample file by running the commands below.

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Then open wp-config.php file and make the following highlighted changes to reference the database and user you created above.

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

When the file opens, make the changes and save.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wpdb');

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Continue to configure Nginx

Step 7: Configure Nginx default site configuration

After setting up WordPress configurations, open Nginx default configuration file and make the below changes, then save the file.

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

Then make change highlighted changes and save the file.

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

Save the file and you’re done.

STEP 8: CHANGE WORDPRESS CONTENT FILE PERMISSIONS

After configuring WordPress settings, your next step will be to change the directory permissions so WordPress can function properly. To do that, run the below commands

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Finally, restart Nginx webserver and open your browser and go to the server IP address or hostname.

sudo systemctl restart nginx.service

Disable Apache2 web server so it never runs.

sudo systemctl stop apache2.service
sudo systemctl disable apache2.service

Open your browser and go to the server hostname and you should see WordPress default setup page.

http://localhost

Continue with WordPress wizard to setup your new site.

WordPress default setup page

Continue with the setup wizard and create a WordPress administration to manage the site online. Don’t forget to name the site appropriately.

wordpress nginx setup

Click Install WordPress when done.

Summary:

This post shows students and new users a simple way to get WordPress installed and configured on Ubuntu 17.04. Users who need to run their own WordPress websites will find this tutorial helpful especially if their new to it.

When you carefully follow the steps above, you’ll in no time have a working WordPress site ready to be customized.

You may also like the post below:

Installing phpMyAdmin on Ubuntu 17.04