Wednesday, May 6, 2015

How To Install Apache And PHP On Windows 8

Copyright 2015 Albert E. Benjamin

I've been trying to install the Apache web server and the PHP scripting language on Windows 8.

 I've installed both of these on Windows XP, and Windows 7 without any problems, but I had a lot of trouble installing them on Windows 8 (8.0 , I never upgraded to 8.1), although I finally got it done. Don't worry about the version though. I don't see any reason why this won't work on Windows 8.1, since neither Windows or Apache or PHP was the problem. The problem was bad instructions,everywhere !

 I spent about 6 hours a day for the better part of a week looking for, and trying advice from a multitude of sources on the internet, and I'm sad to say, not one of these solved my problem.

 So I want to share my solution here, so that hopefully, no one else has to go through this nightmare. So let's get started.


Step 1:


 Download and install "Visual C++ Redistributable for Visual Studio 2012 Update 4" from: http://www.microsoft.com/en-us/download/details.aspx?id=30679
It will normally install itself without any fuss.


Step 2:

 Download PHP 5.6.8 " VC11 x64 Thread Safe" from: http://windows.php.net/download/ Also download the "Debug Pack". Do not install at this time.
 You may notice that it says " Note: x64-builds are currrently experimental ". If you are uncomfortable with this, then download PHP 5.6.8 " VC11x86 Thread safe" instead.


Step 3:

Download "Apache 2.4.12" from:  https://www.apachelounge.com/download/
Do not install at this time.
If you downloaded the x64 version of PHP, then download:

          Apache 2.4.12 Win64" (httpd-2.4.12-win64-VC11.zip)

 If you downloaded the x86 version of PHP, then download:

         Apache 2.4.12 Win32" ( httpd-2.4.12-win32-VC11.zip) .

These will be the first two downloads you will see on the page.

 

Step 4:
 Click on the downloaded Apache  folder. It should be a folder Icon with a zipper, and when you click it, it will open a file explorer window.
 At the top of the window select "Extract All". This will open a dialog box which will show you where the folder will be extracted, and give you the option to change that location. Change the location to "C:"  and extract the folder. It should create a folder on your hard drive named "Apache24" .  So you should have C:\Apache24 .

Step 5:
  Extract  the downloaded PHP folder to C: in exactly the same manner as you extracted the Apache folder. Now rename the extracted php5.6.8 folder with it's long name to simply "PHP" . You may get a warning stating that changing the folder name may cause the program not to work. Go ahead and change the folder name.                  

 
Step 6:

Now we need to edit the "path" enviornment variable in Windows 8. Swipe the right-hand side of your desktop to get to the "settings" gear icon. Click on this icon and select "Control Panel".

 Once you're in control panel, select "System" then click Advanced System Settings.

 Now click "System Properties", then click the  Enviornment Variables button.

Scroll down to find the "path" variable (Don't confuse with "PATHEXT"). Click on this variable to highlight (select) it, and then click the "Edit" button at the bottom of the window.
The Edit System Variable box comes up. In the box labeled "variable value", click on the text to highlight it, then hit the "Home" key on your keyboard to place your cursor at the beginning of this line of text. Using the right-arrow key on your keyboard, move all the way to the end of this line of text, then type a semicolon, followed by "C:\PHP" without the quote marks. Click "OK" and close all the windows/dialog boxes, and close control panel. Now restart your computer. When your computer restarts, you are ready to install Apache and PHP. 

Step 7:
Now navigate to your PHP folder and find the files:
      "php.ini-development" and "php.ini-production"

If you are new to PHP and aren't sure how you want to use it, choose "php.ini-development" ,you can change it to "production" at any time.

If you are seriously developing a project, choose "php.ini-production".

Change the name of your chosen file to "php.ini"

Don't make any other changes to PHP at this time. 

Exit the PHP folder.

Step 8 (Install Apache): 
Go to the "Start" screen and find the command window icon. Right-click it and select "Run As Administrator". Change directory by typing "cd C:" or "cd.." in the command window. If "cd.." doesn't take you to C:, the repeat the action. When you have the C:\> prompt , then type "cd Apache24". Now type "cd bin". The prompt should now read "C:\Apache24\bin>" Now type httpd -k install  . Apache should install smoothly unless it can't bind to (use) port 80, in which case you will have to go into Windows Firewall and allow Apache through the firewall. That's a subject I'll have to cover in another post.

Close the command window and navigate to the Apache24 folder on your hard drive. Open the folder and then open the "bin" sub-folder. In the "bin" folder, double click "ApacheMonitor" . You should now see one of the following icons in the taskbar:
       or --------------->


You should see the icon with the green arrow inside it. This means that Apache is working.


Now click on the Apache feather icon to turn off Apache. When the center of the icon turns red, Apache is turned off.

Step 9:
Navigate to the Apache24 folder, then open the "conf" sub-folder.
Open the file named "httpd". Scroll down the file until you see a bunch of lines that begin with "LoadModule". Scroll to the end of these, and immediately after the last one type:

LoadModule php5_module "C:/PHP/php5apache2_4.dll" 

Now scroll to the very bottom of the page and below everything else on the page, type:

AddType application/x-httpd-php. php   Be sure to leave a space between the "php." and the second "php"  .

Next, type:  PHPIniDir "C:/PHP"

Now save the file and restart Apache by clicking the feather icon.

Step 10:
Now you can test PHP by writing a simple script as follows, and placing the script in the Apache/htdocs folder.

Write the following PHP code in a text editor such as "notepad" :
    
           <? php

                Echo "Hello world";

           <?

Save it as "hello.php" and place it in the Apache/htdocs folder.
Now open your browser and type " http://localhost/hello.php " without the quote marks.
If you see just the plain text: Hello World, then PHP is working. if you see the PHP tags 
( <?php  and ?> ) something's still not working.

Step 11:

 Now you will want to edit your PHP configuration file to turn on the PHP features you want. The configuration file should be named simply "php", and have a gear icon.There are 3-files in my PHP folder named "php, but they have different icons, so be careful to choose the one with the gear icon.

 
Well I hope this works for you as well as it has for me. Thanks for reading.


Albert Benjamin

Ketonetic

 



 











No comments:

Post a Comment