Setting up Apache Web Server (SYS 255) - Chromosom3/TechNotes GitHub Wiki
Apache is a FOSS web server. There are alternatives to Apache such as Internet Information Services (IIS) and Nginx. For this lab, we will focus specifically on Apache though the concepts can be applied to other web servers. Before we can do anything with Apache we must install it. On CentOS, you simply use yum to install it, yum install httpd
note the package is called httpd, not Apache. On Ubuntu systems, you would call the package apache2 and use a different package manager to install, apt install apache2 -y
. Once the package is installed we will want to enable and start the service.
-
systemctl enable httpd
This will enable the server to auto-start on boot. -
systemctl start httpd
This will start the service. -
systemctl status httpd
This will allow you to see the status of the Apache service. -
systemctl reload httpd
This will reload the current Apache configuration. -
systemctl restart httpd
This will restart the Apache server.
-
systemctl enable apache2
This will enable the server to auto-start on boot. -
systemctl start apache2
This will start the service. -
systemctl status apache2
This will allow you to see the status of the Apache service. -
systemctl reload apache2
This will reload the current Apache configuration. -
systemctl restart apache2
This will restart the Apache server.
Just like with DHCP we will need to allow traffic through the firewall for our service to run. You can use the following commands to add the firewall rules and make sure they are applied and working.
-
firewall-cmd --add-service=http --permanent
This will add a firewall rule for port 80 (HTTP). -
firewall-cmd --add-service=https --permanent
This will add a firewall rule for port 443 (HTTPS). -
firewall-cmd --reload
This will update the firewall to apply the changes. -
firewall-cmd --list-services
This will allow you to see what services are allowed through the firewall. -
firewall-cmd --list-all
This will allow you to see what services are allowed through the firewall and ports. -
firewall-cmd --add-port=80/tcp --permanent
Alternative to the first one. This specifies port instead of service.
-
ufw allow 80/tcp
This will add a firewall rule for port 80 (HTTP). -
ufw allow 443/tcp
This will add a firewall rule for port 443 (HTTPS). -
ufw reload
This will update the firewall to apply the changes. -
ufw status
This will allow you to view the status of the firewall.
Once you have Apache installed and configured you will be able to navigate to the default site. Once you confirm that apache is working you will want to follow the steps in /etc/httpd/conf.d/welcome.conf
to disable the default welcome message. Once you disable the default welcome message you can create an index file in /var/www/html/
. The index file will be displayed when people navigate to your website. Below is a sample index.html file. You may also want to install PHP on your website to allow for more features. To do so simply install PHP with your package manager and then restart the Apache service.
<!DOCTYPE html>
<html>
<body>
<h1>Hellow</h1>
</body>
</html>