Tuesday, July 29, 2008

PHP Startup: Unable to load dynamic library --- Specified module could not be found.

Another WAMP error to deal with.

In this case, seeing the PHP error "Fatal error: Call to undefined function: mysql_connect() in some_random_script.php"

Turns out that under PHP 5, the MySQL libraries are no longer included by default. However, the installer package can add them in for you, no problem.

There are multiple reasons this issue shows up, and many of them are explained in the comments section of the official PHP Installation of Extensions on Windows page.

The problem is likely due to one (or both) of the following reasons: 1) You've had a previous installation of PHP or MySQL, and you have older .DLL files scattered about your hard drive, or 2) PHP doesn't know where to find the DLL's.

Here are the fixes:

For the first issue, remove the following old files from your Windows\System32 folder:

  • libeay32.dll
  • ssleay32.dll
  • libmysql.dll

You'll already have the newer versions of those file in your PHP installation folder.

The next step is to make sure that the PHP installation folder is in your system's PATH variable. It doesn't matter if you don't know what that means... simply follow these instructions:

  1. Bring up the "System Properties" window by either pressing Windows-Break on your keyboard, or by right-clicking on "My Computer" and selecting properties.

  2. Select the "Advanced" tab.

  3. Click the "Environment Variables" button at the bottom.

  4. Under "System Variables" at the bottom, scroll down to "Path" and click "edit".

  5. Look for the location of your PHP installation (something like C:\PHP, C:\Program Files\PHP or C:\Progra~1\PHP.

  6. If you don't see your PHP installation folder, add a semi-colon ";" and then the folder of your PHP installation folder.

  7. Close out of all those windows and reboot

Note that this will not fix things until you reboot. As far as I know, there's no way to get Windows to reload the System Variables without a reboot.

Thursday, July 24, 2008

Apache vs. Skype

After upgrading my my PHP installation from 4.4.6 on my windows box to 5.2.6, Apache wouldn't start.

I finally determined that it was because Apache was still trying to load the old PHP4 SAPI module, which no longer existed because I renamed the old PHP4 directory.

So after fixing this, Apache should fire right up, correct? Not so fast... I received another error:

(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. :make_sock: could not bind to address 0.0.0.0:80

Okay, so something else has bound itself to port 80? Why all of the sudden? I didn't have this problem before I upgraded to PHP5, and I know that it's not binding to any ports...

So what's up?

A quick netstat -ao shows me the processes that are bound to each port (the -o option shows the PID). I fired up task manager (make sure that you have the "PID" column checked under "View / Select Columns...") to see who the culprit was ...

... Skype.

So here's the problem (and solution)...

Apparently, my Apache service has been starting up before Skype loads, claiming port 80 (and 443) for itself. When Skype finally loads, it gets a clue and binds to a different port.

But this time, because Apache wasn't able to load (because of my missing PHP4 module), ports 80 and 443 were still available when Skype loaded up. And Skype grabbed them up for itself, which, of course, causes Apache to fail.

Problem is fixed easily by shutting down Skype, re-starting Apache, then re-loading Skype. If Apache loads without problem after a reboot, this shouldn't ever be a problem.

However, if Apache does fail at some point in the future, we don't want our troubleshooting process bogged down with having to figure out the Skype problem again, so let's tell Skype to leave our ports 80 and 443 alone.

Load up Skype, and under Tools -> Options... -> Advanced -> Connection -> uncheck "Use port 80 and 443 as alternatives for incoming connections"