Magento 1.3 on php 5.5

After I got Git working last week, I had to get Magento 1.3 up and running on my development server.

Magento 1.3 was released in March, 2009. A lot has changed since then. (The current version of Magento is 1.8.)

My development server runs php 5.5.5. Magento 1.3 runs on php 5.2.

I didn’t want to roll my development server back to php 5.2. I’ve got other things I need to develop that aren’t stuck in 2009.

Getting this to work isn’t obvious. It took a bit of searching and trial and error. All of what follows is available on the Magento Forums. It’s not all together in one place, though. This post is so I’ll remember how to do it next time, and for the next person (if there ever is one) who needs to get Magento 1.3 going with a more up-to-date php version. It worked for me. It doesn’t come with any warrantee that it’ll work for you.

  • Step 1. Fix the Fatal Error.

When you first install Magento 1.3 and try to run it (go to your installation’s URL), you’ll get a fatal error:

Fatal error: Method Varien_Object::__tostring() cannot take arguments in /path/to/magento/lib/Varien/Object.php on line 488

Why? Because php 5.2 (and lower) allowed you (and Magento) to pass arguments to __toString(). Starting with php 5.3, you can’t do that. Fortunately, you don’t have to know or care what __toString() is to fix the problem. You’ll need to change two files.

In the lib/Varien/Object.php file, find the line (around 484) that reads

public function __toString(array $arrAttributes = array(), $valueSeparator=’,’)

Change __toString to __invoke, (that’s two underscores before the word) leaving the rest of the line the same.

(Note: __invoke() is not available before php 5.3, so if you save this back to a server still on 5.2 or lower, it’s going to bork. See the Extra Bonus Tip below about not transferring configuration files back to your staging/production servers.)

Next, in  /app/code/core/Mage/Core/Controller/Request/Http.php, find the line that reads

$host = split(‘:’, $_SERVER[’HTTP_HOST’]);

Change split to explode, leaving the rest of the line the same.

  • Step 2. Fix the “Can’t retrieve entity” Error.

Now, if you try to load your magento installation in your browser you’re going to get another error:

Can't retrieve entity config: core/store_group

This error is caused by some library files that aren’t compatible with newer versions (5.3 or higher) of php.

To fix this, download a more recent version of Magento here.

Unzip the file and then go to the /lib/Varien directory of the new magento files. From that directory copy the entire Simplexml directory and use it to replace the /lib/Varien/Simplexml directory in the Magento 1.3 files. (Word to the wise: You might want to back up your 1.3 version of the Simplexml directory before you do this, just in case.)

  • Step 3. Clear the Cache.

Magento’s cache is in the /var/cache directory. There will be a bunch of subdirectories in there: Mage--0, Mage--1, etc. Delete them all. Don’t worry about it.

That should do it. Now you should get your Magento site’s home page when you load it in your browser.

Bonus fix. Database Error.

As it turns out, I had a third error come up:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '16267977' for key 'PRIMARY'

Simply running repair table (use phpMyAdmin or whatever) on all the tables in the database (Again, make a backup, right!) fixed this for me.

Extra Bonus Tip. Ignore Configuration File Changes.

If you’re developing on Git (or anywhere else), you probably don’t want to commit all these configuration changes or push them back to the staging or production servers. (They’re probably still running php 5.2 or lower.)

You can’t make Git ignore them because they’re already being tracked. What you can do is tell Git to assume that they haven’t been updated.

For each file you want to ignore:

git update-index --assume-unchanged path/to/file.txt

If you ever need to change them back:

git update-index --no-assume-unchanged path/to/file.txt

Good luck.