Networking

How to install WordPress on Ubuntu 16.04

If you have a need for a WordPress installation, follow the simple steps of getting this powerful platform up and running on Ubuntu 16.04.

wordpresshero.jpg
Image: Jack Wallen

At one point in time, WordPress was the most powerful blogging platform on the planet. And then something interesting happened...WordPress evolved beyond a mere blogging tool. With a massive repository of plugins and an ever-growing number of highly flexible themes, WordPress is used for e-commerce, content management, and so much more.

For anyone wanting to host their own instance of WordPress, all you need is a LAMP stack. Learn the simple process of spinning up a WordPress instance with the help of Ubuntu 16.04.

SEE: WordPress: Why we didn't tell you about a big zero-day we fixed last week (ZDNet)

Prerequisites

First, we must make sure you have the LAMP portion of this server up and running. Since we're using Ubuntu as a foundation, we can install the entire LAMP stack with a single command. Open a terminal window and issue the following commands:

sudo apt-get update && apt-get upgrade
​sudo apt-get install lamp-server^

The above commands will install all of the necessary components for your LAMP server. During the installation, you may be prompted to create and verify a password for the MySQL administrator. If you installed your Ubuntu Server to include the MySQL functionality, chances are you set that administrator password during the operating system installation.

Next we must install the necessary PHP modules. Go back to your terminal window and issue the following command:

sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd

We now must test to ensure that PHP is working properly by creating a test file. Issue the command sudo nano /var/www/html/info.php and copy the following content into the file:

<?php
​phpinfo();
​?>

With that file in place, point a browser to http://IP_OF_SERVER/info.php. You should be greeted by the PHP information screen (Figure A).

Figure A

Figure A

PHP is installed and ready to go.

Create the WordPress database

Before moving onto the installation of WordPress, we must first create the necessary database. From the terminal window, issue the command mysql -u root -p. Note: If you designated a specific user to serve as the MySQL administrator, you will replace root with that user. Once you're on the MySQL prompt, issue the following commands to create the database (USERNAME is the MySQL admin user, and ADMIN_PASSWORD is the password associated with that user):

CREATE DATABASE wpdb;
​GRANT ALL PRIVILEGES ON wpdb.* TO 'USERNAME'@'localhost' IDENTIFIED BY 'ADMIN_PASSWORD';
​FLUSH PRIVILEGES;
​EXIT;

Download and install WordPress

We're ready to download and unpack the WordPress file. Back at your terminal window, issue the following commands:

wget -c http://wordpress.org/latest.tar.gz
​​tar -xzvf latest.tar.gz

I assume you are installing WordPress on a LAMP server that will also host other services. To that end, we'll move the entire wordpress folder to /var/www/html with the command:

sudo mv wordpress /var/www/html

Next we must give the wordpress folder the proper permissions with the commands:

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

For our next trick, we'll rename the WordPress configuration file and modify it to fit our setup. Rename the wp-config-sample.php file with the commands:

cd /var/www/html/wordpress
​sudo mv wp-config-sample.php wp-config.php

Open the file up for editing with the command sudo nano wp-config.php and locate the MySQL settings section (Figure B).

Figure B

Figure B

Configuring the WordPress configuration file.

Change the database_name_here, username_here, and password_here options to reflect your MySQL installation and the WordPress database we created earlier. Save and close that file.

Restart the Apache and MySQL servers with the commands:

sudo systemctl restart apache2.service
​sudo systemctl restart mysql.service

Now point a web browser to http://IP_OF_SERVER/wordpress and finish the installation via the browser-based wizard. To finalize the installation, select the language for the site, set the site title, add an admin user and password (password must be a minimum of WEAK for the installation to continue), and click Install WordPress (Figure C).

Figure C

Figure C

The finishing touches to your installation.

The installation is complete, and you can log in with your admin credentials to start building your site.

WordPress is ready to serve

WordPress is so much more than a blogging platform—after you install it, head over to the WordPress plugin repository to see just how much more you can make this platform do. You'll be surprised to find that WordPress can fill many a need.

Also see

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox