WordPress GuideDevelopment → Install WordPress With Nginx

How to install WordPress with Nginx

Installing WordPress with Nginx gives you more control and performance than a standard Apache-based stack. Let’s walk through everything you need to get WordPress up and running with Nginx on Ubuntu.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What you need to know before you start

Nginx is a lightweight web server known for speed and scalability. When paired with WordPress, it can outperform traditional LAMP stacks, especially under load. You’ll be using a LEMP stack: Linux, Nginx (“Engine-X”), MySQL, and PHP.

Requirements

Step 1: Set up your server environment

Start by updating your system:

sudo apt update && sudo apt upgrade -y

Install essential tools:

sudo apt install curl wget unzip software-properties-common -y

Optional: set your timezone

sudo timedatectl set-timezone America/New_York

Step 2: Install the LEMP stack

Install Nginx

sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx

Install MySQL

sudo apt install mysql-server -y
sudo mysql_secure_installation

Create a WordPress database and user:

sudo mysql

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘strongpassword’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;

Install PHP and extensions

sudo apt install php-fpm php-mysql php-xml php-gd php-curl php-mbstring php-zip -y
php -v

Optional but recommended:

sudo apt install php-opcache php-redis redis-server -y

Step 3: Download and configure WordPress

Download WordPress

cd /tmp
wget https://wordpress.org/latest.zip
unzip latest.zip
sudo mv wordpress /var/www/yourdomain.com

Set permissions

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 {} \;

Create wp-config.php

cd /var/www/yourdomain.com
cp wp-config-sample.php wp-config.php

Edit with your database details:

define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wpuser’);
define(‘DB_PASSWORD’, ‘strongpassword’);
define(‘DB_HOST’, ‘localhost’);

Add salts from https://api.wordpress.org/secret-key/1.1/salt/

Step 4: Configure Nginx for WordPress

Create a server block

sudo nano /etc/nginx/sites-available/yourdomain.com

Paste:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }

    client_max_body_size 100M;
}

Enable the config:

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Enable HTTPS with Let’s Encrypt

sudo apt install certbot python3-certbot-nginx -y
sudo certbot –nginx -d yourdomain.com -d www.yourdomain.com

Step 5: Finalize and test the installation

Restart all services

sudo systemctl restart nginx php8.1-fpm mysql

Visit your domain

Open http://yourdomain.com in your browser and complete the WordPress setup wizard.

Optional configurations for performance and security

Enable OPcache

Edit /etc/php/8.1/fpm/php.ini:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.validate_timestamps=1
opcache.revalidate_freq=2

Restart PHP-FPM:

sudo systemctl restart php8.1-fpm

Enable Redis caching

Install plugin like Redis Object Cache and add this to wp-config.php:

define(‘WP_REDIS_HOST’, ‘127.0.0.1’);
define(‘WP_CACHE’, true);

Harden WordPress and Nginx

Troubleshooting common issues

File permissions

Use chown and chmod to fix permission-related errors

Permalinks not working

Double check try_files line in Nginx config

SSL issues

Run certbot renew –dry-run to test renewals. Use crontab for auto-renewal if needed.

Ready to get started?

Get the fastest, most secure WordPress.org hosting on the market.

Additional resources

What is managed WordPress hosting? →

Get details and decide if managed WordPress hosting is right for you.

WordPress template hierarchy explained for new developers →

Learn how WordPress template hierarchy determines which theme file is used to display content on your site.











A complete guide to WordPress shortcodes →

Shortcodes make life easier. Learn how to get started!

Trust us to help you choose the ideal hosting solution

Loading form…