Sunday, May 31, 2015

PHP Not Loading Extensions


Before you drive yourself nuts looking for a solution and getting confused by all the advice on forums, you need to understand that the problem may be with the PHP organization itself. Though PHP is a great language, I have found on numerous occasions, that the PHP organization (php.net) has terribly inaccurate information.

Here's some examples:


  • Back in the day of PHP 5.2.17, the PHP website stated “Do not use with VC9 version of Microsoft C++”, but guess what, I did, and it worked flawlessly.
  • Today, with PHP 5.6.7, the phpinfo() function identified my intel Core i5 CPU as an AMD64 CPU. 
  • With PHP 5.6.7, phpinfo() listed the path to my php folder as C:\php, even though I had named the folder “PHPx64” and listed it as such in the windows “path” and “PHPRC” enviornment variables, as well as the Apache “PHPIniDir” directive, and, of course, the php.ini configuration  file.
  • Also phpinfo() stated that no php.ini configuration file was loaded. And yet, the PHP core still worked, though it just wouldn't load any extensions.


So, I went back and changed the path to my PHP folder to “C:\php”, in every applicable place (Windows “path” and “PHPRC” enviornment variables, php.ini configuration file, Apache “PHPIniDir” directive, Apache “LoadModule” directives). 
Now phpinfo() shows that my “php.ini” configuration file is loaded at “C:\php\php.ini”. That's one step forward, but PHP still won't load any extensions. 

Now most of the PHP extensions are in the “php/ext” folder, and I had listed “php/ext” as the path to the extensions in all the appropriate places, but this had no effect,and PHP would not load extensions. So I reverted to “C:\php” as the path to the extensions, in every place except the “extensions_dir” directive in the “php.ini” config. file, this I set as “C:\php\ext”, which is what I had originally set it to, but extensions weren't loading so I set it to “C:\php”, but that didn't work either, so I just reverted back to “C:\php\ext”.

Anyway, here's the settings that finally worked:

PHP folder name: “php” in lowercase. PHP 5.6.7 doesn't seem to recognize anything else.

Windows “path” and “PHPRC” enviornment variables: “C:\php” . Note: You will have to create the “PHPRC” enviornment variable, it does not exist. Go to “Settings”--> “Control Panel” → “System” → “Advanced System Settings”. At the lower right-hand corner of the “System Properties” box click on “Enviornment Variables”. In the lower box, called “System variables”, click on “New”. Enter the name “PHPRC” and the value “C:\php” .

In your Apache/conf folder, open the configuration file named “httpd” and add “LoadModule” directives to load the PHP extensions you want to use. The scroll to the very bottom of the page and write: 

          AddType application/x-httpd-php .php
                ( Make sure there's a space between “php” and “.php” )

          PHPIniDir "C:/php"


In your php folder, open the configuration file named “php” (note it may not have the “.ini” extension). Look to the right of the filename and make sure it says “configuration Settings”. Scroll down until you see this heading:
                                        ;;;;;;;;;;;;;;;;;;;;;;;;;
                                        ; Paths and Directories ;
                                        ;;;;;;;;;;;;;;;;;;;;;;;;;

              Now scroll slowly until you see this section:

                                         ; Directory in which the loadable extensions (modules) reside.
                                         ; http://php.net/extension-dir
                                         ; extension_dir = "./"
                                         ; On windows:
                                           extension_dir = "C:\php\ext"

 Set “extension_dir” to “C:\php\ext, as shown above, and remember to remove the  semicolon from the beginning of the line.


   And that's it . I hope this works for you as it did for me. Thanks for reading.

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

 



 











Monday, May 4, 2015

Will Not Load " php5apache2_4.dll " on Windows 8

Copyright 2015 Albert E. Benjamin

If you install apache in a command window, you will get an error message stating that "php5apache2_4.dll is not a valid win32 application". This is usually caused by not having matching versions of PHP and Apache.

First, determine whether your Windows system is actually 32-bit or 64-bit. To determine this, go to "Settings---> "Control Panel"---> "System"---> :"System Information".

After you determine whether you have a 32-bit or 64-bit system, then download the appropriate PHP and Apache versions.
     For 32-bit systems:  PHP5.6.xVC9x86.  and Apache apache2.4.xVC9x86.
     For 64-bit systems: PHP5.6.xVC11x64 and Apache 2.4.12VC11x64.

Also, they must both be either "Thread Safe" or "Non-Thread Safe". 

Note that the PHP site (php.net) states that the 64-bit versions are experimental. If you're uncomfortable with this, then download the 32-bit versions of both Apache and PHP.

Also, I recommend the binaries from "Apache Lounge".