Setting Up an Ubuntu Server for WordPress Hosting with Apache2, PHP 8.2-FPM, and MySQL
By: Bobby
Published on: Nov 16, 2025
2 min read.
In this guide, we’ll walk through the process of configuring a fresh Ubuntu server (tested on Ubuntu 24.04 LTS) to host WordPress efficiently. We’ll use Apache2 as the web server, PHP 8.2-FPM for faster and more scalable PHP processing (instead of the mod_php Apache module), and MySQL for the database. This setup is ideal for production environments, supporting features like process management and better concurrency.
Prerequisites:
- A server with Ubuntu 24.04 LTS installed (root or sudo access).
- A static IP address and domain name (optional but recommended for production).
- Basic command-line knowledge.
We’ll update the system first, then install and configure each component step by step.
Step 1: Update the System
Start by ensuring your server is up to date:
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
Reboot if prompted:
sudo reboot
Step 2: Install Apache2
Install Apache2:
sudo apt install apache2 -y
Enable and start the service:
sudo systemctl enable apache2
sudo systemctl start apache2
Test it by visiting your server’s IP in a browser—you should see the Apache default page.
Adjust firewall rules (if UFW is enabled):
sudo ufw allow 'Apache Full'
sudo ufw reload
Step 3: Install MySQL Server
Install MySQL:
sudo apt install mysql-server -y
Secure the installation:
sudo mysql_secure_installation
Follow the prompts: Set a root password, remove anonymous users, disallow remote root login, and remove test databases.
Enable and start MySQL:
sudo systemctl enable mysql
sudo systemctl start mysql
Step 4: Install PHP 8.2 and PHP 8.2-FPM
Add the Ondřej Surý PPA for the latest PHP versions:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
Install PHP 8.2, FPM, and common WordPress extensions:
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath php8.2-intl -y
PHP-FPM should start automatically. Verify:
sudo systemctl status php8.2-fpm
Step 5: Configure Apache for PHP-FPM
Disable the default mod_php (if any) and enable proxy modules
sudo a2dismod php8.2
sudo a2enconf php8.2-fpm
Restart Apache:
sudo systemctl restart apache2
Edit the default site config to use FPM. Backup first:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.bak
Edit the file:
sudo nano /etc/apache2/sites-available/000-default.conf
Ensure the <Directory /var/www/html> block includes:
<FilesMatch \\.php$>
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"</FilesMatch>
(Full example config snippet at the end of this step.)
Restart Apache again:
sudo systemctl restart apache2
Test PHP Processing: Create /var/www/html/info.php:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Visit http://your-server-ip/info.php—it should show PHP info processed by FPM. Delete the file afterward for security:
sudo rm /var/www/html/info.php
Step 6: Secure Your Server with HTTPS Using Certbot
Now that Apache is serving PHP via FPM, let’s lock it down with a free Let’s Encrypt SSL certificate using Certbot. This enables HTTPS, improves security, and boosts SEO.
Install Certbot
sudo apt install certbot python3-certbot-apache -y