Enabling Apache2 for php

Configuring apache2 web server

You need to insert the following lines into your Apache httpd.conf configuration file to load the PHP module for Apache 2.x:

# 
LoadModule php5_module "E:/softwares/php/php7apache2_4.dll"
AddHandler application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "E:/softwares/php"

Screenshot

Here “E:/softwatres/php” is php installation directory. Refer to Installing php on windows machine - linux - Freemindscafe for details.

hello.php file

Create the following hello.php file under apache web server’s document root. Please refer to Installing apache2 web server on windows machine - linux - Freemindscafe to define the document root for the apache web server.

<html> 
	<head> 
	<title>PHP Test</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
	</head>

<body> 
	<h1>PHP Test</h1>
		<p><b>An Example of PHP in Action</b></p>
		<?php echo "The Current Date and Time is: <br />"; 
		echo date("g:i A l, F j Y.");?> </p>
	<h2>PHP Information</h2> 
		<p> <?php phpinfo(); ?> </p> 
	</body> 
</html>
  • Start apache webserver
  • Access hello.php file in the browser by pointing it to http://localhost/hello.php
  • php scripting should kick in and should render the following