cs@vps-hosting.org

How to Install Apache HTTP Server on a VPS

Introduction to Apache HTTP Server

How to Install Apache HTTP Server

Apache HTTP Server is one of the most widely used web servers in the world. It is open-source, highly customizable, and works across various operating systems. In this guide, you will learn how to install and configure Apache on your VPS to serve websites efficiently.

Why Install Apache on a VPS?

Before diving into the installation process, let’s understand why Apache is a popular choice for VPS hosting:

  • Open-source and free: No licensing costs.
  • Highly customizable: Supports modules for enhanced functionality.
  • Cross-platform compatibility: Works with Linux, Windows, and macOS.
  • Strong community support: Extensive documentation and troubleshooting help.

Prerequisites

Before installing Apache, make sure you have:

  • A VPS running Ubuntu, Debian, CentOS, or any Linux distribution.
  • Root or sudo access to execute commands.
  • An active internet connection for downloading packages.

How to Install Apache on Ubuntu/Debian VPS

Step 1: Update Package Repository

Before installing Apache, update your system packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install Apache

Run the following command to install Apache:

sudo apt install apache2 -y

Step 3: Start and Enable Apache

Once the installation is complete, start and enable Apache to run on system boot:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 4: Verify Apache Installation

To check if Apache is running, use:

sudo systemctl status apache2

Alternatively, open your browser and enter your server’s IP address:

http://your-server-ip

If Apache is running, you will see the default Apache landing page.

How to Install Apache on CentOS/RHEL VPS

Step 1: Update System Packages

First, update the system’s package repository:

sudo yum update -y

Step 2: Install Apache (httpd)

Use the following command to install Apache:

sudo yum install httpd -y

Step 3: Start and Enable Apache

After installation, start the Apache service and enable it to launch at startup:

sudo systemctl start httpd
sudo systemctl enable httpd

Step 4: Configure Firewall

Allow HTTP and HTTPS traffic through the firewall:

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

Step 5: Verify Apache Installation

Check the status of Apache:

sudo systemctl status httpd

To test Apache, open your browser and enter your VPS’s IP address:

http://your-server-ip

If Apache is correctly installed, you will see the default welcome page.

How to Secure Apache Server on VPS

Enable UFW Firewall (Ubuntu/Debian)

For additional security, allow only HTTP and HTTPS traffic:

sudo ufw allow 'Apache Full'
sudo ufw enable

Secure Apache with Let’s Encrypt SSL

To install a free SSL certificate, use Let’s Encrypt:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache

Disable Directory Listing

Prevent attackers from viewing your directory structure by editing the Apache config file:

sudo nano /etc/apache2/apache2.conf

Find the following section and change Indexes to -Indexes:

Options -Indexes

Save the file and restart Apache:

sudo systemctl restart apache2

How to Uninstall Apache from VPS

If you need to remove Apache, use the following commands:

On Ubuntu/Debian:

sudo apt remove apache2 -y
sudo apt autoremove -y

On CentOS/RHEL:

sudo yum remove httpd -y

Conclusion

Installing Apache on a VPS is straightforward and takes just a few steps. Whether you’re using Ubuntu, Debian, or CentOS, you can get Apache up and running in minutes. Once installed, securing Apache with a firewall and SSL is crucial to protect your server. Start hosting your websites today with Apache HTTP Server!

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Worldwide shipping

On all orders above $50

Easy 30 days returns

30 days money back guarantee

International Warranty

Offered in the country of usage

100% Secure Checkout

PayPal / MasterCard / Visa