Setup Apache2 Print

  • 0

Apache HTTP Server (commonly referred to as "Apache") is one of the most widely used web servers in the world. This guide explains how to install Apache on popular Linux distributions such as Ubuntu, Debian, CentOS, AlmaLinux, and Rocky Linux.

Requirements

  • Root or sudo access to the server
  • A Linux distribution (Ubuntu, Debian, CentOS, etc.)
  • Internet connection

Installation Steps

For Ubuntu/Debian:

  1. Update package lists
    sudo apt update
  2. Install Apache
    sudo apt install apache2 -y
  3. Enable and start the Apache service
    sudo systemctl enable apache2
    sudo systemctl start apache2
  4. Check Apache status
    sudo systemctl status apache2
  5. Test in browser
    Visit your server's IP address in a web browser. You should see the Apache default page.

For CentOS/RHEL/AlmaLinux/Rocky Linux:

  1. Install Apache (httpd)
    sudo yum install httpd -y
  2. Enable and start the Apache service
    sudo systemctl enable httpd
    sudo systemctl start httpd
  3. Check Apache status
    sudo systemctl status httpd
  4. Test in browser
    Visit your server's IP address to view the Apache welcome page.

Common Apache Commands

  • Restart Apache:
    sudo systemctl restart apache2 (Ubuntu/Debian)
    sudo systemctl restart httpd (CentOS/RHEL)
  • Reload configuration:
    sudo systemctl reload apache2 or httpd
  • Test Apache configuration:
    apachectl configtest

Default File Locations

  • Configuration file:
    • /etc/apache2/apache2.conf (Ubuntu/Debian)
    • /etc/httpd/conf/httpd.conf (CentOS/RHEL)
  • Document root: /var/www/html
  • Log files: /var/log/apache2/ or /var/log/httpd/

Opening Firewall (Optional)

If using UFW (Ubuntu):
sudo ufw allow 'Apache Full'

If using firewalld (CentOS/RHEL):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload


Was this answer helpful?

« Back