How to Install and Use WordPress on Ubuntu with Nginx

WordPress runs efficiently on Ubuntu when its web, database, and PHP components are configured as a coordinated stack. Nginx handles incoming requests, PHP-FPM processes dynamic pages, and MySQL or MariaDB stores posts, user accounts, settings, and media information. This setup is a practical alternative to Apache for a personal blog, business site, or small online publication.

The instructions below suit a fresh Ubuntu 22.04 or 24.04 server with a regular sudo user and a domain name pointed at the server’s public IP address. The commands work well on an NBN-connected home lab or a cloud instance in Sydney or Melbourne, although a production site should use a reputable Australian or international data centre with reliable backups and support.

Prepare Ubuntu and install the web stack

Connect to the server over SSH, then update the package index and install Nginx, MySQL, PHP-FPM, and the PHP extensions required by WordPress:

sudo apt update
sudo apt upgrade -y
sudo apt install -y nginx mysql-server php-fpm php-mysql php-curl php-gd \
  php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip unzip

Ubuntu starts Nginx and usually starts MySQL automatically after installation. Check the services before continuing:

sudo systemctl enable --now nginx
sudo systemctl enable --now mysql
sudo systemctl status nginx
sudo systemctl status mysql

If the server will be managed remotely, enable the uncomplicated firewall while allowing SSH and web traffic:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

On a home connection, confirm that your router forwards TCP ports 80 and 443 to the Ubuntu machine. Many Australian ISPs use carrier-grade NAT or block inbound connections on some plans, so a low-cost VPS may be simpler for a public website. Keep the server’s timezone accurate as well, particularly if scheduled WordPress posts need to match Australian Eastern, Central, or Western time.

Create the WordPress database

Secure the initial MySQL installation with the built-in script:

sudo mysql_secure_installation

The prompts vary slightly between Ubuntu releases. Remove anonymous users, disable remote root login, remove the test database, and reload the privilege tables. A WordPress site should have its own database and a separate database user rather than using the MySQL root account.

Open the MySQL console:

sudo mysql

Create a database, user, and strong password. Replace the example password with a long, unique value generated by a password manager:

CREATE DATABASE wordpress
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

CREATE USER 'wpuser'@'localhost'
  IDENTIFIED BY 'replace-with-a-long-random-password';

GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The utf8mb4 character set supports Australian English punctuation, accented names, and emoji used in social content. Store the database credentials securely because they will be added to wp-config.php. Never publish that file, place it inside a backup shared publicly, or reuse its password for SSH, email, or a hosting account.

Download WordPress and configure permissions

Move to a temporary directory and download the current WordPress package from the official project:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/wordpress

Give Nginx’s web user ownership of the application files, then apply conservative permissions:

sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

Create the configuration file from the supplied sample and edit it:

cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update the database section so it matches the database created earlier:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'replace-with-a-long-random-password' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );

WordPress also uses authentication salts to protect logged-in sessions. Replace the existing placeholder salt definitions with fresh values from the official WordPress salt service. If you are deploying several sites, generate different salts for each installation. This small step limits the damage caused by a copied or exposed configuration file.

Configure Nginx for the domain

Create an Nginx server block for the domain. Replace example.com and www.example.com with your real hostnames:

sudo nano /etc/nginx/sites-available/wordpress

Use this configuration:

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    root /var/www/wordpress;
    index index.php index.html;

    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 ~ /\.ht {
        deny all;
    }
}

The PHP-FPM socket can differ by Ubuntu release. Check the available socket if Nginx reports that the upstream cannot be found:

ls /run/php/

Change php8.3-fpm.sock to the installed version, such as php8.1-fpm.sock. Enable the site and remove the default server block if it is no longer needed:

sudo ln -s /etc/nginx/sites-available/wordpress \
  /etc/nginx/sites-enabled/wordpress

sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

Before opening the installer, make sure the domain’s DNS A record points to the server. For a site serving Brisbane, Perth, or Adelaide readers, DNS propagation may appear inconsistent for a few hours because different providers cache records for different periods. Test both the bare domain and the www version after propagation.

Finish the browser installation and harden access

Visit http://example.com in a browser. Select Australian English if appropriate, then enter the site title, administrator username, a unique password, and an email address. Avoid using “admin” as the administrator name. A local address such as a @businessname.com.au mailbox is preferable to an account that might be lost when an ISP email service changes.

After the installer completes, sign in at /wp-admin. Set the site address under Settings and Permalinks, then choose “Post name” for readable URLs. Review the timezone setting carefully: Sydney and Melbourne switch between AEDT and AEST, while Brisbane remains on AEST and Perth uses AWST. WordPress can schedule posts according to the selected city.

Enable HTTPS with Let’s Encrypt:

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

Choose the option to redirect HTTP traffic to HTTPS. Certbot installs a renewal timer, which can be checked with:

sudo systemctl status certbot.timer
sudo certbot renew --dry-run

HTTPS protects administrator logins and helps browsers trust the site. It also avoids mixed-content warnings when images or scripts are loaded from secure pages. Review the generated Nginx configuration after renewal, and keep ports 80 and 443 open so certificate renewal can complete.

Manage WordPress safely on Ubuntu

The WordPress dashboard is suitable for installing themes, plugins, and media, but keep extensions to a minimum. Every plugin adds PHP code and may introduce compatibility, performance, or security issues. Download plugins from the WordPress directory or a vendor with a clear update history, and remove inactive extensions rather than leaving them installed.

Use the dashboard for routine updates, then check the site’s front page, contact forms, menus, and responsive layout. If you prefer command-line administration, install WP-CLI:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Run WordPress commands as the web user from the installation directory:

cd /var/www/wordpress
sudo -u www-data wp core update
sudo -u www-data wp plugin list
sudo -u www-data wp theme list

Create backups of both /var/www/wordpress and the database. A basic database export looks like this:

sudo mysqldump -u wpuser -p wordpress > ~/wordpress-$(date +%F).sql

Copy that file and the WordPress directory to storage separate from the server. An external encrypted drive, an object-storage bucket, or a backup service with Australian data residency can work well. A backup kept only on the same VPS will not help after disk failure, accidental deletion, or a compromised account. For additional deployment references, a Linux hosting guide can provide broader background when comparing server arrangements.

Improve speed and troubleshoot common faults

Nginx serves static files quickly, but WordPress still executes PHP for many page requests. A caching plugin can generate static page copies, while PHP OPcache reduces the cost of repeatedly compiling PHP scripts. Install it with:

sudo apt install -y php-opcache
sudo systemctl restart php8.3-fpm

Use the PHP-FPM version installed on your server if it is different. A small site may run comfortably with modest resources, but image-heavy publications and WooCommerce shops need more memory, CPU, and storage. Compress uploaded images, use modern WebP or AVIF files where suitable, and avoid uploading a full camera image for a small thumbnail.

When a page shows “502 Bad Gateway”, inspect PHP-FPM and Nginx logs first:

sudo journalctl -u php8.3-fpm --since "15 minutes ago"
sudo tail -f /var/log/nginx/error.log

A 502 usually means the PHP-FPM service is stopped, the socket path is wrong, or the server has run out of memory. A “403 Forbidden” error commonly points to incorrect ownership or permissions. A broken permalink page often means the try_files rule is missing or the WordPress URL settings do not match the domain.

Keep Ubuntu patched with regular updates and restrict SSH access with keys rather than passwords. Monitor disk space because logs, backups, and uploaded media can silently fill a small server. Once the domain resolves, HTTPS works, and the first backup has been tested, the Ubuntu Nginx WordPress site is ready for publishing: run one final update with sudo apt update && sudo apt upgrade -y, then create and verify a test post.