This guide installs WordPress on Ubuntu 24.04, 22.04 or Debian 12 using Nginx, MariaDB and PHP-FPM. We use example.com as the domain; its A record should already point at your server.
1. Install the packages
sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zipFind the PHP-FPM socket name, because it includes the PHP version (8.3 on Ubuntu 24.04, 8.1 on 22.04, 8.2 on Debian 12):
ls /run/php/2. Secure MariaDB and create the database
sudo mariadb-secure-installationThen open the database shell with sudo mariadb and run, choosing your own strong password:
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;3. Download WordPress
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo cp -a wordpress/. /var/www/example.com/
sudo chown -R www-data:www-data /var/www/example.com4. Configure wp-config.php
cd /var/www/example.com
sudo -u www-data cp wp-config-sample.php wp-config.php
sudo -u www-data nano wp-config.phpSet DB_NAME, DB_USER and DB_PASSWORD to the values from step 2. Replace the block of put your unique phrase here keys with fresh ones from https://api.wordpress.org/secret-key/1.1/salt/.
5. Configure Nginx
Create /etc/nginx/sites-available/example.com. Change the socket in fastcgi_pass to match what ls /run/php/ showed:
server {
listen 80;
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 ~ /\.(?!well-known) {
deny all;
}
}Enable it and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx6. Add HTTPS, then run the installer
Get a certificate first, so your admin password is never sent over plain HTTP. Follow Secure Nginx with Let's Encrypt, then open https://example.com and complete the WordPress setup screens.
Tip: If you upload large media or themes, raise upload_max_filesize and post_max_size in /etc/php/<version>/fpm/php.ini to match client_max_body_size, then run sudo systemctl restart php8.3-fpm (use your version).
Troubleshooting
- 502 Bad Gateway: the
fastcgi_passsocket name is wrong or PHP-FPM is stopped. Compare it withls /run/php/and checksystemctl status php8.3-fpm. - "Error establishing a database connection": the database name, user or password in
wp-config.phpdoes not match step 2. - Permalinks give 404: the
try_filesline is missing fromlocation /. - WordPress asks for FTP details to install plugins: the files are not owned by
www-data. Re-run thechownfrom step 3.
