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.
apt (for Debian/Ubuntu) and dnf (for CentOS/RHEL) – your go-to tools for software installation.systemctl for managing background services like Apache.Let’s get started with installing Apache on Ubuntu or Debian-based systems. We’ll use the apt package manager for this.
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.
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.
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.
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.
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!
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.
sudo dnf update -y
sudo dnf install httpd -y
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
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.
sudo systemctl status httpd
Look for active (running) status.
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.
Now that you have Apache running, let’s get hands-on!
/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.
/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.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!