Install WordPress With Apache, MySQL, and SSL on Ubuntu 20.04

This guide shows the step by step instructions to install WordPress on Ubuntu 20.04 with Apache HTTP server, MySQL database, and an SSL certificate from Let’s Encrypt.

1. Get started by installing all of the required packages on your Ubuntu 20.04 system. This will include Apache, PHP, MySQL, Let’s Encrypt certification bot, and all of the extra Apache modules that WordPress requires in order to run properly.

$ sudo apt update
$ sudo apt install apache2 php libapache2-mod-php mysql-server php-mysql certbot python3-certbot-apache php-curl php-xml php-mbstring php-imagick php-zip php-gd

2. Next, we’ll run through the initial setup of MySQL. Execute the following command, then you’ll be required to answer the prompts that show up. Suggested responses are listed below.

$ sudo mysql_secure_installation

Validate password component? N
Root password? whatever_you_want
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database? Y
Reload privilege tables now? Y

3. With MySQL configured, we can setup our site’s database and user.

$ sudo mysql

For this example, we’ll set our database name and username to linuxnightly. Feel free to replace this with whatever name(s) you’d like.

mysql> CREATE DATABASE linuxnightly;
mysql> CREATE USER 'linuxnightly'@'localhost' IDENTIFIED BY 'strong_password_here';
mysql> GRANT ALL PRIVILEGES ON linuxnightly.* TO 'linuxnightly'@'localhost';
mysql> exit

4. Next, make a directory for your new site. Again, we’ll name ours linuxnightly.

$ sudo mkdir /var/www/linuxnightly

5. Create a new virtual hosts file.

$ sudo nano /etc/apache2/sites-available/linuxnightly.conf

And paste the following template inside of it. Change the values to match your own domain name, email, and site directory. Save your changes and exit the file when done.

<VirtualHost *:80>


DocumentRoot /var/www/linuxnightly
<Directory /var/www/linuxnightly>
	Options FollowSymLinks
	AllowOverride All
	Require all granted

ErrorLog ${APACHE_LOG_DIR}/linuxnightly_error.log
CustomLog ${APACHE_LOG_DIR}/linuxnightly_access.log combined

6. Enable your new site, and disable the default test site that came with Apache. We can also delete its directory entirely.

$ sudo a2ensite linuxnightly.conf
$ sudo a2dissite 000-default.conf
$ sudo rm -rf /var/www/html

7. Test your configuration for errors (you should receive a “Syntax OK” response), then restart Apache for the new changes to take effect.

$ sudo apache2ctl configtest
$ sudo systemctl restart apache2

8. After making sure you have configured your registrar’s DNS settings to point to your Ubuntu server, we can grab a free SSL certificate through Let’s Encrypt by running the following command. Be sure to substitute your own domain name and email into this example. This configuration will also redirect the www. prefix version of your domain name.

$ sudo certbot -d -d --apache --agree-tos -m --no-eff-email --redirect

The certbot program will continue to run in the background, always keeping your certificate up to date by renewing it when necessary. You can check its status with this command, to make sure it’s actively running on your system.

$ sudo systemctl status certbot.timer

To ensure that certbot will auto renew certificates successfully, use the following command to perform a dry run.

$ sudo certbot renew --dry-run

9. Download and install the latest release of WordPress into your site’s directory.

$ sudo wget -O /tmp/wordpress.tar.gz
$ sudo tar -xzvf /tmp/wordpress.tar.gz -C /tmp
$ sudo cp -av /tmp/wordpress/* /var/www/linuxnightly
$ sudo rm -rf /tmp/wordpress.tar.gz /tmp/wordpress

10. Set the proper permissions on your site’s directory.

$ sudo chown -R www-data:www-data /var/www/linuxnightly

11. Finally, you can navigate to your website in a browser and finalize your WordPress settings and installation. During setup, you’ll be prompted for the MySQL database, username, and password you created earlier, so have that information handy.

6 thoughts on “Install WordPress With Apache, MySQL, and SSL on Ubuntu 20.04”

  1. Thank you 🙂

    Best guide I found so far.
    Helped a lot.

    Please just add the process of making sure Certbot is running:
    sudo systemctl status certbot.timer
    Also, how to ensure a Cert will actually Auto Renew:
    sudo certbot renew –dry-run

    Thanks again.
    Have a great week.

    1. Apache and MySQL should be started automatically, and will run your website. If they are not running and you need to start them:

      sudo systemctl start apache2
      sudo systemctl start mysql

Leave a Comment

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