LochStudios  /  Help Centre  /  VPS & Linux  /  Install Apache2 on Ubuntu/Debian

Install Apache2 on Ubuntu/Debian

Install and enable Apache2 web server on Ubuntu/Debian with systemd commands and basic configuration.

Updated

Apache2 is a flexible, widely-used web server. This guide covers installation, enabling the service, and verifying it's running.

Prerequisites

  • Ubuntu/Debian server with sudo access
  • Internet connection

Installation Steps

1. Update package lists

sudo apt update

2. Install Apache2

sudo apt install -y apache2

This installs Apache2 and all required dependencies.

3. Enable Apache2 to start on boot

sudo systemctl enable apache2

4. Start the Apache2 service

sudo systemctl start apache2

5. Verify Apache2 is running

sudo systemctl status apache2

You should see active (running) in the output.

6. Test the installation

Open your browser and navigate to http://your-server-ip. You should see the Apache2 default welcome page.

Alternatively, test from the server itself:

curl http://localhost

Basic Firewall Configuration

If you're using Ubuntu's built-in firewall (UFW), allow HTTP and HTTPS traffic:

sudo ufw allow 'Apache Full'

Or for HTTP only:

sudo ufw allow 'Apache'

If you're using a cloud provider's security group (AWS, Azure, DigitalOcean, etc.), add inbound rules for ports 80 (HTTP) and 443 (HTTPS).

Tips

  • Apache2 configuration files are in /etc/apache2/
  • The main config file is /etc/apache2/apache2.conf
  • Enable additional modules with sudo a2enmod <module-name> (e.g., sudo a2enmod rewrite)
  • Restart Apache after config changes: sudo systemctl restart apache2
  • Check configuration syntax before restarting: sudo apache2ctl -t

For RHEL/CentOS/Rocky

If using a RHEL-based distribution, use dnf instead:

sudo dnf install -y httpd
sudo systemctl enable httpd
sudo systemctl start httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Was this article helpful?

← Back to VPS & Linux