Self-host WordPress on Ubuntu 24.04 with Nginx + MariaDB + PHP 8.3. The full install takes 30 minutes: install the LEMP stack, download WordPress, configure the database, configure Nginx, open the firewall. The team that has a $5/month VPS and 30 minutes has a working WordPress, and the team that does this once has a recipe for the next 10.
Table of contents
- Before you start
- Step 1: install the LEMP stack
- Step 2: secure MariaDB
- Step 3: download WordPress
- Step 4: configure WordPress
- Step 5: configure Nginx
- Step 6: firewall and SSL
- Step 7: finish the install
- How this fits the rest of the stack
- FAQ
Before you start
What you need:
-
An Ubuntu 24.04 VPS (any cloud provider, 1 vCPU + 1 GB RAM is the minimum, 2 vCPU + 2 GB is comfortable)
-
A domain name pointed at the VPS’s IP (an A record)
-
SSH access as a non-root user with sudo
The team that uses a $5/month VPS has enough for a small site. The team that uses a $20/month VPS has headroom for traffic spikes and growth.
Step 1: install the LEMP stack
sudo apt update && sudo apt upgrade -y
sudo apt install nginx mariadb-server php-fpm php-mysql php-xml php-mbstring php-curl php-gd php-zip php-intl
Start the services:
sudo systemctl enable --now nginx mariadb php8.3-fpm
(Adjust the PHP version - 8.3 is the current default on Ubuntu 24.04. Verify with php --version.)
Step 2: secure MariaDB
sudo mysql_secure_installation
Set a root password, remove anonymous users, disallow remote root login, remove the test database. The team that skips this has an open MariaDB - the script is the lock.
Create the WordPress database:
sudo mysql -u root -p
Inside MariaDB:
CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 3: download WordPress
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo cp -a /tmp/wordpress/. /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress
www-data is the user Nginx runs as on Ubuntu. The chown is required - WordPress needs to write to wp-content.
Step 4: configure WordPress
cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Set the database credentials (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST = localhost). The team that uses the credentials from step 2 fills these in.
Also set the WordPress security keys - get them from https://api.wordpress.org/secret-key/1.1/salt/ and paste them in. The team that uses the generated keys has cookies that are signed properly.
Step 5: configure Nginx
Create /etc/nginx/sites-available/wordpress:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable and reload:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 6: firewall and SSL
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
For SSL (Let’s Encrypt, free):
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Certbot edits the Nginx config to redirect HTTP to HTTPS and auto-renew the cert. The team that runs a real site always has HTTPS.
Step 7: finish the install
Open https://example.com in a browser. The WordPress installer runs. Set the site title, admin username, admin password, admin email. The team that uses a strong password and a real email has a WordPress they can recover.
After install: log in at /wp-admin, set the permalink structure (Settings -> Permalinks -> Post name), install a few essential plugins (a security plugin, a backup plugin, a caching plugin), pick a theme, and start writing.
FAQ
How much does it cost to self-host WordPress?
VPS: $5-20/month. Domain: $10-15/year. SSL: free (Let’s Encrypt). Total: under $30/month for a small site. The team that runs a high-traffic site adds a CDN ($0-50/month) and a managed database ($15-50/month).
Can I migrate from wordpress.com later?
Yes - export from wordpress.com, import to the self-hosted install. The team that plans a 1-2 week migration with a low DNS TTL has a smooth cutover.
How do I back up my WordPress?
The most reliable: a plugin like UpdraftPlus or BackWPup that backs up the database and wp-content to S3, Google Drive, or local. Test the restore. The team that has a backup but has not tested the restore has a backup that may or may not work.
How do I speed up WordPress?
- Use a caching plugin (WP Super Cache, W3 Total Cache, or LiteSpeed Cache if you use LiteSpeed). 2. Use a CDN. 3. Optimize images (ShortPixel, Imagify). 4. Use a fast theme (avoid heavy page builders). 5. Use a recent PHP version.
Should I use a static site generator instead?
If the site is mostly content (no comments, no user accounts, no eCommerce), a static site generator (Hugo, Astro, Eleventy) is faster, more secure, and cheaper to host. WordPress is the right pick if you need the plugin ecosystem, user accounts, comments, or eCommerce.
How this fits the rest of the stack
For a sense of what the full project costs before it commits, the RunxBuild hosting calculator shows the line items together. The API, the database, the storage, the worker, the bandwidth - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers.
Useful related references: