How to Install WordPress with Apache on Ubuntu 18.04 2022

WordPress is by far the most popular open source blogging and CMS platform, powering more than a quarter of the world’s websites. It is based on PHP and MySQL and offers a variety of features that can be extended with free and premium plugins and themes. WordPress makes it easy to create your ecommerce store, website, portfolio or blog.

In this tutorial, we are going to show you how to install WordPress on an Ubuntu 18.04 machine. The process is relatively straightforward and takes less than ten minutes. At the time of writing this article, the latest version of WordPress is version 5.0.2.


We will be using a LAMP stack with Apache as web server, SSL certificate, latest PHP 7.2 and MySQL/MariaDB as database server.

requirements

Make sure the following prerequisites are met before proceeding with this tutorial:

  • Have a domain name that points to your server’s public IP address. We use example.com .Logged in as a user with sudo privileges. Apache will be installed by following these instructions. You have installed an SSL certificate for your domain. You can install a free Let’s Encrypt SSL certificate by following these instructions.


Refresh the package list and update the installed packages to the latest versions:

sudo apt update sudo apt upgrade

Creating a MySQL database

WordPress uses MySQL database to store all its data like posts, pages, users, plugins and theme settings. First, we create a MySQL database, a MySQL user account and grant access to the database.

If you don’t have MySQL or MariaDB installed on your Ubuntu server, you can do so by following one of the guides below:


Login to the MySQL shell by typing the following command:

sudo mysql

In the MySQL shell, run the following SQL statement to create a database:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Next, create a MySQL user account and grant access to the database:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'change-with-strong-password';

Finally, exit the MySQL console by typing:


EXIT

Install PHP

PHP 7.2, the default PHP version in Ubuntu 18.04, is fully supported and recommended for WordPress.

Run the following command to install PHP and any required PHP extensions:

sudo apt install php7.2 php7.2-cli php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

Restart Apache for the newly installed PHP extensions to load:

sudo systemctl restart apache2

WordPress is downloading

Before downloading the WordPress archive, first create a directory to hold our WordPress files:


sudo mkdir -p /var/www/example.com

The next step is to download the latest version of WordPress from the WordPress downloads page using the following wget command:

cd /tmp wget https://wordpress.org/latest.tar.gz

When the download is complete, extract the archive and move the extracted files to the domain’s document root:

tar xf latest.tar.gz sudo mv /tmp/wordpress/* /var/www/example.com/

Set the correct permissions to allow the web server full access to the site’s files and directories using the following chown command:

sudo chown -R www-data: /var/www/example.com

Configure Apache

By now, Apache with SSL certificate should already be installed on your system if you don’t check the prerequisites for this tutorial.

The next step is to edit the Apache virtual hosts configuration for our WordPress domain:

sudo nano /etc/apache2/sites-available/example.com.conf

The following Apache configuration guides http to https and www to a non-www version of your domain and enable HTTP2. Do not forget, example.com with your WordPress domain and set the correct path to the SSL certificate files.


/etc/apache2/sites-available/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted

Enable virtual host for the domain. The following command creates a symbolic link from the sites-available sites-enabled to the sites-enabled Directory created:

sudo a2ensite example.com

Restart the Apache service for the new configuration to take effect by typing:

sudo systemctl restart apache2

Completing the WordPress installation

With WordPress downloaded and server configuration complete, it’s time to complete the WordPress installation through the web interface.

Open your browser, enter your domain and a screen similar to the following will appear:

From here you can customize your WordPress installation by installing new themes and plugins.

Conclusion

Congratulations, you have successfully installed WordPress with Apache on your Ubuntu 18.04 server. Getting started with WordPress is a good starting point to learn more about getting started with WordPress.

Ubuntu WordPress MySQL Mariadb CMS Apache

Previous post What is Apache | WordPress
Next post Clickfunnels Experiences & Test 2022 ▷ Prices, Costs, Templates