How to Self-Host WordPress on a VPS (Complete Guide)
Self-hosting WordPress on a VPS can give you full control over your server environment, better performance, and the flexibility to customize your applications. This guide will walk you through the necessary steps to install and configure WordPress on a VPS. We will cover the use of both traditional setups and Docker containers.
Choosing a VPS Provider
Before diving into the installation process, you need to select a VPS provider. Hereโs a quick comparison of popular VPS services for hosting WordPress:
| Provider | Monthly Price | CPU Cores | RAM | SSD Storage | Website |
|---|---|---|---|---|---|
| Contabo VPS | 5.99 EUR | 4 | 8GB | 200GB | Contabo |
| Hetzner Cloud | 4.15 EUR | 2 | 2GB | 20GB | Hetzner |
| DigitalOcean | 6 USD | 1 | 1GB | 25GB | DigitalOcean |
| Vultr | 6 USD | 1 | 1GB | 25GB | Vultr |
| Linode | 5 USD | 1 | 2GB | 25GB | Linode |
For detailed comparisons, visit our full VPS comparison.
Steps to Self-Host WordPress on a VPS
Step 1: Provision Your VPS
- Sign Up: Choose your provider and create an account.
- Select an Image: Choose a Linux distribution (Ubuntu 20.04 LTS is recommended).
- Choose Plan: Select the appropriate plan based on your traffic and storage needs.
- Access Your VPS: Once your server is provisioned, youโll receive an IP address and root access.
Step 2: Initial Setup
-
Connect to Your VPS:
ssh root@your_server_ip -
Update System:
apt update && apt upgrade -y
Step 3: Install Required Packages
Install LAMP Stack
You need to install Apache, MySQL, and PHP (LAMP) to run WordPress.
apt install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring -y
Secure MySQL
Run the MySQL secure installation script:
mysql_secure_installation
Step 4: Create a Database for WordPress
-
Access MySQL:
mysql -u root -p -
Execute the following commands:
CREATE DATABASE wordpress; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 5: Download and Configure WordPress
-
Download WordPress:
cd /var/www/html wget https://wordpress.org/latest.tar.gz tar xzvf latest.tar.gz mv wordpress/* ./ rm -rf wordpress latest.tar.gz -
Set Permissions:
chown -R www-data:www-data /var/www/html chmod -R 755 /var/www/html -
Create wp-config.php:
cp wp-config-sample.php wp-config.php nano wp-config.phpReplace
database_name_here,username_here, andpassword_herewith your database details.
Step 6: Finalize Apache Configuration
-
Create a New Virtual Host:
nano /etc/apache2/sites-available/wordpress.confAdd the following configuration:
<VirtualHost *:80> DocumentRoot /var/www/html ServerName your_domain.com <Directory /var/www/html> AllowOverride All </Directory> </VirtualHost> -
Enable the New Site and Rewrite Module:
a2ensite wordpress.conf a2enmod rewrite systemctl restart apache2
Step 7: Access WordPress
Open a web browser and navigate to http://your_server_ip or http://your_domain.com. You should see the WordPress installation screen.
Self-Hosting WordPress Using Docker
For those inclined to use containerization, you can also install WordPress via Docker. Hereโs how to do it.
-
Install Docker:
apt install docker.io docker-compose -y -
Create a
docker-compose.ymlfile:version: '3' services: db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: root_password MYSQL_DATABASE: wordpress MYSQL_USER: wp_user MYSQL_PASSWORD: user_password wordpress: image: wordpress restart: always ports: - "8000:80" environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wp_user WORDPRESS_DB_PASSWORD: user_password WORDPRESS_DB_NAME: wordpress -
Run the Docker Container:
docker-compose up -d
Access it via http://your_server_ip:8000.
FAQs
How can I secure my self-hosted WordPress site?
To secure your WordPress site, establish a strong password for the MySQL user and use HTTPS for your domain. Configure a firewall using UFW and regularly update WordPress to protect against vulnerabilities. Additionally, consider security plugins such as Wordfence or Sucuri for additional layer protection.
Is self-hosting WordPress on a VPS difficult?
Self-hosting WordPress on a VPS may seem daunting initially, especially if youโre unfamiliar with server management. However, with clear instructions and practice, it becomes manageable. Having command-line experience can significantly mitigate challenges. Docker can also simplify the setup process, as it abstracts many complexities.
What are the advantages of using a VPS for WordPress?
A VPS offers greater control over your environment compared to shared hosting. You can configure the server as per your needs, optimize performance, and ensure better uptime. Moreover, you can scale resources as your site grows, providing flexibility and enhanced security.
Self-hosting lets you dive into an exciting world of web development and offers the freedom to manage your applications.