Apache Web server Setup Notes - Oliver-Mustoe/Oliver-Mustoe-Tech-Journal GitHub Wiki
In this page I detail how I installed Apache & PHP on a CentOS 7 VM, as well as webpage examples.
Notes
Apache Install
First I added a A record named "web01" with and IP address pointed towards my mail01(10.0.5.4), the "Forward DNS" section in Setup Notes details how to create an A record.
I then installed Apache on the mail01/web01 system with the command:
- sudo yum install httpd
Then I started and enabled, so it starts on startup, Apache with the commands:
- sudo systemctl start httpd
Then - sudo systemctl enable httpd
To verify everything was working I ran the command:
- sudo systemctl status httpd
And saw that the service was active and running.
Next I added the appropriate ports to the firewall with the following commands in order:
- sudo firewall-cmd ––permanent ––add-port=80/tcp
- sudo firewall-cmd ––permanent ––add-port=443/tcp
And then I reloaded the firewall with the command:
- sudo firewall-cmd ––reload
To test this was working I went into a web browser and typed "http://web01.firstname.local" where I saw a testing page.
PHP install & making a webpage
NOTE: I could have just used html to make a basic webpage, but used PHP to add more to the site
First I installed PHP with the command:
- sudo yum install php
Then I restarted httpd, so PHP can work, with the command
- sudo systemctl restart httpd
Next I went into my Webroot directory for Apache, "cd /var/www/html", and added a file named "index.php" with the command:
- sudo touch index.php
NOTE: As mentioned above I could have instead made a file "index.html" to just run html, but index.html would NOT be able to run PHP code unless specified in a apache configuration file
Then I edited the file, sudo nano index.php, and addded the following code:
NOTE: PHP code must be inside the html header
Now I went back to "http://web01.firstname.local" and instead of the testing page I get this: