Installing WordPress on VPS

You can set up WordPress using your server’s public IP address now and bind your actual domain name later when you are ready.

Here is the complete step-by-step guide to installing WordPress on Nginx + PHP-FPM using your IP address.

Step 1: Install Nginx & PHP-FPM

Run the following commands in your VS Code terminal to install Nginx and the necessary PHP extensions:

Bash

sudo apt update
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y
php -m | grep -E 'mysqli|curl|gd|mbstring|xml|zip'


This will install and verify all packages required

Check your PHP version to confirm the socket file name:

Bash

ls /run/php/

(You will see a socket file like php8.1-fpm.sock or php8.3-fpm.sock—keep note of the version number).

Step 2: Create the WordPress Database

Since MySQL is already installed on your server, log into MySQL:

Bash

sudo mysql -u root -p

Execute these commands to create a dedicated database and 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;

Step 3: Download & Extract WordPress

Download the latest release into /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 permissions so Nginx/PHP can write media uploads & plugins
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress

Step 4: Configure Nginx to Use Your Server IP

  1. Remove the default Nginx placeholder site:Bashsudo rm /etc/nginx/sites-enabled/default
  2. Create a new Nginx configuration file:Bashsudo nano /etc/nginx/sites-available/wordpress
  3. Paste the following configuration (replace YOUR_SERVER_IP with your actual VPS IP address and adjust the PHP version socket if necessary):

Nginx

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

    server_name YOUR_SERVER_IP; # e.g., 192.0.2.1

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

    # Enable WordPress Permalinks
    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; # Adjust version if needed (e.g. php8.3-fpm.sock)
    }

    # Deny access to hidden files (.htaccess, .git, etc.)
    location ~ /\.ht {
        deny all;
    }

    # Cache static assets
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }
}
  1. Enable the file and test for syntax errors:Bashsudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx

Step 5: Complete WordPress Installation in Your Browser

  1. Open your browser and navigate to:Plaintexthttp://YOUR_SERVER_IP
  2. You will see the WordPress Setup Wizard. Click Let’s go!
  3. Enter your database details:
    • Database Name: wordpress_db
    • Username: wp_user
    • Password: YourStrongWPPassword123!
    • Database Host: localhost
    • Table Prefix: wp_
  4. Complete the site admin setup!

How to Switch to a Domain Later

When you acquire your domain and point your A Record to your server IP, updating WordPress takes less than 2 minutes:

  1. Update Nginx: Open /etc/nginx/sites-available/wordpress, replace YOUR_SERVER_IP in server_name with yourdomain.com [www.yourdomain.com](https://www.yourdomain.com), and reload Nginx (sudo systemctl reload nginx).
  2. Update WordPress URLs: Go to WordPress Admin > Settings > General, and change both WordPress Address (URL) and Site Address (URL) from http://YOUR_SERVER_IP to [http://yourdomain.com](http://yourdomain.com).
  3. Add Free SSL: Generate an HTTPS certificate via Certbot:Bashsudo certbot --nginx -d yourdomain.com -d www.yourdomain.com