Setting Up a Web Server
This article outlines the steps taken to successfully complete the task of setting up two static websites on an Apache web server, highlighting the importance of each step and its relevance in a real-world IT environment.
1. Context and Importance
In the world of IT infrastructure, setting up web servers is a fundamental task. This exercise, involving the installation of the httpd
package and serving two static websites, simulates a common scenario in systems administration and DevOps. It demonstrates core skills such as:
-
Package Management: The ability to install and manage software (
httpd
in this case) on a Linux system using tools likeyum
. -
Service Management: Controlling the lifecycle of a service (starting, enabling, and restarting Apache) using
systemctl
. -
Firewall Configuration: Securing the server by explicitly opening the required port (
6100
) for public access while keeping other ports closed. - File Permissions and Ownership: Understanding and managing file and directory access to ensure the web server can read content while maintaining system security.
-
Web Server Configuration: Customizing the server's behavior, such as changing the listening port and setting up virtual directories (
Aliases
), to meet specific requirements.
Mastering these skills is crucial for anyone responsible for deploying and maintaining web applications in a production environment.
2. Step-by-Step Completion
Step a: Install Apache
The first step was to install the Apache HTTP server. The yum
package manager was used for this, as it handles all dependencies automatically.
sudo yum install httpd -y
Step b: Configure Port and Firewall
By default, Apache listens on port 80. To meet the requirement of serving on port 6100, the Listen
directive in /etc/httpd/conf/httpd.conf
was modified.
# Before:
Listen 80
# After:
Listen 6100
This change tells Apache to bind to the new port. However, for external clients to reach this port, the firewall had to be configured. Since firewalld
was not installed, iptables
was used to open the port.
sudo iptables -I INPUT -p tcp --dport 6100 -j ACCEPT
sudo service iptables save
Finally, the Apache service was started and enabled to ensure it would run on system boot.
sudo systemctl start httpd
sudo systemctl enable httpd
Step c: Copy and Configure Websites
The two websites, news
and cluster
, were backed up on the jump_host
under the /home/thor
directory. The goal was to copy them to the web server's document root, /var/www/html/
, and make them accessible via http://localhost:6100/news/
and http://localhost:6100/cluster/
.
First, the destination directories were created:
sudo mkdir -p /var/www/html/news
sudo mkdir -p /var/www/html/cluster
The file transfer faced a permission issue as the tony
user lacked write access to /var/www/html
. This was solved by first changing the ownership of the directories.
sudo chown -R tony:tony /var/www/html/news
sudo chown -R tony:tony /var/www/html/cluster
Then, the files were copied from the jump_host
to stapp01
using scp
.
scp -r /home/thor/news/* tony@stapp01:/var/www/html/news/
scp -r /home/thor/cluster/* tony@stapp01:/var/www/html/cluster/
After the copy was successful, ownership of the directories was reverted to the apache
user so the web server could read the files.
sudo chown -R apache:apache /var/www/html/news
sudo chown -R apache:apache /var/www/html/cluster
Finally, Alias
directives were added to the Apache configuration file to map the URL paths to the new directories.
Alias /news/ "/var/www/html/news/"
<Directory "/var/www/html/news/">
Require all granted
</Directory>
Alias /cluster/ "/var/www/html/cluster/"
<Directory "/var/www/html/cluster/">
Require all granted
</Directory>
The Apache service was then restarted to apply these changes.
Step d: Verification
The final step was to verify that the websites were accessible locally on stapp01
using curl
.
curl http://localhost:6100/news/
curl http://localhost:6100/cluster/
Both commands successfully returned the HTML content of the respective websites, confirming the successful completion of the exercise.
Conclusion
This exercise successfully demonstrated the end-to-end process of setting up a web server for static content. It highlighted the importance of fundamental system administration tasks, from package installation and firewall configuration to managing file permissions and web server aliases. These are critical skills for anyone working in IT infrastructure, as they form the building blocks for hosting more complex web applications and services.
Top comments (0)