Tutorial: How to Self-Host WordPress or WooCommerce on Your VPS
For businesses and bloggers alike, hosting WordPress or WooCommerce on a Virtual Private Server (VPS) provides superior control, flexibility, and performance over shared hosting. In this guide, we’ll walk you through the steps to self-host WordPress or WooCommerce on your VPS, from setting up your server to installing and securing your site.
For tailored VPS solutions, visit our Virtual Server Plans page, offering both CT (LXC) and VM (KVM) options.
Why Self-Host WordPress or WooCommerce on a VPS?
- Enhanced Control: A VPS lets you control server resources, access, and security settings for optimized performance.
- Scalability: VPS plans can scale with your site’s growth, making them ideal for high-traffic sites and WooCommerce stores.
- Cost-Effective for Growing Sites: Self-hosting on a VPS often offers better cost-performance value than premium shared hosting options.
Prerequisites
- A VPS Server: A Linux-based VPS with SSH access.
- Basic Command-Line Knowledge: Familiarity with basic server commands will help throughout the process.
- Domain Name: Ensure your domain is pointing to your VPS IP.
Step 1: Update Your VPS Server
Start by updating your server to ensure all packages are current:
sudo apt update && sudo apt upgrade -y # For Debian/Ubuntu
sudo yum update -y # For CentOS/RHEL
Step 2: Install the LAMP/LEMP Stack
To run WordPress or WooCommerce, you’ll need a web server, PHP, and a MySQL or MariaDB database.
For Apache (LAMP Stack):
# Install Apache, MySQL, and PHP
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php -y
For Nginx (LEMP Stack):
# Install Nginx, MySQL, and PHP
sudo apt install nginx mysql-server php php-fpm php-mysql -y
Verify the installation by checking the web server status:
sudo systemctl status apache2 # For Apache
sudo systemctl status nginx # For Nginx
Step 3: Configure MySQL Database for WordPress
Set up a MySQL database and user for WordPress or WooCommerce:
sudo mysql -u root -p
Inside the MySQL prompt, run the following commands:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 4: Install and Configure PHP
Install additional PHP extensions for WordPress or WooCommerce compatibility:
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc -y
After installation, restart Apache or Nginx to apply PHP settings:
sudo systemctl restart apache2 # For Apache
sudo systemctl restart nginx # For Nginx
Step 5: Download and Install WordPress
Download the latest version of WordPress:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
Move WordPress files to the web directory:
sudo mv wordpress /var/www/html/wordpress # Adjust path for Nginx if needed
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Step 6: Configure WordPress
In the WordPress directory, rename the sample configuration file and edit it with your database details:
cd /var/www/html/wordpress
cp wp-config-sample.php wp-config.php
nano wp-config.php
Update the following lines with your database name, username, and password:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'password');
Step 7: Set Up Apache or Nginx for WordPress
For Apache:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the configuration and rewrite module, then restart Apache:
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl restart apache2
For Nginx:
sudo nano /etc/nginx/sites-available/wordpress
Add the following:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Step 8: Complete WordPress Installation
Visit your domain (e.g., http://example.com) to finalize the installation. Enter site details like title, admin username, and password to complete the setup.
Benefits of Hosting WordPress or WooCommerce on VPS
- Improved Performance: VPS offers dedicated resources for smoother operations.
- Customizable Settings: Full control over server configurations, allowing for better optimization.
- Scalability: Easily scale resources as your site grows.
Self-hosting WordPress or WooCommerce on a VPS grants greater control over resources, security, and customization. By following this guide, you’ll have a robust platform for your website or eCommerce store. Explore our Virtual Server Plans for reliable VPS options tailored to your needs.