Install WordPress on Ubuntu 24.04 with Apache, MariaDB, PHP8.3 (LAMP)
Last Updated: October 6th, 2025
This tutorial is going to show you how to install WordPress on Ubuntu 24.04 with Apache, MariaDB, and PHP8.3 (LAMP Stack). WordPress is the most popular CMS (Content Management System) in the world. It is estimated that more than a third of websites today are powered by WordPress. PHP8.3 is included in the Ubuntu 24.04 repository, and WordPress runs perfectly with it.
Prerequisite
- To follow this tutorial, you need an Ubuntu 24.04 OS running on a remote server. You can utilize a Virtual Private Server (VPS) with at least 1GB of RAM.
- You also need a domain name so visitors can type your domain name in the web browser address bar to access your website.
- This tutorial assumes that you have already set up a LAMP stack on Ubuntu 24.04.
Step 1: Download WordPress
SSH into your Ubuntu 24.04 server and update existing software:
sudo apt update && sudo apt upgrade -y
Next, visit the official WordPress download page to grab the latest release archive or acquire it directly via the command line using wget:
wget https://wordpress.org/latest.zip
Next, extract the archive to the /var/www/ directory with unzip:
sudo apt install unzip
sudo mkdir -p /var/www/
sudo unzip latest.zip -d /var/www/
The -d option specifies the target directory. WordPress web files will be extracted to /var/www/wordpress. We can rename this directory to match your domain name for better identification (replace example.com with your real domain name):
sudo mv /var/www/wordpress /var/www/example.com
Step 2: Create a Database and User for WordPress Site
Log into the MariaDB shell as root with the following command:
sudo mysql -u root
Once you are logged in, create a dedicated database for WordPress:
create database wordpress;
Then enter the command below to create a database user for WordPress and grant all privileges. Replace wpuser and your-password with your preferred username and secure password:
grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';
flush privileges;
exit;
Step 3: Configure WordPress
Go to your WordPress directory:
cd /var/www/example.com/
Copy the sample configuration file and rename it to wp-config.php:
sudo cp wp-config-sample.php wp-config.php
Now edit the new config file with a command-line text editor like Nano:
sudo nano wp-config.php
Find the following lines and replace the placeholder text with your database name, username, and password:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your-password');
By default, every WordPress database table name begins with wp_ as the prefix. It’s highly recommended to change it to something unique to improve your environment security:
$table_prefix = '9OzB3g_';
Save and close the file. Next, set the Apache user (www-data) as the owner of the WordPress site directory:
sudo chown www-data:www-data /var/www/example.com/ -R
Step 4: Create an Apache Virtual Host file for WordPress
Run the following command to create a virtual host file for your WordPress site in Apache:
sudo nano /etc/apache2/sites-available/example.com.conf
Put the following configuration into the file. Replace example.com with your own domain name. Don’t forget to create corresponding A records in your DNS zone manager:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com
# This enables .htaccess files, which are needed for WordPress Permalinks to work.
<Directory "/var/www/example.com">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>
Save and close the file. Then test your configuration:
sudo apache2ctl configtest
If you see "Syntax OK", enable this virtual host block and reload Apache:
sudo a2ensite example.com.conf
sudo systemctl reload apache2
Now, enter your domain name in the browser address bar to load the wizard. If the installation wizard isn’t displayed or complains about missing libraries, install the necessary PHP extensions:
sudo apt install php8.3-mbstring php8.3-xml php8.3-mysql php8.3-common php8.3-gd php8.3-bcmath php8.3-json php8.3-cli php8.3-curl php8.3-zip
sudo systemctl reload apache2
Step 5: Enabling HTTPS
To encrypt your HTTP traffic, you can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Certbot:
sudo apt install certbot python3-certbot-apache
Run this command to obtain and install the TLS certificate automatically:
sudo certbot --apache --agree-tos --redirect --hsts --uir --staple-ocsp --email [email protected] -d yourdomain.com,www.yourdomain.com
Once the setup completes, your installation wizard will run safely over HTTPS.
Step 6: Finish the Installation with the Setup Wizard
Follow the on-screen configuration fields to set up an admin account, site title, and finalize the standard installation process.
Optimizing Domain Routing and Service Settings
Redirecting WWW to Non-WWW (Or Vice-Versa)
You can manage your canonical target domain variants directly within the web application. Navigate to your WordPress Dashboard > Settings > General and enforce your preferred version (www or non-www) in both the WordPress Address and Site Address fields using the secure https:// prefix.
Fixing the Double 301 Redirect
To optimize performance and bypass an explicit double redirect behavior, you can map your direct routing layers into the virtual host configuration files. Edit the primary virtual host configuration file:
sudo nano /etc/apache2/sites-enabled/example.com.conf
Locate the RewriteRule appended by Certbot and modify it to target your final canonical variant directly instead of relying on the variable:
RewriteRule ^ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
Next, apply the matching logic directly inside the SSL configuration layer file:
sudo nano /etc/apache2/sites-enabled/example.com-le-ssl.conf
Add these rewrite guidelines right above the closing </VirtualHost> block to instantly push domain variants directly to your final destination choice:
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
Save changes and reload Apache to apply updates cleanly:
sudo systemctl reload apache2
TLS Certificate Auto-Renewal
Let's Encrypt certificates require a renewal schedule. Automate this via the system crontab management space:
sudo crontab -e
Append the renewal task block to run daily checks and automatically reload Apache configuration maps when modifications happen:
@daily certbot renew --quiet && systemctl reload apache2
Increase Upload File Size Limit
If you use PHP-FPM to process web scripts, you should increase the upload threshold from the standard 2MB value to handle larger theme assets or media gallery uploads. Run the following inline adjustments directly onto your configuration map files:
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 20M/g' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 20M/g' /etc/php/8.3/fpm/php.ini
sudo systemctl restart php8.3-fpm
How to Send Emails in WordPress
Your WordPress site needs to send transactional emails for system actions like account registration or password resets. Setting up an isolated mail server or using a dedicated mail infrastructure handles this cleanly. It is recommended practice to run your mail host environment and WordPress on two separate servers to optimize speed and protect your primary server IP from direct tracking or DDoS vulnerabilities.
Once you have a secure SMTP environment ready, integrate it via an email module directly in WordPress:
- Go to your WordPress Dashboard, select Plugins > Add New, and search for
WP Mail SMTP. Install and activate the plugin. - Navigate to the newly active WP Mail SMTP settings pane in the dashboard menu sidebar.
- Scroll down to the Mailer selection area, toggle the option from the default PHP mailer mechanism over to Other SMTP.
- Fill out the configuration blocks with your secure SMTP infrastructure parameters:
- Enter your mail host target endpoint string.
- Select TLS encryption and force port 587.
- Enable authentication checks, then map your system inbox address and its target password key securely.
Save your configuration to complete the setup. You can test delivery actions by triggering a routine password reset link from your platform gateway login page.