How to Install WordPress on Ubuntu Server (Nginx, PHP and MariaDB)

WordPress runs about forty percent of the web, and hosting it yourself costs nothing beyond the server you already have. You need three things it sits on — Nginx (tutorial 26), MariaDB (tutorial 29) and PHP — and then WordPress itself is a folder of files and a five-minute web installer.
Quick reference
| Step | Command |
|---|---|
| Install PHP | sudo apt install php-fpm php-mysql php-xml php-gd php-curl php-mbstring php-zip php-intl -y |
| Make the database | sudo mysql → CREATE DATABASE wordpress; etc. |
| Download WordPress | curl -O https://wordpress.org/latest.tar.gz |
| Site folder | /var/www/example.com owned by www-data |
| Nginx config | server block with a location ~ .php$ section |
| Installer | https://example.com in a browser |
1. Install PHP
sudo apt install php-fpm php-mysql php-xml php-gd php-curl php-mbstring php-zip php-intl -y
php -v shows the version (8.x). Note it — the Nginx config refers to it.
Raise the upload limit while you're here, in /etc/php/8.3/fpm/php.ini (adjust the version):
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
sudo systemctl restart php8.3-fpm
2. Create the database
sudo mysql
CREATE DATABASE wordpress;
CREATE USER 'wp'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'localhost';
FLUSH PRIVILEGES;
exit;
3. Download WordPress
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
4. Nginx
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
client_max_body_size 64M;
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; }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
5. Run the installer
Open http://example.com (or the server's IP if you've put it in your hosts file). Choose a language, then enter the database name, user and password from step 2, host localhost. Then your site title, admin username (not "admin") and a strong password.
Done. Log in at /wp-admin.
6. Add HTTPS
sudo certbot --nginx -d example.com -d www.example.com
Then in WordPress, Settings → General, change both URLs to https://.
Permalinks
Settings → Permalinks → Post name. The try_files line in the Nginx config is what makes pretty URLs work.
Troubleshooting
Downloads the PHP file instead of running it. The location ~ .php$ block isn't matching or PHP-FPM isn't running. sudo systemctl status php8.3-fpm, and check the socket path matches ls /run/php/.
"Error establishing a database connection." Wrong credentials, or the user was made as @'%' not @'localhost'. Test with mysql -u wp -p wordpress.
Can't install plugins / asked for FTP details. Ownership. sudo chown -R www-data:www-data /var/www/example.com.
Uploads fail with "exceeds the maximum". Raise it in all three places: php.ini, client_max_body_size in Nginx, and restart both.
White screen. Add define('WP_DEBUG', true); to wp-config.php to see the error, or check /var/log/nginx/error.log.
Wrapping up
PHP, a database, the WordPress files owned by www-data, an Nginx block with the PHP location, and the installer does the rest. Add Certbot and you have a properly hosted site for the price of the electricity.
