Setting up Apache HTTP Server (httpd) on a Linux system is a straightforward process that allows you to host a website on your own server. In this detailed guide, we'll go through the steps to install Apache, create a basic web page, configure the firewall, and access your website from a web browser.
Before installing Apache, it's a good idea to check if the httpd package is available in your repository. Open your terminal and run:
dnf list httpd
This command will list the details of the httpd package, including its version and repository information.
To install Apache, use the dnf package manager with the following command:
dnf install httpd -y
The -y
flag automatically confirms the installation without prompting you for confirmation.
Now that Apache is installed, let's create a basic HTML file to test the server. We'll use the echo
command to write a simple HTML message to the index.html
file in the default web directory:
echo "<marquee><h1><font color=teal>Site is working...</font></h1></marquee>" > /var/www/html/index.html
This command creates an HTML file that displays a scrolling marquee message: "Site is working..."
Next, start the Apache service and ensure it starts automatically on boot with the following commands:
systemctl restart httpd
systemctl enable --now httpd
systemctl restart httpd:
Restarts the Apache service.systemctl enable --now httpd:
Enables the Apache service to start at boot and starts it immediately.To allow HTTP traffic through the firewall, you need to add HTTP as an allowed service. Use the following commands:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --zone=libvirt --add-service=http
firewall-cmd --reload
Finally, open a web browser and navigate to the IP address of your server to see the new site. For example:
firefox http://10.0.0.100
You've now successfully set up Apache on your Linux system and hosted a simple website. This guide covers the basic steps, but Apache offers extensive configuration options for more complex setups. Whether you're setting up a personal blog or a business website, Apache is a powerful and flexible web server that can meet your needs. Happy hosting!