Moving from shared hosting to your own VPS with Nginx is a huge leap in speed and control. It is also the moment where many people get stuck: terminal, packages, configuration… But the process, properly ordered, is perfectly manageable. Here is the complete path to get WordPress running on Nginx on your own server.
Nginx is fast and lightweight, ideal for WordPress. The trick is not magic: it is following the steps in order and not skipping security.
What you are going to build: a LEMP stack
LEMP is Linux, Nginx (the E comes from its pronunciation, "engine-x"), a MariaDB or MySQL database and PHP. It is the base on which WordPress will run. We will work on a freshly installed Ubuntu with SSH access.
1. Install Nginx, the database and PHP
# Update the system and install the stack
sudo apt update && sudo apt upgrade -y
sudo apt install nginx mariadb-server php-fpm php-mysql -y2. Create the database
First secure MariaDB with sudo mysql_secure_installation. Then log in with sudo mysql and create a dedicated database and user for WordPress (never use the root user): a CREATE DATABASE wordpress;, a CREATE USER with a strong password and a GRANT of permissions on that database. Note down those credentials: WordPress will ask for them.
3. Download and place WordPress
Download the latest version of WordPress, unpack it into /var/www/mydomain and adjust the permissions so Nginx (user www-data) can read it. Copy wp-config-sample.php to wp-config.php and fill in the database name, user and password you created in the previous step.
4. Configure the Nginx server block
Create a file in /etc/nginx/sites-available/ with the site configuration, enable it with a symbolic link to sites-enabled and reload Nginx. The essentials look like this:
server {
listen 80;
server_name mydomain.com;
root /var/www/mydomain;
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/php-fpm.sock;
}
}5. Enable HTTPS and finish the installation
Point your domain to the server, issue the SSL certificate with Certbot and open https://mydomain.com: the WordPress installer will greet you to create the administrator user. Before opening it to the public, get the firewall, SSL and backups ready; I explained it in another performance guide and it is worth combining with good server maintenance.
Common mistakes
- Wrong permissions: WordPress cannot write and updates or uploads fail.
- Forgetting the PHP block in Nginx: the browser downloads index.php instead of running it.
- Not configuring permalinks and getting 404 errors on posts.
- Leaving the site on HTTP: enable HTTPS from the start.
Rehearse it twice
The first time, deploy on a test VPS and write down every command in a file. The second, do it on the real server following only those notes. With that method, what took an afternoon becomes an hour, and the notes turn into your documentation.
Before calling the site done, go through a short list: sudo nginx -t before every reload, WordPress permalinks working, a test image upload, a plugin update that writes to disk and HTTPS with a redirect from HTTP. Each point covers one of the most common mistakes in this guide.
Order matters too: database, files, Nginx and HTTPS. Problems almost always come from wanting to go fast and leaving permissions or security for later.
Want to migrate to a VPS but the terminal intimidates you? At Codegea we deploy and configure WordPress on Nginx, with SSL, backups and everything tuned, and leave it ready to work. Tell me your case.
Written by
Derian Pinto
Founder & Full Stack Developer
Founder of Codegea. Builds custom websites, stores and platforms, and integrates and supports Arc XP for media companies.
