This article explains how to set up website hosting on a VPS. Hosting a website on a VPS gives you full control over your server environment, better performance, and scalability.
Follow these steps to get started:
Prerequisites:
- A VPS with a public IP address (Ubuntu/CentOS/other Linux distributions)
- Root or sudo access to the VPS
- A registered domain name (optional, but suggested)
- Basic knowledge of using the terminal
Step 1: Update Your Server
Log in to your VPS via SSH and update the package list:
- For Ubuntu/Debian:
sudo apt update && sudo apt upgrade -y
- For CentOS/RHEL:
sudo yum update -y
Step 2: Install a Web Server
- Option A: Apache:
sudo apt install apache2 -y # Ubuntu sudo systemctl enable apache2 sudo systemctl start apache2
- Option B: Nginx
sudo apt install nginx -y # Ubuntu sudo systemctl enable nginx sudo systemctl start nginx
Access your VPS IP in a browser (e.g., http://your-server-ip). You should see a default web server page.
Step 3: Upload Your Website Files
You can upload files using:
- SFTP (Secure File Transfer Protocol)
- scp command:
scp -r /local/website-folder user@your-vps-ip:/var/www/html
Replace existing index.html if using the default document root..
Step 4: Configure Your Domain (Optional)
Point your domain’s DNS A record to your VPS IP address.
Then configure a virtual host:
Apache Example:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Add:
<VirtualHost *:80> ServerName yourdomain.com DocumentRoot /var/www/html </VirtualHost>
Enable the site:
sudo a2ensite yourdomain.com.conf sudo systemctl reload apache2
Step 5: (Optional) Secure with SSL
Install Certbot and configure HTTPS:
For Apache:
sudo apt install certbot python3-certbot-apache -y sudo certbot --apache
For Nginx:
sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx
Your website is now live on your VPS. It offers greater control, flexibility, and performance than shared hosting, making it an ideal solution for growing websites and custom setups. We hope you found this guide helpful.
Find more information about: How to Transfer Backup from cPanel to VPS