Step-by-Step WordPress Setup on Ubuntu with Apache and MariaDB

blurry computer

This is just a reminder for how I did this for myself, though I do hope some others fine this useful as every time I install WordPress without a guide I seem to miss something that leads to weird permission errors.

This will be based off a Ubuntu Installation using 22 LTS

I deployed my site to Linode with the following setup CPU: 1 core RAM: 2GB

Honestly this is just a list of instructions. Just follow through and you should have a shiny new WordPress install.

#Update apt and upgrade packages
sudo apt update
sudo apt upgrade

#Install Apache2
sudo apt install apache2
sudo a2enmod rewrite
sudo systemctl start apache2
sudo systemctl enable apache2

#Set FQDN
sudo vim /etc/apache2/apache2.conf

## Add in the end of the file 
ServerName thesimpledev.com

#Configure Virtual Hosts
sudo a2dissite 000-default.conf
sudo vim /etc/apache2/sites-available/site.conf

## File contents
<VirtualHost *:80>
    ServerName thesimpledev.com
    ServerAlias www.thesimpledev.com
    ServerAdmin steven@thesimpledev.com
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =thesimpledev.com [OR]
    RewriteCond %{SERVER_NAME} =www.thesimpledev.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

sudo a2ensite site.conf
sudo vim /etc/apache2/sites-available/site-ssl.conf

## File Contents
<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName thesimpledev.com
    ServerAlias www.thesimpledev.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

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

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/thesimpledev.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/thesimpledev.com/privkey.pem

</VirtualHost>
</IfModule>

sudo a2ensite site-ssl.conf
sudo apache2ctl configtest
sudo systemctl restart apache2

#Install MariaDB (Dropin replacement for MySQL)
sudo apt install mariadb-server mariadb-client
sudo systemctl start mariadb
sudo systemctl enable mariadb

#Secure the DB installation
sudo mysql_secure_installation

#Login with your root account
sudo mysql -u root -p

#Your password should be blank so just press enter and then run
#IMPORTANT! Make sure to change password
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

#Install PHP
sudo apt install php libapache2-mod-php php-mysql php-gd php-json php-curl php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl imagemagick php-imagick

#Configure PHP
cd /var/www/html
sudo vim info.php

##insert the following information
<?php phpinfo(); ?>

##Visit the site go get the location of the php.ini file
rm info.php
sudo vim /dir/php.ini

##Fine and update the following values
upload_max_filesize = 512M
post_max_size = 512M
memory_limit = 1024M
max_execution_time = 900
max_input_time = 900

#Download and install WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo rsync -av wordpress/ /var/www/html/

#Configure your WordPress
cd /var/www/html
rm index.html
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php

#Use the following values once again replacing password
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
define('WP_MEMORY_LIMIT', '1024M');
define('DISABLE_WP_CRON', true);

#Setup file permissions
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/ -type f -exec chmod 640 {} \;

#Restart time!
sudo systemctl restart apache2

sudo apt-get install certbot python3-certbot-apache
sudo certbot --apache
sudo certbot renew --dry-run

#Set up real cron
sudo crontab -e
*/5 * * * * wget -q -O - https://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Everything should hopefully work after all of that.