How to Host a Static Website on a VPS Using Apache

2025-07-16 โ€” By Akshay Singh ยท 6 min read

Share this article:

Hosting your own static website on a VPS gives you complete control and flexibility โ€” no platform limitations, no hidden restrictions. In this guide, we will talk about how to host a static HTML, CSS and JS website on a Linux VPS using the Apache web server.


๐Ÿš€ Why Host a Static Site on a VPS?

  • Complete control: No platform dependency
  • Scalability: You decide how to scale
  • Cost-effective: Especially for static sites
  • Flexibility: Run cron jobs, scripts, or additional services

Apache remains a solid choice for serving static content โ€” it's stable, widely supported, and easy to configure.


๐Ÿงฐ Prerequisites

  • A Linux VPS (Ubuntu 22.04 LTS recommended)
  • A static website folder (e.g., built with plain HTML or exported from frameworks like Astro, Hugo, or Next.js static export)
  • SSH access to the VPS
  • A domain name (optional but ideal)

๐Ÿ” Step 1: Connect to Your VPS

Use SSH to log into your VPS:

ssh root@your-server-ip

If you're using a different user:

ssh your-user@your-server-ip

๐Ÿงฑ Step 2: Install Apache Web Server

Update packages and install Apache:

sudo apt update && sudo apt install apache2 -y

Enable and start the Apache service:

sudo systemctl enable apache2
sudo systemctl start apache2

You can check if it's working by visiting http://your-server-ip in your browser.


๐Ÿ—‚ Step 3: Set Up Your Website Directory

Let's assume your website is called mywebsite.

sudo mkdir -p /var/www/mywebsite

Copy your static files into that folder (youโ€™ll upload them in the next step).


๐Ÿงพ Step 4: Create a Virtual Host Configuration

Create a new Apache config file:

sudo nano /etc/apache2/sites-available/mywebsite.conf

Paste the following basic config:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName yourdomain.com
    DocumentRoot /var/www/mywebsite

    <Directory /var/www/mywebsite>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Replace yourdomain.com with your actual domain or server IP.

Enable the site and disable the default site:

sudo a2ensite mywebsite.conf
sudo a2dissite 000-default.conf

Reload Apache:

sudo systemctl reload apache2

๐Ÿ“ Step 5: Upload Your Static Website

Use scp from your local machine to upload the files:

scp -r ./your-static-site/* user@your-server-ip:/var/www/mywebsite

Or use SFTP with a tool like FileZilla.


๐Ÿ” Step 6: Set Correct Permissions

Ensure Apache can read the files:

sudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite

๐ŸŒ Step 7: Point Your Domain (Optional but Recommended)

Update your domainโ€™s DNS A record to point to your VPS IP.

Then update Apacheโ€™s config (ServerName) and reload:

sudo systemctl reload apache2

๐Ÿ›ก Bonus: Enable UFW Firewall and Allow HTTP

sudo ufw allow 'Apache Full'
sudo ufw enable

๐Ÿ”’ Bonus: Enable HTTPS with Let's Encrypt (Optional)

Install Certbot:

sudo apt install certbot python3-certbot-apache -y

Run the command to get a free SSL certificate:

sudo certbot --apache

Follow the prompts to secure your domain with HTTPS.


โœ… You're Live!

Visit your site via http://yourdomain.com or http://your-server-ip. Youโ€™ve just self-hosted a website using Apache โ€” no cPanel, no platform restrictions.


๐Ÿง  Final Tips

  • Compress images before uploading to save bandwidth
  • Use .htaccess for custom rules (e.g., redirects)
  • Monitor server logs:
    tail -f /var/log/apache2/access.log
    

if you stuck somewhere? Please reach out me via the Contact Us page.

Happy deploying!

NTheDailyDevs
TheDailyDevs is a developer-first blog and knowledge hub created by passionate engineers to share real-world development tips, deep-dive tutorials, industry insights, and hands-on solutions to everyday coding challenges. Whether you're building apps, exploring new frameworks, or leveling up your dev game, you'll find practical, no-fluff content here, updated daily.