TECHNICAL GUIDE

Use this guide as an implementation reference. Validate commands, policies and version-specific behaviour in a lab before applying changes to production systems.

1. Prepare Ubuntu and DNS

Use a clean Ubuntu 24.04 LTS server, a sudo account and a domain such as www.example.com pointing to the server. Decide whether Nginx will be the only web server on this host; do not run Apache and Nginx on the same public ports unless intentionally configured as a reverse proxy.

sudo apt update && sudo apt full-upgrade -y\nsudo apt install -y nginx mysql-server curl wget unzip ufw\nsudo systemctl enable --now nginx mysql

2. Install PHP-FPM and WordPress extensions

sudo apt install -y php-fpm php-mysql php-curl php-gd \\\n  php-mbstring php-xml php-xmlrpc php-soap php-intl \\\n  php-zip php-imagick php-bcmath php-cli php-opcache

Confirm the PHP version and extensions required by the WordPress release and plugins you intend to use. Set PHP memory, upload and execution limits based on the site workload.

3. Secure MySQL and create a database

sudo mysql_secure_installation\nsudo mysql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';\nGRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;

Use a unique database password and a dedicated account. Keep MySQL bound to localhost unless a separate secured database tier is planned.

4. Download and set up WordPress files

Download the current stable WordPress archive from wordpress.org and verify it before extraction.

cd /tmp\nwget https://wordpress.org/latest.tar.gz\ntar -xzf latest.tar.gz\nsudo mkdir -p /var/www/example.com\nsudo rsync -a wordpress/ /var/www/example.com/\nsudo chown -R www-data:www-data /var/www/example.com\nsudo find /var/www/example.com -type d -exec chmod 755 {} \\;\nsudo find /var/www/example.com -type f -exec chmod 644 {} \\;

Keep deployment files owned by the web server only where needed. For stricter deployments, use a controlled deployment account and restrict write access to uploads and update paths.

5. Create wp-config.php

cd /var/www/example.com\nsudo cp wp-config-sample.php wp-config.php\nsudo nano wp-config.php

Set the database name, user, password and host. Generate unique authentication keys and salts using the official WordPress secret-key service. Do not reuse the sample keys or commit wp-config.php to a public repository.

6. Configure Nginx

sudo nano /etc/nginx/sites-available/example.com
server {\n  listen 80;\n  server_name example.com www.example.com;\n  root /var/www/example.com;\n  index index.php index.html;\n  client_max_body_size 64m;\n  location / {\n    try_files $uri $uri/ /index.php?$args;\n  }\n  location ~ \\.php$ {\n    include snippets/fastcgi-php.conf;\n    fastcgi_pass unix:/run/php/php8.3-fpm.sock;\n  }\n  location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|webp)$ {\n    expires 30d;\n    log_not_found off;\n  }\n  location ~ /\\. { deny all; }\n}

Change the PHP-FPM socket to the actual installed version. Enable the site and test Nginx:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/\nsudo nginx -t\nsudo systemctl reload nginx

7. Complete the browser installation and HTTPS

Open the domain and follow the WordPress setup wizard. Select the site title, create a unique administrator username (not admin), set a strong password and provide a monitored email address.

After DNS is working, install Certbot for Nginx and enable HTTPS:

sudo apt install -y certbot python3-certbot-nginx\nsudo certbot --nginx -d example.com -d www.example.com\nsudo nginx -t\nsudo systemctl reload nginx

Set the WordPress and Site Address URLs to HTTPS in the admin settings and verify redirects.

8. Secure WordPress

  • Keep WordPress core, themes and plugins updated; remove unused extensions.
  • Use MFA for administrator accounts and least-privilege roles for editors/authors.
  • Disable theme/plugin editor access in production using DISALLOW_FILE_EDIT.
  • Restrict SSH and database access; use SFTP rather than plain FTP.
  • Apply a web application firewall or suitable edge protection.
  • Use strong backups and test restoration, including database and uploads.
  • Monitor PHP/Nginx logs, failed logins, disk space and certificate renewal.

9. Backups, caching and performance

Schedule database dumps and file-level backups. Use a cache plugin or server-side cache compatible with your theme and application, but test logged-in, checkout and dynamic pages carefully. Enable PHP OPcache, configure image optimisation and CDN only after validating caching behaviour. Store at least one backup off the server.

Official references

Conclusion

A production WordPress site needs a clean Nginx/PHP-FPM setup, isolated database credentials, HTTPS, least-privilege access and reliable off-server backups. Keep plugins minimal and test updates before applying them to a live site.

Found this useful?