L33t Links #35
- why i broke 89 tests
- RoboZZle, robot-programming game
- Let a human test your app, not (just) unit tests
- The Crapware Con
A couple of weeks ago I was forced to getting Magento, an open source e-commerce platform written in PHP, up and running on 5.3 which Magento isn’t natively compatible with. After hours, and even days, of hard work I got it running with only minor issues, so for future reference I’m posting the steps I followed here. Now you may be wondering how this could ever belong on a blog about Ruby and Rails, but the guide is also intended to remind you not to return to PHP ever. Magento as a system and PHP as a language have been one of the most painful technical experiences of my entire life.
After having installed XAMPP, extract magento-1.3.2.3.zip into C:\xampp\htdocs and start Apache and MySQL using the XAMPP Control Panel. Now head to http://localhost/magento and congratulations: You’re looking at your first obscure error:
Fatal error: Method Varien_Object::__tostring() cannot take arguments in C:\xampp\htdocs\magento\lib\Varien\Object.php on line 488
But have no worries, the fix is easy. Open C:\xampp\htdocs\magento\lib\Varien\Object.php in your favorite text-editor. On line 484 the definition of the function __toString() begins. Rename that function to __invoke() and go back to your browser and hit refresh. A new error will appear, but this time wrapped in a basic Magento layout. Progress.
Unknown error (8192): Function split() is deprecated in C:\xampp\htdocs\magento\app\code\core\Mage\Core\Controller\Request\Http.php on line 274
The thing is that in PHP 5.3, split() was deprecated in favor of explode(). They used to be aliases so once again the fix is easy. Go to the file and line in question and replace split with explode. Now go back to the browser and hit the back button to get away from the error submission form. Then refresh.
You should see a welcome message and text area containing the terms and conditions of Magento. But before you agree to them and click continue, unpack magento-sample-data-1.2.0.zip that you downloaded previously to an arbitrary location. Navigate to http://localhost/phpmyadmin and create a database named “magento”. Click the import tab and select magento_sample_data_for_1.2.0.sql. After the 1487 SQL queries has executed successfully it’s time to do something dirty.
The thing is that Magento has it’s own sort of migrations, but they can’t run on our version of PHP. Since we just imported the sample data into our database, which includes all the tables Magento needs, all we need is a way to skip the migrations. Open C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\Resource\Setup.php and comment line 121 out using //.
With that done it’s time to continue. After adjusting the localization settings you may encounter another error:
PHP Extension "curl" must be loaded
Obviously we just have to enable the curl extension. Open C:\xampp\php\php.ini and remove the semicolon at the beginning of the line saying ;extension=php_curl.dll, then restart Apache using the Control Panel. Switch to your browser and click continue. What you see is the configuration screen of Magento. Change whatever you want to change (not the database name and table prefix, though). In specific, I recommend enabling the “Use Web Server (Apache) Rewrites” option for prettier URLs.
The next screen lets you create an admin account. When you’re done, click continue. You should see a message telling you that “you’re all set” and an encryption key. Let this be a word of warning: If you loose your encryption key you’re on your own. Copy it to a safe place and click “Go to Backend”. Log in and observe a familiar error; you should know how to fix it. You may encounter it again as you browse the admin section of Magento.
Congratulations. Magento is up and running with an incompatible version of PHP. I hope this has taught you a lesson. Stick with Rails. No seriously.