Nick Jones

a magento developer at Meanbee (@nickj89) and uk magento expert based in Bath

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:

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

and your database:

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.

cp -R magento_1-3 magento_1-4

Then duplicate the database.

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.

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.

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:

[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.

./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.

  • Can a customer login?
  • Can a customer register?
  • Can a customer add a product to their basket?
  • Can a customer checkout?

Then just before you launch.

  • Switch caching one (and prime)
  • Enable compliation

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

rm magento && ln -s magento_1-4 magento

Voila.

14 Responses to Fool Proof Magento Upgrades

  1. Pingback: Magento including Javascript by System path | Nick Says

  2. Will says:

    hi,

    I am using Magento 1.3.2.3 and am being asked to update to 1.4.0.1 but am worried that if i update it will reset all my e-mail templates back to default (read it in a blog), reset any changes to files i made in default theme folder even though i am using a different theme and i am worried it will change my setting in configurations settings like paypal etc. It took me ages to get everything setup and working. I am also worried some of my extensions will not work with update.

    Please give me some help.

    Thanks

  3. martijn says:

    Great tutorial. I have one questoin though: When having a live website people will continue to order on this website. Meanwhile i'm upgrading on a dev site. So you have a difference in the live website and the dev website. How do i sync the old and new database? Can you just copy the database again? If so how do you manage to upgrade the database?

    • Nick says:

      Ah.. that, I did not consider. Assuming the changes are design only, I'd go through the upgrade steps again. If they were CMS pages, etc, then I'd first upgrade the site (making sure that the design works ONLY), then I'd do the page creation and updates on the live site.

      A tool to do this properly would be quite nice.

  4. Brian says:

    One thing to add:
    Before the 'Check duplicate installation' delete the var/cache folder in the new site.
    Otherwise… all the links and admin log in might still point back to the old site

    • T | says:

      Thanks for this little guide … and a remark.

      You may have a /tmp/magento/var/cache in addition to $magentodir/var/cache which, undeleted, will create some very weird results. Usually this happens when the /var/cache directory is not writable by the web server, but I had current files in both of them …

  5. Sergey says:

    Hey Nick,

    I've done everything you said twice and getting this error SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'core_variable' already exists

    Any ideas?

    Sergey

  6. kyle says:

    mysql -uusername -ppassword -e "UPDATE `magento_core_config_data` SET `value` = 'http://www.example.com/magento_1-4&#039; WHERE `path` = 'web/unsecure/base_url'" magento_1-4

    make sure you put the / at the end of your base_urls in the databse ;)

  7. adam says:

    hey nick
    this worked wonders for me, i;'ve inherited a magento 1.1.8 install i need to upgrade the theme for.
    The back up finally worked a treat, after i'd worke dthrough all the magento code for depricated calls.
    Shame to upgrade to 1.4 it seems i must install 1.2/1.3/1.4 consecutivley and use the admin back up system any help or advise woudl be appreciated.

  8. Gavin says:

    Hi Nick,

    I've done this a few times and its worked great but on a few occassions, the root site has upgraded which has resulted in a 'complete magento download' installation screen??

    Is there somewhere in the .pear installation files that point to the root?

    In my case i did
    http://www.livewebsite.com
    http://www.livewebsite.com/upgradefolder/

    I ran ./pear mage-setup and upgrade on the /upgradefolder/ which contains an exact copy of the root website, a copy of the database and all the core-config paths updated to be http://www.livewebsite.com/upgradefolder/

    any ideas?

  9. Gavin says:

    yes, i'm pretty sure it exists as I made a straight copy of the public_html folder into /upgradefolder/

    I'm just about to do another upgrade on a site, I'll let you know if I get any other strange results.

  10. izzyb says:

    Hello Nick,

    Great article. A couple of questions:
    1. Would this work on a hosted solution as well? Or would you recommend some changes?
    2. I have a 1.3.1 version that I would like to upgrade to 1.6.1 – what would be the best way of doing that?

    Thanks

  11. Coop says:

    I tried to follow these instructions and basically found that any link that i have on the duplicate site (a subdomain) points right back to the regular domain's store/database. I even updated the config.xml file to use the backup database and the core_confi_data to point to the subdomain with no luck. Do you have any suggestions on a possible fix for this so i can atleast try to apply the upgrade?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">