How Do You Get an Apache Web Server to Publish a Specific .PHP File on a CentOS/RHEL/Fedora Server?

Problem scenario
You are using a RedHat derivative distribution of Linux.  You want to install Apache Web Server on it so it can publish PHP content.  How do you install and configure the necessary dependencies to do this?

1.  Install Apache web server:  sudo yum -y install httpd

2.  Install PHP:  sudo yum -y install php

3.  Examine the httpd.conf file.  It is usually in this location: /etc/httpd/conf/

Find the DocumentRoot section.  It may look like this:

DocumentRoot "/var/www/html"

This means that the directory path where the web server will look for .html or .php files is /var/www/html.

4.  Place a PHP file in the DocumentRoot location found above (e.g., create /var/www/html/good.php) with the following content:



<form action="anotherPage.php" method="post">

Check this text field out: <input type="text" name="pk" value=<?php echo $var1; ?>>

<input type="submit"2>


5.  Start the web server with this command:  sudo service httpd start

6.  Open a web browser.  Construct a URL like this:


Replace x.x.x.x with the external IP address of the above server.  Replace good.php with the name you gave to the .php file in step #4.  Go to this URL in the web browser.  This tests your work above.

Leave a comment

Your email address will not be published. Required fields are marked *