How to Install WordPress on a VPS with LEMP Stack (Nginx, PHP 8.4, MariaDB)
To install WordPress VPS LEMP stack correctly, you need four parts working together: Nginx to serve pages, MariaDB to store content, PHP 8.4 to run WordPress, and a server block that ties them together. This guide walks through that full wordpress nginx php mariadb setup on Ubuntu 24.04, from a fresh server to a working site with HTTPS. It assumes you already have a VPS with root or sudo access and a domain pointed at the server IP.
If you are still sizing the server, check how much RAM a WordPress VPS needs before you start. A small blog runs fine on 1 to 2 GB of RAM, but WooCommerce or a busy site needs more headroom, especially once PHP-FPM and MariaDB both run on the same machine.
Before You Start: Server Prep and Security Basics
Update the system first, then lock down access. A fresh VPS with password login and an open firewall is an easy target, so do the basics before you install anything else. If you have not done this yet, follow the first 10 things to do after buying a VPS checklist, and set up UFW on Ubuntu Server 24.04 so only SSH, HTTP, and HTTPS stay open.
Run these commands:
- sudo apt update && sudo apt upgrade -y
- sudo ufw allow OpenSSH && sudo ufw allow ‘Nginx Full’ && sudo ufw enable
- sudo timedatectl set-timezone UTC (or your local timezone)
Point your domain DNS A record at the VPS IP and wait for it to resolve. You can check with dig +short yourdomain.com. If it still shows an old IP, do not continue to the SSL step yet, because certificate issuance will fail.
Install WordPress VPS LEMP Stack Step by Step
This is the core lemp stack ubuntu wordpress install. Install Nginx, MariaDB, and PHP 8.4 with the extensions WordPress needs:
- sudo apt install -y nginx mariadb-server
- sudo apt install -y php8.4-fpm php8.4-mysql php8.4-curl php8.4-gd php8.4-mbstring php8.4-xml php8.4-zip php8.4-intl php8.4-bcmath
- sudo systemctl enable –now nginx mariadb-server php8.4-fpm
On Ubuntu 24.04, PHP 8.4 may come from the default repos or the Ondrej PHP PPA depending on the image. If apt cannot find php8.4, add the PPA with sudo add-apt-repository ppa:ondrej/php, run sudo apt update, then retry the install. Do not mix PHP versions. If php8.3-fpm is also installed, disable it so only one PHP-FPM pool answers requests.
Secure MariaDB next:
- sudo mysql_secure_installation
- Answer yes to setting a root password, removing anonymous users, disallowing remote root login, and removing the test database.
Then create the WordPress database and user. Replace the placeholders with your own values:
- sudo mysql -u root -p
- CREATE DATABASE wpdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘a-long-random-password’;
- GRANT ALL PRIVILEGES ON wpdb.* TO ‘wpuser’@’localhost’; FLUSH PRIVILEGES; EXIT;
Download WordPress and Set File Permissions
Download the latest WordPress release into the web root, then set ownership so Nginx and PHP-FPM can read files without making everything world-writable:
- cd /var/www && sudo mkdir -p yourdomain.com && cd yourdomain.com
- sudo wget https://wordpress.org/latest.tar.gz && sudo tar -xzf latest.tar.gz && sudo mv wordpress/* . && sudo rmdir wordpress
- sudo chown -R www-data:www-data /var/www/yourdomain.com
- sudo find /var/www/yourdomain.com -type d -exec chmod 755 {} ; && sudo find /var/www/yourdomain.com -type f -exec chmod 644 {} ;
Copy wp-config-sample.php to wp-config.php and fill in the database name, user, and password you created. Generate fresh salts from the WordPress secret-key service and paste them in. Never reuse salts from a tutorial or another site. If you are moving an existing site instead of starting fresh, read how to migrate WordPress from shared hosting to a VPS first, because the database import and search-replace steps differ from a clean install.
Configure the Nginx Server Block
Create /etc/nginx/sites-available/yourdomain.com with a server block like this. Adjust the domain, root path, and PHP socket version to match your server:
server { listen 80; server_name yourdomain.com www.yourdomain.com; root /var/www/yourdomain.com; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.4-fpm.sock; } location ~ /.ht { deny all; } }
Enable the site and test the config:
- sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
- sudo nginx -t && sudo systemctl reload nginx
Visit the domain and finish the WordPress installer in the browser. Choose a strong admin password and an admin email you actually check, because password resets and update notices go there.
Add HTTPS with Certbot
Install Certbot and the Nginx plugin, then request a certificate:
- sudo apt install -y certbot python3-certbot-nginx
- sudo certbot –nginx -d yourdomain.com -d www.yourdomain.com
Certbot rewrites the Nginx block to redirect HTTP to HTTPS and sets up auto-renewal. Test renewal with sudo certbot renew –dry-run. If renewal fails, check that port 80 is open and that no other service is holding it.
Secure WordPress VPS Nginx: Common Pitfalls
A secure wordpress vps nginx setup needs a few fixes that beginners often skip. First, check PHP-FPM tuning. The default pm.max_children value can exhaust RAM on a small VPS under traffic, which shows up as 502 errors. Lower it on a 1 GB server, raise it only after you measure memory use. Second, turn on a page cache plugin or Nginx FastCGI cache once the site works, but test logged-in pages after you enable caching so admin pages never serve cached content to visitors.
Third, watch file uploads. If uploads fail, the cause is usually the PHP upload_max_filesize or post_max_size limit, not WordPress itself. Edit the PHP-FPM php.ini, restart php8.4-fpm, and retest. Fourth, keep backups separate from the server. A snapshot on the same VPS does not help if the provider account or disk fails. Copy backups offsite on a schedule.
Finally, update on a routine. Update WordPress core, themes, and plugins from the dashboard, and update the OS with apt on a regular schedule. Most hacked WordPress sites on VPS servers were not hacked through Nginx or MariaDB. They were hacked through an outdated plugin left untouched for months. Patch promptly, keep one backup before major updates, and test the site after each update.