WordPress

Install WordPress

In this walkthrough we will setup WordPress on an Apache web server running PHP and a MySQL database called MariaDB. The Linux operating system will be Ubuntu 22.04.2. SSL will be setup with Let’s Encrypt using certbot . I have SSH’d into the server so I need to open the SSH port before enabling the universal fire wall.

# sudo ufw allow 22/tcp
# sudo ufw enable

Update server.

# sudo apt update && sudo apt upgrade -y
Apache

1. Install & Configure Apache.

# sudo apt install -y apache2

We will need to allow Apache through the firewall by opening port 80/tcp and 443/tcp for HTTP and HTTPS.

# sudo ufw allow 'Apache Full'
# sudo ufw status

Start Apache.

# sudo systemctl enable --now apache2

Create the file example.conf for the Apache virtual host in directory /etc/apache2/sites-available.

# sudo vi /etc/apache2/sites-available/example.conf

Add the following code, un-hash logs if required.

<VirtualHost *:80>
    ServerAdmin contact@example.com
    DocumentRoot /var/www/example/wordpress
    ServerName example.com
    ServerAlias www.example.com

    <Directory "/var/www/example/wordpress">
         Allowoverride All
    </Directory>

    # ErrorLog logs/example.com-error_log
    # CustomLog logs/example.com-access_log combined
</VirtualHost>

The configuration should automatically create symlinks within /etc/apache2/sites-enabled/. If not run the following command to enable the configuration.

# sudo a2ensite example.conf

Disable the default site 000-default use -p to purge all traces of the module in the internal state data base.

# sudo a2dissite -p 000-default

Restart Apache.

# sudo systemctl reload apache2
PHP

2. Install PHP and PHP extensions.

# sudo apt install -y libapache2-mod-php php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip

Restart Apache.

# sudo systemctl reload apache2
MySQL

3. Install & Configure MariaDB (MySQL).

# sudo apt install -y mariadb-server

Start MariaDB Service and enable for auto start.

# sudo systemctl enable --now mariadb

Secure database.

# sudo mysql_secure_installation
  1. Set root password
  2. Remove anonymous
  3. Set local only
  4. Remove test db
  5. Reload permissions

Configure MariaDB with user and database for WordPress.

# sudo mysql -u root -p

Enter these values changing <database-name>, <user-name> and <password> we will need to remember these for later when setting up WordPress.

MariaDB [(none)]> CREATE DATABASE <database-name>;
MariaDB [(none)]> CREATE USER <user-name>@localhost IDENTIFIED BY '<password>';
MariaDB [(none)]> GRANT all PRIVILEGES ON <database-name>.* TO <user-name>@localhost;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> QUIT;
SSL

4. Install & Configure SSL

Check Apache virtual host is setup correctly.

# sudo apache2ctl configtest

Result should be syntax ok, If changes are needed the reload Apache after.

# sudo systemctl reload apache2

Install Certbot and python3-certbot-apache a plugin to connect Certbot with Apache.

# sudo apt install -y certbot python3-certbot-apache

Obtain a certificate with Certbot.

# sudo certbot --apache

Verify Certbot auto-renewal

# sudo systemctl status certbot.timer

Test Renewal.

# sudo certbot renew --dry-run
WordPress

5. Install & Configure WordPress

To download WordPress we will need the wget package.

# sudo apt install -y wget

Download WordPress in www so it can be used for other websites.

# sudo cd /var/www/
# sudo wget https://wordpress.org/latest.tar.gz

Extract WordPress.

# sudo mkdir -p /var/www/example
# sudo cp /var/www/latest.tar.gz /var/www/example
# sudo tar xzf /var/www/example/latest.tar.gz
# sudo rm /var/www/example/latest.tar.gz

Setup file access.

# sudo chown -R www-data:www-data /var/www/example
# sudo chmod -R 775 /var/www/example

Configure WordPress. Open your favorite browser and enter your domain name example.com into the URL.

# https://example.com/

Follow the installation steps using the database details we setup earlier in this walkthrough.

Scroll to Top