Apache Lab - devinziegler/Devin-Tech-Journal GitHub Wiki
Apache is a tool used for hosting web servers. This entry will show some Apache basics, including installation using a CENTOS system.
yum install httpd
Default port for HTTP
is 80
, default port for HTTPS
is 443
. CENTOS by default does not allow incoming traffic through these ports.
- Edit the firewall using the following commands: List Current Firewall Rules:
firewall-cmd --list-all
Add a permeant rule to the firewall:
firewall-cmd --add-service=<service_name> --permanent
Restart the firewall service:
firewall-cmd --reload
Type this command to start the web server:
systemctl start httpd
The default page shown when a client connects will be the Apache welcome page. This can be disabled by making index.html
file in the web root directory, then comment out the the file located at /etc/httpd/conf.d/welcome.conf
.
<!DOCTYPE html>
<html>
<body>
<p>Welcome to my web server.</p>
</body>
</html>
- This is a nifty diagram of how a html file is formatted.
PHP is an open source scripting language used for server side scripting. In my case, I had to edit the httpd config file to allow php scripting.
Add the following string to /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php
Make sure to restart httpd after editing using the following command:
systemctl restart httpd
Below is an example of a for loop that will count to 10:
<?php
for ($x = 1; $x <= 10; $x++> {
echo "X is equal to: $x <br>";
}
?>
- HTML and PHP files should go into the webroot directory,
/var/www/html
.