Install WordPress on Ubuntu 17.04 | 17.10 with Apache2 HTTP/2 and Let’s Encrypt SSL

The good thing about starting a new WordPress website or blog is that you get a chance to set up everything right the first time. When you get it right the first time, there will be no need to go back to fix issues that weren’t setup correctly.

When starting a new website in 2018, don’t forget to include these: SSL/TLS and HTTP/2 support.

These days, majority of websites and blogs are running over HTTPS.

WordPress sites running over HTTPS or SSL/TLS may rank better than those that are not. Since HTTPS is important in the eyes of Google and other search engine providers, why not include it with your WordPress setup.

Also, HTTP/2 (version 2) is the newer version to HTTP/1 and is rapidly gaining tractions as well. So, if you’re going to be installing WordPress in 2018, get a free Let’s Encrypt SSL/TLS certificate and well as enable HTTP/2.

This brief tutorial is going to show students and new users how to install WordPress with Apache2 HTTP/2 and Let’s Encrypt support on Ubuntu 17.04 | 17.10.When  you’re ready to get WordPress setup properly, continue with the steps below:


It’s good to always update Ubuntu servers before installing packages… to update Ubuntu, run the commands below.

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

After updating Ubuntu, continue below with installing required packages for WordPress to work.


Starting with Apache2 version 2.4.24 and up, HTTP/2 support is included by default… The Apache2 version the comes with Ubuntu doesn’t have support for HTTP/2, at least not yet. To install Apache2 with HTTP/2 support, you’ll need to add third-party repository… Run the commands below to install the latest version of Apache2 with HTTP/2 support.

sudo add-apt-repository ppa:ondrej/apache2
sudo apt update
sudo apt install apache2

Now that Apache2 latest is installed, run the commands below to enable HTTP/2 support… HTTP/2 support is enabled from Apache2 2.4.24 and up.

sudo a2enmod http2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service


MariaDB database server is rapidly overtaking MySQL in the open source and Linux communities… MariaDB is the default database server on majority of Linux distributions… and WordPress requires a database server.. run the commands below to install MariaDB.

sudo apt-get install mariadb-server mariadb-client

After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

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

After that, run the commands below to secure MariaDB server and create a new root password.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat 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


Now that Apache2 and MariaDB are installed, run the commands below to install PHP and related PHP modules on the new server. This is a good list of PHP modules to install.

sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl

After install PHP, run the commands below to open PHP-FPM default file.

sudo nano /etc/php/7.x/apache2/php.ini

Depending on your system, the x in the command above could be 0 or 1 .

Then scroll down the lines in the file and change the following lines below and save.

post_max_size = 100M
memory_limit = 256M
max_execution_time = 360
upload_max_filesize = 100M


At this point, all the required WordPress packages and and servers are installed. The new server  is now ready to host WordPress… On the new server, create a blank WordPress database. WordPress will use this empty database to store its content.

Run the commands below to logon to the database server. When prompted for a password, type the root password you created above.

sudo mysql -u root -p

Then create a blank database called WP_database  you can use the same database name from the old server.


Create a database user called wp_user with new password.  You can use the same username and password from the old server.

CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'type_password_here';

Then grant the user full access to the database.

GRANT ALL ON WP_database.* TO 'wp_user'@'localhost' IDENTIFIED BY 'type_user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.



Next, configure the WordPress site configuration file on the server. Run the commands below to create a new configuration file called wordpress.conf

sudo nano /etc/apache2/sites-available/wordpress.conf

Then copy and paste the content below into the file and save it. Replace with your own domain name.

<VirtualHost *:80>   
  ServerAdmin [email protected]
     DocumentRoot /var/www/html/wordpress/

     <Directory /var/www/html/wordpress/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined


Save the file and exit.


After configuring the VirtualHost above, enable it by running the commands below

sudo a2ensite wordpress.conf
sudo a2enmod rewrite


Next, visit WordPress site and download the latest…. or run the commands below to do that for you.

cd /tmp && wget
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/html/wordpress

Then run the commands below to set the correct permissions for WordPress root directory.

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


Next, run the commands below to create WordPress wp-config.php file. This is the default configuration file for WordPress.

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

Then run the commands below to open WordPress configuration file.

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

Enter the highlighted text below that you created for your database and save.

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

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

/** MySQL database password */
define('DB_PASSWORD', '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', '');

Save the file and you’re done.

Now all is configured… run the commands below to reload Apache2 web server settings.

sudo systemctl reload apache2.service

After that, open your browser and browse to the server IP address or domain name to continue with WordPress setup.

Step 10: Obtain and Configure Let’s Encrypt SSL Certificates

Now that the WordPress configuration is done, continue below to get Let’s Encrypt installed and configured. Let’s Encrypt now provides a Apache2 client to automate this process.

Before obtaining Let’s Encrypt certificates, make sure your Apache2 configuration is setup correctly… for your site config file, make sure the ServerName and ServerAlias are defined.

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/wordpress/

When those settings are confirmed, continue below to get the certificate for your domain name.

To get the Let’s Encrypt SSL/TLS client installed on Ubuntu, run the commands below

sudo apt-get install python-certbot-apache

After that run the commands below to obtain your free Let’s Encrypt SSL/TLS certificate for your site.

sudo certbot --apache -m [email protected] -d -d

After running the above commands, you should get prompted to accept the licensing terms. If everything is checked, the client should automatically install the free SSL/TLS certificate and configure the Nginx site to use the certs.

Please read the Terms of Service at You must
agree in order to register with the ACME server at
(A)gree/(C)ancel: A

Choose Yes ( Y ) to share your email address

Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
(Y)es/(N)o: Y

This is how easy is it to obtain your free SSL/TLS certificate for your Nginx powered website.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Pick option 2 to redirect all traffic over HTTPS. This is important!

After that, the SSL client should install the cert and configure your website to redirect all traffic over HTTPS.

Congratulations! You have successfully enabled and

You should test your configuration at:

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2018-02-24. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

The highlighted code block should be added to your Apache2 WordPress configuration file automatically by Let’s Encrypt certbot. Your WordPress site is ready to be used over HTTPS.

<VirtualHost *:80>   
  ServerAdmin [email protected]
     DocumentRoot /var/www/html/wordpress/

     <Directory /var/www/html/wordpress/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

A new configuration file for the domain should also be created named /etc/apache2/sites-available/wordpress-le-ssl.conf. This is Apache2 SSL module configuration file and should contain the certificate definitions defined in it.

<IfModule mod_ssl.c>
<VirtualHost *:443>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/wordpress/
      <Directory /var/www/html/wordpress/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/
SSLCertificateKeyFile /etc/letsencrypt/live/
Include /etc/letsencrypt/options-ssl-apache.conf


When Let’s Encrypt configured and HTTP/2 enabled, add this like to the Apache2 global configuration file to enable HTTP/2 on all sites.

sudo nano /etc/apache2/apache2.conf

Then add the line below anywhere in the file and save… After that, restart and HTTP/2 will be enabled on all sites.

Protocols h2 http/1.1

If you don’t want to enable it for all sites, add the line above to the site specific SSL config file.

<IfModule mod_ssl.c>
   <VirtualHost *:443>
      ServerAdmin [email protected]
      DocumentRoot /var/www/html/wordpress/
      Protocols h2 http/1.1

Save and restart Apache2.

sudo systemctl reload apache2.service

and Let’s Encrypt installed and configured…. Open your browser and browse to the domain name or IP address


If everything is setup correctly, you’ll see WordPress setup wizard and continue with the setup.

ubuntu wordpress lets encrypt

Follow the on-screen instruction to complete the wizard.. you will be asked to input your database configuration, administrative details and other configuration settings. When complete you may sign-in and start using InvoiceNinja. Return to anytime thereafter to sign-in.

That’s it!

To setup a process to automatically renew the certificates, add a cron job to execute the renewal process.

sudo crontab -e

Then add the line below and save.

0 1 * * * /usr/bin/certbot renew & > /dev/null

The cron job will attempt to renew 30 days before expiring

You may also like the post below:

1 Comment

  1. Thank you, great post!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.