WordPress on Nginx
Step by Step, Ubuntu 24.04.
Copy-paste commands that take a fresh Ubuntu 24.04 cloud server to a WordPress site on Nginx, PHP-FPM and MariaDB, with HTTPS. Then what you give up without .htaccess.
Published October 27, 2026 · Last updated October 27, 2026
Before you start
This is for someone leaving shared cPanel hosting for a server of their own who wants Nginx as the web server. You need a fresh Ubuntu 24.04 server, a root shell on it, and a domain whose A record already points at the server's IP address (Let's Encrypt checks that in step 6). Every command runs as root. Replace example.com with your domain and ChangeMe_Strong#Pass with a password of your own.
1. Update the server and install the stack
apt update && apt upgrade -y
apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-xml php-mbstring php-zip php-intlOn Ubuntu 24.04, php-fpm installs php8.3-fpm, and Ubuntu ships nginx 1.24 and MariaDB 10.11. WordPress's requirements page recommends PHP 8.3 or newer and MariaDB 10.11 or newer, so the stock packages meet both. Everything comes from Ubuntu's own archive, with no extra repository to add.
2. Turn on the firewall
ufw allow OpenSSH
ufw allow 80,443/tcp
ufw enableKeep the first line. Without ufw allow OpenSSH, turning the firewall on closes the SSH port you are working through.
3. Secure MariaDB and create the database
mysql_secure_installationAnswer Y to removing anonymous users, disallowing remote root login, and dropping the test database. Then open the database shell and create one database and one user for WordPress:
mariadb
CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'ChangeMe_Strong#Pass';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;Why all privileges, on one database? The user can reach only wordpress, nothing else on the server. Inside it, WordPress's hardening guide advises against taking away the schema rights, because updates that change tables would fail.
4. Download WordPress
cd /var/www
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mkdir -p /var/www/wordpress/wp-content/uploads
chown -R www-data:www-data /var/www/wordpressNginx and PHP-FPM both run as www-data on Ubuntu, so WordPress can write its own config, uploads and updates.
5. Write the server block
Open a new file for the site:
nano /etc/nginx/sites-available/wordpressPaste this in, change both names on the server_name line, and save:
server {
listen 80;
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 ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}Three lines do the work. try_files ... /index.php?$args sends every address that isn't a real file to WordPress, which is what makes pretty permalinks work. The uploads block refuses to run any PHP file someone manages to upload. try_files $uri =404 passes a PHP request on only if that script exists. Then switch the site on, test, and reload:
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t && systemctl reload nginxRun nginx -t before every reload. It checks the syntax and opens every file the config names, so a typo stops there instead of taking the site down. If it complains about the socket, ls /run/php/ shows the name your PHP version uses.
6. HTTPS with Let's Encrypt
apt install -y python3-certbot-nginx
certbot --nginx -d example.com -d www.example.com
certbot renew --dry-runCertbot's Nginx plugin gets a free Let's Encrypt certificate and adds the HTTPS lines to your server block for you. The dry run rehearses a renewal with test certificates and saves nothing. Renewal should already be scheduled; systemctl list-timers is where to check.
7. Run the WordPress installer, straight away
Open https://example.com and give the installer the database details from step 3:
Database Name wordpress
Username wp_user
Password ChangeMe_Strong#Pass
Database Host localhost
Table Prefix wp_Don't stop between step 6 and this one. Until the installer is finished, whoever reaches the site first can complete it and own it. Create your admin account with a strong, unique password.
8. Prove PHP can't run from uploads
echo '<?php echo "ran";' > /var/www/wordpress/wp-content/uploads/test.php
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/wp-content/uploads/test.php
rm /var/www/wordpress/wp-content/uploads/test.phpYou want 403. Anything else means the uploads block in step 5 isn't matching; fix it before you add plugins. WordPress's own Nginx page recommends this test, because a typo in that rule can leave a loophole.
The trade-offs, honestly
- There is no .htaccess. In WordPress's words, Nginx has "no directory-level configuration file like Apache's .htaccess". Permalinks already work through the
try_filesline, but a plugin that tells you to paste rules into .htaccess (caching, redirects, security) needs those rules rewritten for the server block, thennginx -tand a reload. - Every change is a root change. On shared cPanel hosting a setting was a form. Here it is a file you edit and a service you reload. That is the control you came for, and the work that comes with it.
- Updates come from one place. Nginx, PHP and MariaDB all come from Ubuntu's archive in this setup, so
aptupdates them and there is no outside repository to track. WordPress, its plugins and themes still update from its own dashboard. - A panel may suit you better. If editing a server block is not how you want to spend an afternoon, a cloud server here can run Enhance instead: our Enhance guide shows what moves across from cPanel. Mail, backups and cron on a server with no panel are mapped in our no-panel guide.
One question
Why Nginx, and not OpenLiteSpeed?
Both run WordPress well. Pick Nginx if you already know it, or if the plugins and tools you rely on publish Nginx rules. If you would rather have a browser console for the web server, our OpenLiteSpeed guide builds the same site on that.
Where to go next
We're Ace-Host: family-held and debt-free since 2003, based in Southfield, Michigan, running our own network (AS22878) on our own hardware. A cloud server here can run with no panel at all, as in this guide, or with cPanel, Enhance, Webuzo or DirectAdmin.
Sources
- WordPress, Requirements; Nginx (server rules, the uploads rule and its test, no .htaccess); Hardening WordPress (database privileges); Server environment (PHP extensions). Fetched October 27, 2026.
- nginx, Command-line parameters (
-t). Fetched October 27, 2026. - Certbot, User Guide (Nginx plugin,
renew --dry-run, scheduled renewal). Fetched October 27, 2026. - Ubuntu, noble-updates package pages (nginx, php8.3-fpm, mariadb-server; fetched October 15, 2026), php-defaults (the php-* packages; fetched October 27, 2026) and the release cycle (24.04 LTS standard support to May 2029; fetched October 15, 2026).
A Cloud Server for Your Nginx Build.
Every cloud server comes with full root and can run with no panel, as in this guide, or with cPanel, Enhance, Webuzo or DirectAdmin. A system administrator will talk it through with you before you commit to anything.
Rather ask first? Start a conversation. Cancelling a cloud server is one click in your client area, any time, with no notice period and no ticket to open. That is written into the user agreement.