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 httpdThis will enable the server to auto-start on boot. -
systemctl start httpdThis will start the service. -
systemctl status httpdThis will allow you to see the status of the Apache service. -
systemctl reload httpdThis will reload the current Apache configuration. -
systemctl restart httpdThis will restart the Apache server.
-
systemctl enable apache2This will enable the server to auto-start on boot. -
systemctl start apache2This will start the service. -
systemctl status apache2This will allow you to see the status of the Apache service. -
systemctl reload apache2This will reload the current Apache configuration. -
systemctl restart apache2This 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 --permanentThis will add a firewall rule for port 80 (HTTP). -
firewall-cmd --add-service=https --permanentThis will add a firewall rule for port 443 (HTTPS). -
firewall-cmd --reloadThis will update the firewall to apply the changes. -
firewall-cmd --list-servicesThis will allow you to see what services are allowed through the firewall. -
firewall-cmd --list-allThis will allow you to see what services are allowed through the firewall and ports. -
firewall-cmd --add-port=80/tcp --permanentAlternative to the first one. This specifies port instead of service.
-
ufw allow 80/tcpThis will add a firewall rule for port 80 (HTTP). -
ufw allow 443/tcpThis will add a firewall rule for port 443 (HTTPS). -
ufw reloadThis will update the firewall to apply the changes. -
ufw statusThis 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>