Installing WordPress on VPS

Adding WordPress alongside your Node.js apps on the same VPS is completely straightforward, especially since you already have Nginx handling reverse proxy duties. Nginx will cleanly route domain requests: sending your Node.js traffic to its respective internal ports and serving WordPress directly via PHP-FPM.

Here is the cleanest way to set up WordPress alongside Node.js.

1. Install PHP & MySQL (If not already present)

WordPress requires PHP and a MySQL database to function.

A. Install PHP-FPM and Required Modules

Run this on your server:

Bash

sudo apt update
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip -y

Check your installed PHP version (e.g., PHP 8.1 or 8.3) to confirm the socket path:

Bash

systemctl status php*-fpm

(Take note of the PHP version, e.g., php8.1-fpm or php8.3-fpm)

B. Create a WordPress Database & User in MySQL

Log into MySQL as root or an admin user:

Bash

sudo mysql -u root -p

Run the following SQL statements to create the database and dedicated user:

SQL

CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'YourStrongWPPassword123!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

2. Download WordPress

Place WordPress files in /var/www/wordpress:

Bash

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

# Set correct permissions so Nginx/PHP can write to wp-content (plugins/themes)
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress

3. Configure Nginx for WordPress

Create a new server block configuration for your WordPress domain/subdomain (e.g., blog.yourdomain.com or yourdomain.com).

Bash

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

Paste the following configuration (adjust server_name and PHP version if needed):

Nginx

server {
    listen 80;
    server_name blog.yourdomain.com; # Or your main domain

    root /var/www/wordpress;
    index index.php index.html index.htm;

    # Universal WordPress Permalinks support
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Pass PHP scripts to PHP-FPM
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Ensure this matches your installed PHP version
    }

    # Deny access to sensitive hidden files
    location ~ /\.ht {
        deny all;
    }

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

Enable the configuration and reload Nginx:

Bash

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t  # Tests for syntax errors
sudo systemctl reload nginx

4. Secure WordPress with SSL

Generate a free SSL certificate using Certbot:

Bash

sudo certbot --nginx -d blog.yourdomain.com

5. Complete Setup via Browser

Navigate to [https://blog.yourdomain.com](https://blog.yourdomain.com) in your browser. You will see the standard WordPress setup screen:

  • Database Name: wordpress_db
  • Username: wp_user
  • Password: YourStrongWPPassword123!
  • Database Host: localhost
  • Table Prefix: wp_ (or change for added security, e.g., wp_alphanetix_)

How This Integrates with Your System

Because Nginx manages all incoming web traffic on ports 80 and 443:

Request DomainNginx ActionTarget Engine
api.yourdomain.comproxy_pass http://localhost:3000Node.js (PM2)
blog.yourdomain.comDirect file service + FastCGIPHP-FPM / WordPress

Both systems operate independently without performance bottlenecks or port conflicts!