2014-03-14

How to install PHP/Apache in windows?

In this article we are going to see how can we setup PHP environment in Windows PC. I will do that section-wise, so that if we follow steps, we can install in other versions of windows/Linux also.

Step 1 : Download PHP binaries : There are lots of PHP distribution, but I am going to use most popular sourceforge.net projects. So download the binary
a. XAMPP from this link or
b. WAMPP from this link
Here we get the main PHP binary but we do not need as both XAMPP and WAMP .

Step 2 : Extract Downloaded binary(or Install). If we Extract or install the downloaded item in a location to a drive,( I have located to D:\ drive ). We will get shortcuts of control pannel. If you do not get shortcut, you will find in D:\xampp\xampp-control.exe (for XAMPP)
and D:\wamp\wampmanager.exe (for WAMPP)

Step 3 : Run Control Panel : For XAMPP The control panel looks like this

And WAMP, control panel look like this.

We can start & stop services which are included in the control panel. Usually a both have basic Apache server hosted PHP, MySQL. XAMPP have some extra servers like fileZila, tomcat etc.

Step 4: Adding PHP to path variable: Go to Control Panel -> System -> Advance System Settings -> Advance -> Environment Variable. Now, in system variable section , double click path and add the location where the php.exe present in the end .


In my case, if it is XAMPP , I have to add  ;D:\xampp\php;
or if it is WAMP , I have to add ";D:\wamp\bin\php\php5.4.3;"

Step 5: Changing Default Port : Usually , windows have IIS running in the system in localhost in 80 port. So, if we try to run Apache, it will not able to run as the port is not free. So, we have to change  different port settings (which is 80) to any free port( I have used 8888 as Apache port) .
For XAMPP : Go to D:\xampp\apache\conf (Apache configuration folder) and open "httpd.conf" with note pad.

For WAMP: Go to D:\wamp\bin\apache\apache2.2.22\conf (Apache configuration folder) and open "httpd.conf" with note pad.

Now, for both case find this text "Listen 80" and "ServerName localhost:80" and change the ports to 8888.

 

Be careful here, the # sign refers to not active , so do not start those lines with #(it will not be active)

 
and change the port number 80 to 8888. 

Note : some time skype also occupy 80 port and Apache could not run, from XAMPP, we can check current port status by clicking  "netstart"(previously port check)

When we change the port, we have restart Apache server. 

Step 6: (optional) : Locating PHP to  IDE: I am using PHPStorm as my IDE. To show IDE , we need to locate the PHP.exe path to IDE.
From PHP storm,  Go to File -> Settings . Select PHP and select which version to run( I am using PHP 5.5) .

And, now select PHP interpreter. So we have show the location where is our php.exe is present.
So, if we use XAMPP in the system it will be "D:\xampp\php",
if it is WAMP, it will be "D:\wamp\bin\php\php5.4.3"

Now, select OK , OK to apply Changes.

So, we are done. We have successfully installed Apache with PHP in our system . We can also make Apache to run at start up of windows (as service) from XAMPP/WAMP server control panel.

Thanks..:)