Tuesday, April 10th 2007


Running osCommerce on PHP 5.2.1
posted @ 8:03 am in [ Apache -osCommerce -PHP -Technology ]

We use a lot of osCommerce in our client projects as it is one of the most advanced Open Source e-commerce systems available on the market today, and best of all we can share the code with our clients without them having to pay costly licensing contracts or even worse, cough cough, being tied in to a 3 year monthly fee contract like some other vend(or/a)s do in our market.

So, with a recent upgrade to PHP 5.2.1 on one of our development servers, osCommerce ms2.2, the best core release of the platform, refused to play ball having largely been tested and developed for PHP 4. Not to fear though, with a bit of research and a few tweaks we were able to get it up running.

1. Running your PHP as a Module rather than a CGI on Windows

In order to allow PHP local variables to be set, rather than just global ones, you have to run your PHP within Apache as a Module and for mySQL to work download and install the extra libmysql.dll from the mySQL homepages.

As we are now running PHP as a Module, rather than a CGI, it no longer automatically includes the working directory the executable is in (normally c:\program files\php-5.2.1\ or similar) so simply placing this file in that directory, as we used to do, works. You need to either add this directory to the PATH environment in Windows, or copy the libmysql.dll to the Windows/System32/ directory or similar.

Then modify your httpd.conf to include the following

#BEGIN PHP INSTALLER EDITS – REMOVE ONLY ON UNINSTALL
PHPIniDir “C:\\Program Files\\php-5.2.1\\”
LoadModule php5_module “C:\\Program Files\\php-5.2.1\\php5apache2_2.dll”
#END PHP INSTALLER EDITS – REMOVE ONLY ON UNINSTALL

For the php.ini uncomment the mySQL module needed (remember you need to download the extra Module DLLS for PHP 5.2.1 for this to work and path the Module directory correctly)

extension=php_mysql.dll

and

; Directory in which the loadable extensions (modules) reside.
extension_dir =”C:\Program Files\php-5.2.1\ext”

2. Modifying the local environment variables for PHP

In your working directory, create a new .htaccess file and assign the following PHP parameters within it

php_value register_globals on
php_value register_long_arrays on

3. Restart everything

Restart Apache to pick up the new PHP configuration, and then run a quick phpinfo(); in a test PHP file to check that the local values for the two variables above are set.

And.. you should have a running osCommerce MS2.2 on PHP 5.2.1 and Apache 2