Fool Proof Magento Upgrades

Never upgrade a live site. Never, ever, upgrade a live site. Seeing the dot com erroring out is one of the most stressful situations you can put yourself in. So don’t be an idiot. Work out a bullet proof upgrading strategy. Here’s one for Magento.

A lot of this is common sense, but it may be comforting to find a set of instructions that someone has already followed and tested.

The Environment I’m going to be upgrading a store running Magento 1.3 at http://www.example.com/magento_1-3 to Magento 1.4 at http://www.example.com/magento_1-4. For convenience I have a soft link from magento_1-3 -> magento at the moment.

Backing up files and your database When messing around on the command line, if you are not methodical in your approach then, you can end up doing something stupid. Take a backup of your files:

1
tar -czf magento_1-3.backup.tar.gz magento_1-3

and your database:

1
mysqldump -uusername -ppassword dbname > magento_1-3.backup.sql

and put them somewhere safe like your home directory, or even download them to your home computer. Don’t leave them somewhere web accessible.

Duplicate your current installation First duplicate the files.

1
cp -R magento_1-3 magento_1-4

Then duplicate the database.

1
2
mysql -uusername -ppassword -e "CREATE DATABASE `magento_1-4`"
mysql -uusername -ppassword magento_1-4 <magento_1-3.backup.sql

Don’t forget to update the paths in the database. Modifying the database manually is usually a big no-no, but this really is minor and so should be fine.

1
2
mysql -uusername -ppassword -e "UPDATE `magento_core_config_data` SET `value` = 'http://www.example.com/magento_1-4' WHERE `path` = 'web/unsecure/base_url'" magento_1-4
mysql -uusername -ppassword -e "UPDATE `magento_core_config_data` SET `value` = 'https://www.example.com/magento_1-4' WHERE `path` = 'web/secure/base_url'" magento_1-4

Point to the new database The first time I did this I couldn’t for the life of me figure out why the URLs hadn’t changed over, but the site looked perfect. We need to point Magento to the new database. We can do that by editing the app/etc/local.xml configuration file in the magento_1-4 directory. You’ll find the <dbname>database_name</dbname> tags there.

Check duplicate installation Try visiting http://www.example.com/magento_1-4 in your browser. Try logging into the administration area. We are just trying to work out if everything carried over fine.

Perform the upgrade You can either do the upgrade from the Magento Downloader in the administration area of the duplicated site, or you can do it on the command line.

1
2
3
cd magento_1-4
./pear mage-setup
./pear upgrade magento-core/Mage_All_Latest

Don’t worry about any long pauses, the pear client has a habit of hanging on me.

When I tried this the first time I kept getting conflicts (magento-core/Mage_Core_Modules cannot be installed, conflicts with installed packages), with output like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[nrj@eggbert magento_1-4]$ ./pear upgrade magento-core/Mage_All_Latest
magento-core/interface_frontend_blank requires package "magento-core/Mage_Core_Modules" (version >= 1.3.2.2, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.4.0.1
magento-core/Mage_Core_Modules cannot be installed, conflicts with installed packages
magento-core/Mage_All_Latest requires package "magento-core/Mage_Core_Modules" (version >= 1.4.0.1, version <= 1.4.0.1), installed version is 1.3.2.4
magento-core/mage_all_latest requires package "magento-core/Mage_Core_Adminhtml" (version >= 1.3.2.4, version <= 1.3.2.4), downloaded version is 1.4.0.1
magento-core/Mage_Core_Adminhtml cannot be installed, conflicts with installed packages
magento-core/mage_all_latest requires package "magento-core/Interface_Adminhtml_Default" (version >= 1.3.2.2, version <= 1.3.2.2), downloaded version is 1.4.0.1
magento-core/Interface_Adminhtml_Default cannot be installed, conflicts with installed packages
magento-core/mage_all_latest requires package "magento-core/Interface_Frontend_Default" (version >= 1.3.2.2, version <= 1.3.2.2), downloaded version is 1.4.0.0
magento-core/Interface_Frontend_Default cannot be installed, conflicts with installed packages
magento-core/mage_all_latest requires package "magento-core/Interface_Install_Default" (version >= 1.3.2, version <= 1.3.2), downloaded version is 1.4.0.1
magento-core/Interface_Install_Default cannot be installed, conflicts with installed packages
magento-core/mage_all_latest requires package "magento-core/Mage_Downloader" (version >= 1.3.2.1, version <= 1.3.2.1), downloaded version is 1.4.0.0
magento-core/Mage_Downloader cannot be installed, conflicts with installed packages
magento-core/Mage_Centinel requires package "magento-core/Mage_Core_Modules" (version >= 1.4.0.0, version <= 1.4.1, excluded versions: 1.4.1), installed version is 1.3.2.4
magento-core/Interface_Frontend_Base_Default requires package "magento-core/Mage_Core_Modules" (version >= 1.4.0.1, version <= 1.4.1, excluded versions: 1.4.1), installed version is 1.3.2.4
magento-core/Phoenix_Moneybookers requires package "magento-core/Mage_Core_Modules" (version >= 1.4.0.0, version <= 1.4.1, excluded versions: 1.4.1), installed version is 1.3.2.4
magento-core/mage_core_modules requires package "magento-core/Lib_Varien" (version >= 1.3.2.2, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.4.0.0
magento-core/Lib_Varien cannot be installed, conflicts with installed packages
magento-core/mage_core_modules requires package "magento-core/Lib_Google_Checkout" (version >= 1.2.0, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.4.0.0
magento-core/Lib_Google_Checkout cannot be installed, conflicts with installed packages
magento-core/mage_core_modules requires package "magento-core/Lib_Js_Calendar" (version >= 1.3.2, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.51.0
magento-core/mage_core_adminhtml requires package "magento-core/Lib_Js_Calendar" (version >= 1.3.2, version <= 1.3.2), downloaded version is 1.51.0
magento-core/Lib_Js_Calendar cannot be installed, conflicts with installed packages
magento-core/mage_core_modules requires package "magento-core/Lib_Js_Mage" (version >= 1.3.2.3, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.4.0.1
magento-core/Lib_Js_Mage cannot be installed, conflicts with installed packages
magento-core/mage_downloader requires package "magento-core/Lib_Js_Prototype" (version >= 1.3.1, version <= 1.4.0, excluded versions: 1.4.0), downloaded version is 1.6.0.3.0
magento-core/lib_js_mage requires package "magento-core/Lib_Js_Prototype" (version >= 1.3.2, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.6.0.3.0
magento-core/mage_core_modules requires package "magento-core/Lib_Js_Prototype" (version >= 1.3.2, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.6.0.3.0
magento-core/Lib_Js_Prototype cannot be installed, conflicts with installed packages
magento-core/mage_core_modules requires package "magento-core/Lib_PEAR" (version >= 1.3.1, version <= 1.3.3, excluded versions: 1.3.3), downloaded version is 1.4.0.0
magento-core/Lib_PEAR cannot be installed, conflicts with installed packages
magento-core/mage_core_adminhtml requires package "magento-core/Lib_Js_Ext" (version >= 1.0.18800, version <= 1.0.18800), downloaded version is 1.4.0.0
magento-core/interface_adminht ml_default requires package "magento-core/Lib_Js_Ext" (version >= 1.0.18800, version <= 1.0.18800), downloaded version is 1.4.0.0
magento-core/Lib_Js_Ext cannot be installed, conflicts with installed packages
magento-core/mage_core_adminhtml requires package "magento-core/Lib_LinLibertineFont" (version >= 1.1.1, version <= 1.1.1), downloaded version is 2.8.14.0
magento-core/Lib_LinLibertineFont cannot be installed, conflicts with installed packages
magento-core/lib_varien requires package "magento-core/Lib_ZF" (version >= 1.7.2.4, version <= 1.7.3, excluded versions: 1.7.3), downloaded version is 1.9.6.0
magento-core/Lib_ZF cannot be installed, conflicts with installed packages
magento-core/lib_zf requires package "magento-core/Lib_ZF_Locale" (version >= 1.7.2.2, version <= 1.7.3, excluded versions: 1.7.3), downloaded version is 1.9.6.0
magento-core/Lib_ZF_Locale cannot be installed, conflicts with installed packages
downloading Lib_Js_TinyMCE-3.2.5.0.tgz ...
Starting to download Lib_Js_TinyMCE-3.2.5.0.tgz (831,669 bytes)
.....................................................................................................................................................................done: 831,669 bytes
upgrade ok: channel://connect.magentocommerce.com/core/Lib_Js_TinyMCE-3.2.5.0

This can be avoided (and I can’t see any harm in avoiding it, we’ve got backups after all) by adding the –force switch to the pear client.

1
./pear upgrade --force magento-core/Mage_All_Latest

Check the upgrade worked The bulletproof way of checking that the upgrade worked is just to login to your administration area and check the Magento version at the bottom of the page.

Post-upgrade check list Now that your upgrade appears to work don’t rush into switching over just yet. It’s probably best to run through the key customer actions.

Then just before you launch.

Once you are happy you can remove the symbolic link from the old version of Magento to your new version by running the following.

1
rm magento && ln -s magento_1-4 magento

Voila.