How To Install WordPress With Self-Signed SSL And Apache2 On Ubuntu 14.04

This brief tutorial is going to show you how to easily install WordPress with Apache2 and self-signed SSL certificate support on Ubuntu 14.04. Since most webmasters are migrating to WordPress over SSL, this guide should help you get started in a test environment before actually implementing it on your live sites.

A good thing to always do is test your environment and configuration before implementing. The best solution is to setup a test environment or virtual workstation where you can test changes before applying them to your real site.

When you’re thinking about implementing secure WordPress for your sites, you should first test your setting. Create a new guest machine, same configuration as your live site and carry out your test. For this post, I’ll be using VirtualBox software with Ubuntu 14.04 server installed. Then I will install Apache2 with SSL module enabled, and create a self-signed certificate.

After setting up Apache2 and the self-signed certificate, I will then install WordPress over a HTTPS or HTTP over SSL. That’s it.

Enhance your coding experience with this split keyboard that offers up to 9" of separation.

So, this tutorial only applies to new WordPress installation. If you already have a working WordPress blog, then this won’t be the post to read. I will write a tutorial later that will show you how to migrate your existing WordPress to HTTPS.

After installing Ubuntu 14.04 on a guest machine or which other ways you installed it, and after configuring basic settings, go and install Apache2.

  • Installing Apache2 on Ubuntu 14.04

To install Apache2 on Ubuntu, run the commands below

sudo apt-get update && sudo apt-get install apache2

 

Next, run the commands below to enable Apache2 SSL module. This module is responsible for process SSL certificates for Apache2.

sudo a2enmod ssl

 

Next, restart Apache2 by running the commands below. Everytime you enable a module for Apache2, restart Apache2 to apply the changes.

sudo service apache2 restart

 

  • Creating a Self-Signed SSL Certificate

The reason we’re creating self-signed SSL certificate is because we’re using a test environment. A self-signed certificate isn’t a trusted certificate you can use online. It’s only mostly used in test environments.

For your live WordPress site, you will have to register and get a trusted certificate from a Certificate Authority or CA. Then install the certificate on your blog.

The process is the same as what we’re doing here.

Create a directory to hold your certificates.

sudo mkdir -p /etc/apache2/ssl

 

Then run the commands below to generate a server certificate key called server.key and create a self-signed certificate called server.crt, copy both files into the new directory created above.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/server.key -out /etc/apache2/ssl/server.crt

 

If you’re going to use a trusted certificate issued by a trusted CA on your WordPress blog, then you’ll need to run the commands below to create a certificate signing request. Then send the CSR file to a CA to sign it and generate a SSL certificate for your blog. You’ll then continue below to learn how to apply the certificate you’ll receive from the CA.

openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr

 

Since we’re not using a CA in our test environment, only run the commands which create a server key and encrypt it as well to create a SSL cert.

When prompted after running the commands above, answer correctly based the screen below.

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:Minnesota
Locality Name (eg, city) []:Minn
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Blog
Organizational Unit Name (eg, section) []:Dept of Blogging
Common Name (e.g. server FQDN or YOUR name) []:myblog.com
Email Address []:webmaster@yourdomain.com

 

After that, open Apache2 default SSL configuration file to include the location of the SSL certificate file and certificate key.

sudo vi /etc/apache2/sites-available/default-ssl.conf

 

Add / change to the lines below.

[.....]
ServerName mydomain.com:443
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
[.....]

 

Save the file and close out.

 

Next, enable the default SSL site file by running the commands below.

sudo a2ensite default-ssl.conf

 

Restart Apache2 and test the site. By this time, you should be able to access the site using HTTPS in your browser.

 

When SSL is working OK, continue below.

 

  • Installing MySQL Database on Ubuntu 14.04

Then next thing is installing MySQL database server on Ubuntu. WordPress using database servers to store and retrieve data. The most popular open source database server is MySQL. Install it below.

sudo apt-get install mysql-server mysql-client

 

You’ll be prompted to create a database password. Create it and keep it.

Next, start the database server by running the commands below.

sudo service mysql start

 

Then use the commands below to sign on to the database as root using the password you created for it.

mysql -u root -p

 

Then run the SQL statement below to create a WordPress database called wordpressdb.

CREATE DATABASE wordpressdb;

 

Next, create a database user called wordpressuser with new password

CREATE USER wordpressuser@localhost IDENTIFIED BY 'user_password_here';

 

Then give the users control over the wordpress database

GRANT ALL ON wordpressdb.* TO wordpressuser@localhost;

 

Exit.

 

  • Installing PHP5 and other PHP5 modules on Ubuntu

The next step is installing PHP5 and other tools. WordPress is a PHP application and depends on PHP to function. Run the commands below to install it.

sudo apt-get install php5 php5-gd php5-ldap php-pear php5-xmlrpc php5-mcrypt php5-tidy php5-common php5-snmp php5-curl php5-mysql

 

After that, run the commands below to download WordPress file.

cd /tmp && wget http://wordpress.org/latest.zip

 

Then unzip the downloaded file.

unzip latest.zip

 

Then copy the content to the default Apache2 document root.

sudo cp -rf wordpress/* /var/www/html/

 

Then make Apache2 the owner of the directory.

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

 

Then set the permission on the directory correctly by running the commands below.

sudo chmod -R 755 /var/www/html/

 

Rename WordPress wp-config-sample.php file to wp-config.php

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

 

Edit wp-config.php file and add the database connection information.

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

 

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpressdb‘);

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

/** MySQL database password */
define(‘DB_PASSWORD’, ‘data_user_password‘);
Save the file and you’re done.

 

Restart Apache2 and you should be able to connect to the site and install WordPress.

sudo service apache2 restart

 

Open your host file on Windows or other machine and add an entry for mydomain.com to point to your server IP address.

Open the command prompt as an administrator on Windows, then run the commands below.

notepad C:/windows/system32/Drivers/etc/hosts

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.168.107.71                 myblog.com

 

Try to access https://myblog.com/index.php  and WordPress installation should come up.

 

wordpress ssl installation

 

Continue with the installation until you’re done.

 

install wordpress over ssl

 

 

Enjoy!

 

SSL wordpress installation

 

Protect yourself and your devices with the most trusted internet security software availabe.

Invest in some screen real estate with a new big screen, backlit monitor availabe in five different sizes and price points.

8 thoughts on “How To Install WordPress With Self-Signed SSL And Apache2 On Ubuntu 14.04”

  1. Great walk through. If you’re like me and want to use the WP site as your default site; mv the index.html to something like index.old

Leave a Reply

Your email address will not be published. Required fields are marked *