2025-07-16 โ By Akshay Singh ยท 6 min read
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.
Apache remains a solid choice for serving static content โ it's stable, widely supported, and easy to configure.
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
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.
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).
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
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.
Ensure Apache can read the files:
sudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite
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
sudo ufw allow 'Apache Full'
sudo ufw enable
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.
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.
.htaccess
for custom rules (e.g., redirects)tail -f /var/log/apache2/access.log
if you stuck somewhere? Please reach out me via the Contact Us page.
Happy deploying!