Installing PHP and Apache have been done quite frequently by all I think and most of them know about it. But I believe some others might want to up to date installing VC9 PHP and Apache in windows system.
So I thought that I share this and there is not that right place than sitepoint PHP forum.
To run the applications compiled with VC8 or VC10, it is required to install the respective (or latest one is always better) Visual C++ redistributable packages. You can download the package from Microsoft's official site for free.
- To download Visual C++ 2008 - http://www.microsoft.com/download/en/details.aspx?id=5582
- To download Visual C++ 2010 - http://www.microsoft.com/download/en/details.aspx?id=8328
Note: If you have any Visual Studio installed in your PC then you don't have to install them separately.
Where to install?
Since I have not used any installers for both PHP and Apache, I will be downloading the pre compiled zipped packages and install them in my D drive. The folder structure will look like below:
- d:/etc/apache - Apache installation
- d:/etc/php - PHP installation
- d:/etc/www - document root folder
Note: You can change the drive and path for the installations in your own way.
- Download the latest Apache 2.4.1 (as of writing this) from [http://www.apachelounge.com/download/ (direct link for the current version - [URL="http://www.apachelounge.com/download/win32/bins/httpd-2.4.1-win32.zip"]http://www.apachelounge.com/download/win32/bins/httpd-2.4.1-win32.zip](http://www.apachelounge.com/download/)) and unzip it in d:/etc/apache
- Download latest version 5.4 from http://windows.php.net/download and unzip it in d:/etc/php. While downloading PHP, choose the Thread Safe version for windows.
- Download the PHP and Apache connector DLL file from [http://www.apachelounge.com/download/ (direct link: [URL="http://www.apachelounge.com/download/win32/mods-2.4/php5apache2_4.dll-php-5.4-win32.zip"]http://www.apachelounge.com/download/win32/mods-2.4/php5apache2_4.dll-php-5.4-win32.zip](http://www.apachelounge.com/download/)) and extract the file php5apache2_4.dll and copy it to d:/etc/php.
Though the configurations may vary from individual's requirement but here I will be discussing for some basic configurations in PHP and Apache.
[*]Open the file d:/etc/apache/conf/httpd.conf in any text editor (I use my lovely Notepad++) then find and make the following changes/configurations as per your installation path.
[*]Set the server root
[*]Enable required Apache modules. I just uncomment one more for mod_rewrite module.
[*]Add the following lines somewhere (I did just below the module enabling)
LoadModule php5_module "d:/etc/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
[*]Change server admin email address
[*]Change the document root:
[*]If you want to allow .htaccess to be used under document root do the following under <Directory "d:/etc/www">
[*]Find the follwoing and replace the path:
ScriptAlias /cgi-bin/ "d:/etc/apache/cgi-bin/"
[*]Add index.php in directory index
DirectoryIndex index.html [B][I]index.php[/I][/B]
- Rename php.ini-development to php.ini
- Find extension directory setting and set the path as per your installation.
- Uncomment (remove the simicolon ; from the beginning of the line) the extensions that you want to enable them. i.e.
- If you want to test email sending from the PHP in local system, then you need to set the SMTP. i.e.
Rest of the changes/configurations are totally depends on requirement project wise.
Set Environment Variables for PHP (Windows 7)
- To be available PHP globally in Windows, the path of the PHP has to be set.
- Right click on Computer and click Properties.
- Click on Advanced system settings on the left side (top).
- Click on the Environment variables.
- Under System variables, double click the Path variable name and add ;d:\etc\php without double quotes at the end where semicolon ( ; ) is the separator.
- Click OK to save. Sometimes you may need to restart the computer this to take it into effect.
Install Apache as Service
Since we have just copied the files in a folder, the Apache is not yet not a windows service. To install it as a service follow the steps.
- Run the command line (cmd.exe) As Administrator. Browse the folder c:\Windows\System32\ and right click on cmd.exe and select Run as Administrator.
- Change directory to d:\etc\apache\bin in the command line
- Run the command to install it
Now restart the computer and test both PHP and Apache. To test both together create a PHP file phpinfo.php in d:\etc\www. Now browse in the browser as http://localhost/phpinfo.php.
If you can see the PHP information then now you are done !
I am sorry if there are any language issues (due to weak English correct words, grammar mistakes) but I believe that it is understandable. I had also posted it in my blog. Also please suggest if I have made any mistakes or written something wrong, I would be grateful to you.