PHP unable to load dynamic library php_openssl.dll

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\ext\php_openssl.dll' - The operating system cannot run %1.
Windows, Apache, PHP, and OpenSSL. An error! How do you fix it? Real answers and you get to choose the easiest way for you.

You install Apache and PHP under Windows then hit this error message. Perhaps you use PHP under Apache happily for years then switch on SSL and hit the error. Pain. We will look at the error message than track back to the cause then hit some real easy solutions.

PHP Warning To PHP it is a warning message. To you it is critical because you cannot use SSL. You would not have switched SSL on if you did not need it. The warning bit is because the OpenSSL code is giving the wrong response to PHP.

PHP Startup PHP hits the error when PHP starts. PHP starts when the Apache Web server starts. If PHP things it is a warning instead of an error, PHP continues on and tells Apache to continue. You have to stop Apache, fix the problem, then start again.

Unable to load dynamic library Windows calls them DLLs. Linux and Unix use other names. PHP loads first then reads php.ini to see what other code is needed then loads DLLs based on the setting in php.ini. In Windows XP Pro, php.ini is in C:\Program Files (x86)\PHP and can be read by any text editor.

I recommend Bluefish as a Web related editor because you can use the same editor on both Windows and Linux. Bluefish will also recognize the different line endings across files from different operating systems. The Windows editors might bunch all the lines up together if they do not get Windows style line endings. If you use Java, bah choke spit Oracle proprietary, look at jEdit because it has better search facilities or Eclipse because it has more features than you will ever use in several lifetimes.

Look in php.ini for the line extension_dir="C:\Program Files (x86)\PHP\ext" or similar. This identifies the directory where your DLL extensions are stored. Look in that directory first for any missing extension.

While you are looking in php.ini, look for the line extension=php_openssl.dll. You found the line requesting the DLL. This line is created automatically by the PHP installation process. If you want to change the line up of modules, you can select PHP in the Windows Control panel then change the list of selected modules.

C:\Program Files (x86)\PHP\ext\ is the part of the PHP warning telling you where the DLL should be.

php_openssl.dll is the missing DLL. When you look for php_openssl.dll, you will find it is not missing because it was automatically installed by the PHP installation process or the change process, assuming you installed from the automatic installer.

The operating system cannot run %1. is just a distraction because you do not know what %1 means. %1 could be a program required by php_openssl.dll. The message is useless if it does not tell us what is really missing.

What has happened so far? Apache started PHP and PHP started php_openssl.dll then php_openssl.dll tried to load two modules, could not or found the wrong ones, then php_openssl.dll send a false message back to PHP about the problem being a warning, not a critical error, then PHP told Apache to go ahead without the missing bit.

What is missing or faulty? php_openssl.dll tries to load libeay32.dll and ssleay32.dll. They are in C:\Program Files (x86)\PHP. If they were missing, you would have a faulty installation. You can end up with a faulty installation if you use the .zip version of PHP instead of the full automatic install or you use one of those WAMP style packages for installing everything in one hit, those complete packages are not always complete and do not always check every combination of options.

The real problem with libeay32.dll and ssleay32.dll is that they are also in C:\Program Files (x86)\Apache Group\Apache2\bin. php_openssl.dll tries to use the Apache version instead of the PHP version and chokes on the old code. This happens with any version of PHP from 5.1 through to 5.3 when used with anything other than the most current Apache. Why would you use a new PHP with an old Apache? Some new version of Apache kill PHP and you have to go back to an old version of Apache. A few times I have had to jump from APache 2.2 back to Apache 2.0 to make PHP work.

You want the most modern PHP because life is better with the new features and all the security updates. Apache has not changed much, for our purposes, between 2.0 and 2.2. Using Apache 2.0 to keep PHP happy is equivalent to choosing a small friendly dog to live in your apartment. Going the other way and using the latest Apache then settling for an old PHP is equivalent to choosing a pitbull or a mastiff for a tiny apartment full of young children.

How much difference are we talking about in libeay32.dll and ssleay32.dll? My Apache has SSL modules from September 2007. The PHP is from July 2010 and contains SSL modules from November 2007.

Solutions

Yeah, I hate the marketing abuse of solution. Here are two fixes that really are solutions for some people. One or the other should work for you. Updating Apache is relatively easy and new versions include security updates, making the Apache update the preferred solution if it works for you.

Update Apache

When you update PHP, retry newer versions of Apache. You might get a newer version of the SSL code in Apache without installing anything that is so new, it breaks PHP.

A new version of Apache is unpredictable because it might contain an interface change and create a problem. You might not have a problem on one server because your site on the server does not use every part of Apache. Hundreds of your other sites might crash and burn because the change is in an area those sites use. I work on over 200 sites across a variety of servers, VPSs, test systems, Q&A systems, and customer configurations. Perhaps 20 out of 200 required a reversion to an older version of PHP at some stage. A very small percentage of those PHP reversions required an older version of Apache for compatibility. A few cases required a change from Apache 2.2 to 2.0 because a new version of PHP, or a module switched on in PHP, did not work with 2.2.

Copy libeay32.dll and ssleay32.dll

Copy libeay32.dll and ssleay32.dll from PHP to Apache, from C:\Program Files (x86)\PHP to C:\Program Files (x86)\Apache Group\Apache2\bin.

This is the easiest change but misses out on any other updates. Apache usually works with newer versions of modules. Your result might be different. Your Web site might use feature A, B, and C. An update might change B. Your testing might hit A and C many times but never B. One of your customers visits the site and selects something that uses B.

Conclusion

The error can be fixed easily with a manual change. Bringing your Web site up to date is more useful and should be done one day but is more work and requires extensive testing, something you should schedule for a quiet day with no distractions.