How to Install WordPress on a VPS? Print

  • 0

WordPress is a popular content management system for building websites. This guide explains how to install WordPress on a Linux VPS with Nginx, MySQL, and PHP, incorporating VPS.DO elements for context.

Prerequisites

  • A VPS with root access (e.g., VPS.DO’s 1H2G plan with Ubuntu 20.04/22.04).
  • A domain name pointed to your VPS IP.
  • Basic SSH and server administration knowledge.

Step-by-Step Installation

1. Connect to Your VPS

Access your VPS via SSH using credentials from VPS.DO’s SolusVM control panel:

ssh root@your_vps_ip

2. Update System and Install Dependencies

Update the system and install Nginx, MySQL, and PHP:

sudo apt update && sudo apt upgrade -y
sudo apt install nginx mysql-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip -y

3. Configure MySQL

Secure MySQL and create a WordPress database:

sudo mysql_secure_installation

Log in to MySQL:

sudo mysql -u root -p

Create a database and user:

CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4. Download and Configure WordPress

Download the latest WordPress version:

cd /var/www
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo mv wordpress yourdomain.com
sudo chown -R www-data:www-data /var/www/yourdomain.com

Configure WordPress:

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

Update database settings:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'secure_password');
define('DB_HOST', 'localhost');

5. Configure Nginx

Create an Nginx configuration file:

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

Add:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com;
    index index.php index.html;
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Enable the site and restart Nginx:

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

6. Install SSL (Optional but Recommended)

Secure your site with a Let’s Encrypt SSL certificate:

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

Follow prompts to configure HTTPS.

7. Complete WordPress Setup

Visit http://yourdomain.com (or https://yourdomain.com if SSL is enabled) in a browser. Follow the WordPress setup wizard to configure your site, admin user, and password.

8. Secure and Monitor

  • Firewall: Allow HTTP/HTTPS:
    sudo ufw allow 80,443/tcp
    sudo ufw enable
    
  • Monitor Resources: Use VPS.DO’s SolusVM panel to track CPU, RAM, and disk usage to ensure WordPress runs smoothly.
  • Backups: Schedule regular backups of /var/www/yourdomain.com and the MySQL database.

Installing WordPress on a VPS with Nginx, MySQL, and PHP is straightforward and enables a fast, customizable website. VPS.DO’s NVMe SSDs and full root access ensure optimal performance. Secure your site with SSL and monitor resources for reliability.


Was this answer helpful?

« Back