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


3 Responses to “Running osCommerce on PHP 5.2.1”

  1. Alex Says:

    Additional comments

    – You need to leave the associaton of the .php extension with the php application in the Apache 2.2 httpd.conf file otherwise Apache will be unable to know how to handle PHP files

    – SNIP –

    ScriptAlias /php/ "c:/php/"
    AddType application/x-httpd-php .php

    – SNIP –

  2. jetty Says:

    Hi, thanks for your blog.

    And I have done what you said, but the problem is still occurred on step 2 durning the installation. No action is executed when I clicked “continue”.

    My PHP is 5.2.1 and my MySQL is 5.0.37...

    I wrote a testdb.php to test the database connection, It’s OK.

    So, what is the problem?
    Any advice is helpful, thank you.

  3. jetty Says:

    …The problem is that osc used the old long array for post data…

    turn on the php value register_long_arrays, everything will be fine.

    Done.

Leave a Reply