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.

No comments:

Post a Comment