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
-
Create a directory for your website:
sudo mkdir -p /var/www/mywebsite.com/public_html
-
Set the correct permissions:
sudo chown -R $USER:$USER /var/www/mywebsite.com/public_html
-
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
-
Create a new Apache configuration file:
sudo nano /etc/apache2/sites-available/mywebsite.com.conf
-
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>
-
Save and close the file.
-
Enable the virtual host:
sudo a2ensite mywebsite.com.conf
-
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.
-
Install Certbot:
sudo apt install certbot python3-certbot-apache -y
-
Generate an SSL certificate:
sudo certbot --apache -d mywebsite.com -d www.mywebsite.com
-
Follow the prompts and agree to the terms.
-
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.