Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Install Apache in Linux

In this tutorial, we will learn how to install the Apache web server on a Linux system. We will cover installation steps for Ubuntu/Debian-based and CentOS/RHEL-based distributions.

Installing Apache on Ubuntu/Debian-based systems

  • Update your system's package index:
sudo apt-get update
  • Install Apache:
sudo apt-get install apache2
  • Check the status of the Apache service:
sudo systemctl status apache2

If Apache is running correctly, the output should show "active (running)".

  • Enable Apache to start on boot:
sudo systemctl enable apache2
  • Open your web browser and navigate to http://localhost or http://your-server-ip. You should see the Apache default welcome page, confirming that the installation is successful.

Installing Apache on CentOS/RHEL-based systems

  • Install the EPEL (Extra Packages for Enterprise Linux) repository to get additional packages:
sudo yum install epel-release
  • Update your system's package index:
sudo yum update
  • Install Apache:
sudo yum install httpd
  • Check the status of the Apache service:
sudo systemctl status httpd

If Apache is running correctly, the output should show "active (running)".

  • Enable Apache to start on boot:
sudo systemctl enable httpd
  • Open your web browser and navigate to http://localhost or http://your-server-ip. You should see the Apache default welcome page, confirming that the installation is successful.

Configuring firewall rules for Apache (CentOS/RHEL-based systems)

To allow incoming traffic to your web server on CentOS/RHEL-based systems, configure the firewall rules with the following commands:

  • Allow HTTP traffic (port 80):
sudo firewall-cmd --permanent --add-service=http
  • Allow HTTPS traffic (port 443):
sudo firewall-cmd --permanent --add-service=https
  • Reload the firewall to apply the changes:
sudo firewall-cmd --reload

Now your Apache web server should be accessible from external networks.

By following these steps, you can install and configure the Apache web server on your Linux system. You can then start building and deploying your web applications.

  1. Setting up Apache on Ubuntu/Linux:

    • Use the package manager to install Apache on Ubuntu.
    sudo apt-get update
    sudo apt-get install apache2
    
  2. Installing Apache HTTP Server on CentOS:

    • Use yum package manager to install Apache on CentOS.
    sudo yum install httpd
    
  3. Apache installation steps on Debian/Linux:

    • Use apt package manager to install Apache on Debian.
    sudo apt-get update
    sudo apt-get install apache2
    
  4. Configuring Apache on Red Hat Linux:

    • Edit Apache configuration files located in /etc/httpd/ on Red Hat.
    sudo nano /etc/httpd/conf/httpd.conf
    
  5. Apache web server installation commands for Linux:

    • Use distribution-specific package managers (apt, yum, etc.) for installation.
    sudo apt-get install apache2  # Ubuntu/Debian
    sudo yum install httpd       # CentOS
    
  6. Securing Apache server on Linux:

    • Implement security measures such as configuring firewalls, SSL/TLS, and access controls.
    sudo ufw allow 80              # Allow HTTP traffic
    sudo ufw allow 443             # Allow HTTPS traffic
    
  7. Starting, stopping, and restarting Apache in Linux:

    • Use systemctl to manage Apache services.
    sudo systemctl start apache2   # Start Apache
    sudo systemctl stop apache2    # Stop Apache
    sudo systemctl restart apache2 # Restart Apache
    
  8. Apache virtual host setup on Linux:

    • Configure virtual hosts by creating separate configuration files.
    sudo nano /etc/apache2/sites-available/example.com.conf
    
  9. Enabling and disabling Apache modules in Linux:

    • Use a2enmod and a2dismod commands to manage Apache modules.
    sudo a2enmod ssl    # Enable SSL module
    sudo a2dismod php7.4 # Disable PHP module
    
  10. Checking Apache version on Linux:

    • Use the apache2 -v or httpd -v command to check the Apache version.
    apache2 -v
    
  11. Apache configuration files in Linux:

    • Main configuration files are typically located in /etc/apache2/ or /etc/httpd/.
    sudo nano /etc/apache2/apache2.conf
    
  12. Common issues during Apache installation on Linux:

    • Verify port availability (80, 443).
    • Check file permissions and ownership.
    • Review error logs for troubleshooting.
    tail -f /var/log/apache2/error.log