Home Cloud Serevrs Set Up and Host a Website on a Linux VPS Using Apache

Set Up and Host a Website on a Linux VPS Using Apache

Last updated on Feb 13, 2025

Hosting a website on a Linux VPS gives you full control over your server, security, and performance. This guide will walk you through installing, configuring, and securing an Apache web server on a Linux VPS.


📌 Prerequisites

  • A Linux VPS (Ubuntu, Debian, CentOS, or AlmaLinux) from VolticHost

  • Root or sudo user access

  • A domain name (optional but recommended)

  • Ports 80 (HTTP) and 443 (HTTPS) open in the firewall


1️⃣ Update Your System

Before installing anything, update your package list.

For Ubuntu/Debian, run:

sudo apt update && sudo apt upgrade -y

For CentOS/AlmaLinux/RockyLinux, run:

sudo yum update -y

Your system is now up to date!


2️⃣ Install Apache Web Server

For Ubuntu/Debian

sudo apt install apache2 -y

Start and enable Apache:

sudo systemctl start apache2
sudo systemctl enable apache2

For CentOS/AlmaLinux

sudo yum install httpd -y

Start and enable Apache:

sudo systemctl start httpd
sudo systemctl enable httpd

Apache is now installed and running!


3️⃣ Configure Firewall for Apache

For Ubuntu/Debian (UFW)

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

For CentOS/AlmaLinux (Firewalld)

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Your web server can now receive HTTP and HTTPS requests!


4️⃣ Create a Website Directory

  1. Create a directory for your website:

    sudo mkdir -p /var/www/mywebsite.com/public_html
    
    
  2. Set the correct permissions:

    sudo chown -R $USER:$USER /var/www/mywebsite.com/public_html
    
    
  3. Create a sample index page:

    echo "<h1>Welcome to My Website!</h1>" | sudo tee /var/www/mywebsite.com/public_html/index.html
    
    

Your website files are now set up!


5️⃣ Configure Apache Virtual Hosts

  1. Create a new Apache configuration file:

    sudo nano /etc/apache2/sites-available/mywebsite.com.conf
    
    
  2. Add the following content (replace mywebsite.com with your actual domain):

    <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName mywebsite.com
        ServerAlias www.mywebsite.com
        DocumentRoot /var/www/mywebsite.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
    
  3. Save and close the file.

  4. Enable the virtual host:

    sudo a2ensite mywebsite.com.conf
    
    
  5. Reload Apache to apply changes:

    sudo systemctl reload apache2
    
    

Your website is now hosted on Apache!


6️⃣ Set Up SSL with Let’s Encrypt (HTTPS)

To secure your site with HTTPS, install a free Let’s Encrypt SSL certificate.

  1. Install Certbot:

    sudo apt install certbot python3-certbot-apache -y
    
    
  2. Generate an SSL certificate:

    sudo certbot --apache -d mywebsite.com -d www.mywebsite.com
    
    
  3. Follow the prompts and agree to the terms.

  4. Auto-renew the certificate:

    sudo systemctl enable certbot.timer
    
    

Your website is now secured with HTTPS!


7️⃣ Test Your Website

Find Your VPS IP Address

Run:

curl ifconfig.me

Copy the IP and open it in a web browser:

http://your-vps-ip

If using a domain, visit:

http://mywebsite.com

Your website is now live!


🎉 Conclusion

You've successfully set up and hosted a website on a Linux VPS using Apache! Your site is now accessible via HTTP and HTTPS. 🚀

For more assistance, contact VolticHost Support.