Skip to content
FullStackDostFullStackDostLearn · Build · Level Up
  • All Courses
  • Updates
  • My Account
  • Practice
  • All Courses
  • Updates
  • My Account
  • Practice
  • Home
  • Full Stack Development

LAMP Tutorials

Curriculum

  • 1 Section
  • 5 Lessons
  • 2 Weeks
Expand all sectionsCollapse all sections
  • LAMP Tutorials
    The LAMP stack is a popular open-source web development platform that consists of four key components: Linux, Apache, MySQL, and PHP.
    5
    • 1.1
      LAMP Stack
    • 1.2
      Installing Apache Web Server on Linux
    • 1.3
      Apache Virtual Host Configuration on Linux: Host Multiple Websites Efficiently
    • 1.4
      MySQL installation on Linux
    • 1.5
      PHP installation on Linux

Installing Apache Web Server on Linux

Introduction to Apache Web Server

Welcome, future FullStackDost developers! Today, we’re diving into the exciting world of web servers, and our first stop is Apache HTTP Server. Think of a web server as the digital waiter for your website. When someone types your website address into their browser, the web server is responsible for fetching and delivering all the necessary files (HTML, CSS, JavaScript, images) to their computer.

Apache is one of the oldest, most reliable, and widely used web servers in the world. It’s open-source, powerful, and incredibly flexible, making it a fantastic choice for hosting everything from simple personal blogs to complex enterprise applications. In this lesson, we’ll guide you through the step-by-step process of installing Apache on popular Linux distributions, ensuring you can get your first web pages online.

Key Concepts You’ll Master

  • What is a Web Server? Understand its fundamental role in delivering web content.
  • Why Apache? Discover its popularity, features, and advantages.
  • Linux Package Managers: Learn about apt (for Debian/Ubuntu) and dnf (for CentOS/RHEL) – your go-to tools for software installation.
  • Service Management: Get familiar with systemctl for managing background services like Apache.
  • Firewall Configuration: Understand the importance of opening ports for web traffic using UFW or Firewalld.

Step-by-Step: Installing Apache on Ubuntu/Debian

Let’s get started with installing Apache on Ubuntu or Debian-based systems. We’ll use the apt package manager for this.

1. Update Your Package Index

Before installing new software, it’s always a good practice to update your system’s package index. This ensures you get the latest versions and dependencies.

sudo apt update

This command refreshes the list of available packages and their versions from your distribution’s repositories.

2. Install the Apache2 Package

Now, let’s install the Apache web server package, which is named apache2 on Ubuntu/Debian.

sudo apt install apache2 -y

The -y flag automatically confirms any prompts, making the installation smoother. Once the installation completes, Apache should automatically start running.

3. Verify Apache Service Status

To confirm that Apache is up and running correctly, you can check its service status using systemctl.

sudo systemctl status apache2

You should see output indicating an active (running) status. Press q to exit the status view.

4. Adjust Your Firewall (UFW)

Even if Apache is running, your server’s firewall might be blocking external access to it. Ubuntu uses UFW (Uncomplicated Firewall) by default. We need to allow HTTP (port 80) and HTTPS (port 443) traffic.

sudo ufw allow 'Apache'

This command allows traffic on both HTTP (port 80) and HTTPS (port 443) for the Apache profile. If UFW is not already enabled, you might need to enable it first (be cautious if doing this on a remote server without SSH access already allowed!):

sudo ufw enable

You can then verify the firewall status:

sudo ufw status

Ensure that ‘Apache’ (or ports 80/443) is listed as allowed.

5. Test Your Web Server

Finally, it’s time to see your Apache server in action! Open your web browser and navigate to your server’s IP address. If you don’t know your server’s IP, you can find it using commands like ip a s or hostname -I.

hostname -I | awk '{print $1}'

Once you have the IP, enter it into your browser:

http://YOUR_SERVER_IP

You should see the default Ubuntu Apache welcome page, which typically says “Apache2 Ubuntu Default Page”. Congratulations, your Apache web server is successfully installed and serving content!

Installing Apache on CentOS/RHEL/Fedora

For Red Hat-based distributions like CentOS, RHEL, or Fedora, the process is quite similar, but we use the dnf (or older yum) package manager and the Apache package is named httpd.

1. Update Your Package Index

sudo dnf update -y

2. Install the HTTPD Package

sudo dnf install httpd -y

3. Start and Enable the HTTPD Service

On these distributions, Apache doesn’t always start automatically after installation. You need to explicitly start and enable it to run on boot.

sudo systemctl start httpd
sudo systemctl enable httpd

4. Adjust Your Firewall (Firewalld)

CentOS/RHEL/Fedora typically use firewalld. We need to allow HTTP and HTTPS services through it.

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

The --permanent flag makes the changes persistent across reboots, and --reload applies them immediately.

5. Verify HTTPD Service Status

sudo systemctl status httpd

Look for active (running) status.

6. Test Your Web Server

Just like with Ubuntu, find your server’s IP and enter it into your browser:

http://YOUR_SERVER_IP

You should see the default CentOS/RHEL Apache test page.

Practice Exercise: Your First Web Server Customization

Now that you have Apache running, let’s get hands-on!

  1. Install on a Different Distribution: If you used Ubuntu/Debian, try setting up Apache on a CentOS/RHEL/Fedora virtual machine or vice-versa. This will solidify your understanding of different package managers and firewall tools.
  2. Change the Default Web Page: Navigate to the default web root directory (/var/www/html on Ubuntu/Debian, /var/www/html on CentOS/RHEL) and create a simple index.html file with your own custom message. For example:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>My First Apache Page</title>
    </head>
    <body>
        <h1>Hello FullStackDost! My Apache Server is Alive!</h1>
        <p>This is my custom web page served by Apache.</p>
    </body>
    </html>

    After saving, refresh your browser to see your changes.

  3. Monitor Apache Logs: Get comfortable with checking Apache’s log files. On Ubuntu/Debian, error logs are typically at /var/log/apache2/error.log and access logs at /var/log/apache2/access.log. On CentOS/RHEL, they are usually in /var/log/httpd/. Use tail -f to watch them in real-time as you access your server.

Summary

You’ve successfully installed and configured the Apache HTTP Web Server on your Linux system! This is a foundational step in becoming a full-stack developer. You now understand how to use package managers, manage services, configure firewalls, and verify your web server’s operation. This powerful tool will be the backbone for serving your web applications. Keep practicing, and you’ll master it in no time!

LAMP Stack
Prev
Apache Virtual Host Configuration on Linux: Host Multiple Websites Efficiently
Next

Copyright © 2026 FullStackDost. All Rights Reserved.

  • Privacy Policy
  • Terms of Service
  • Contact Support

Powered by EduPress