PHP is a general purpose server-side scripting language designed to generate dynamic web pages. It is among one of the first developed server-side scripting languages that is embedded into an HTML source document, rather than calling an external file to process data. In this article we are going to configure PHP with Apache.
You can download PHP from Download PHP for Windows. I downloaded VC9 x86 Thread Safe zip package.
- Extract all the files from the zip package downloaded.
- Put all files/folder into a folder e.g. C:\PHP. I put all files/folders into D:\hMailServer\php.
Install Apache Server on Windows. Follow Install Apache Server on Windows for detailed description.
Configure PHP with Apache
- Open the file “httpd.conf” located in “apache_installation_folder\conf” folder. In my case httpd.conf is in “D:\hMailServer\Apache2.2\conf”
- Rename “php.ini-development” to “php.ini” located in PHP installation folder.
- Add below lines in httpd.conf file. Please replace the installation path and while doing so please remember to replace all back slashes with forward slashes.
# Add these lines to configure PHP with Apache LoadModule php5_module "D:/hMailServer/PHP/php5apache2_2.dll" AddType application/x-httpd-php .php # configure the path to php.ini PHPIniDir "D:/hMailServer/php/"
- Save httpd.conf file.
- Now, restart Apache Web Server. Please refer Install Apache Server on Windows for more details on stopping/starting Apache Web Server.
Testing the PHP
- Create a simple a new file having below contents:
<html> <head> <title>Test PHP Installation</title> </head> <body> <h1><?php echo "You have successfully configured PHP with Apache"; ?></h1> </body> </html>
- Save this file as test.php in htdocs folder of your Apache installation folder. In my case it is “D:\hMailServer\Apache2.2\htdocs”
- Browse “http://localhost/test.php”. If “You have successfully configured PHP with Apache” message appears in your browser means successful configuration of PHP with Apache Web Server.