Good day to Amasty blog readers! Today I’m speaking on a topic our team had many requests for: how to upgrade your Magento store correctly?
We have been talking about the importance of upgrading software a lot; it is crucial both for your server software and your Magento installation. Regular Magento updates bring you not only the new features but also security fixes, which is highly important for your Magento store’s safety.
Say, you see that your Magento version needs an upgrade. It’s hard to guess which version you have now, but we hope it’s 220.127.116.11 at least.
1. Prepare for Magento upgrade
To make the process more vivid we installed a shop on Magento 18.104.22.168 with sample data and we are going to upgrade it to 22.214.171.124, which is the latest stable Magento version as of this writing.
The website is installed into /home/mgtest/public_html, the database is on localhost and is called mgtest_magento. So if you use the instructions from this article, make sure you replace these values with your own ones.
2. Full Magento backup
This rule refers not only to upgrading Magento, but to any serious changes you’re going to apply on your website.
Backup your Magento store!
This is an essential procedure which saves you from unsuccessful updates, site breakdowns, data loss and makes sure the update won’t drive you up the wall.
The simplest variant of Magento backup can be implemented using these two commands:
tar -czf ~/magento-files.tar.gz -C /home/mgtest public_html mysqldump --add-drop-table -h localhost -u mgtest -p mgtest_magento | gzip > ~/magento-db.sql.gz
Please feel free to read a detailed article on Magento backup.
In case your Magento version update goes wrong, you can easily roll everything back:
cd /home/mgtest mv public_html public_html-BAK tar -xzf ~/magento-files.tar.gz gzip -dc ~/magento-db.sql.gz | mysql -h localhost -u mgtest -p mgtest_magento
3. Check system requirements
Check if your server suits minimum system requirements of the Magento version you’re upgrading to. You may want to have a look at the PHP version (5.4.x or 5.5.x is needed) and memory_limit value in php.ini in the first place.
4. Create a sandbox
Never ever update the primary website if you’re not 100% sure everything’s go. If you don’t test the update on a sandbox you won’t know if the website is going to work after the update and how much time the upgrading process will take.
Your store’s upgrade may require up to several hours, and there’s no point in shutting the primary e-shop down for the whole working day just to find out that the upgrade went wrong, the time’s lost and all you have to do is to restore the website from a backup copy. Also, remember that recovering from a backup copy takes more time than backing up itself, so count this time in.
To check if the update is going to run smoothly, let’s make a sandbox which we’re going to upgrade first. We have created an empty mgtest_staging database beforehand.
cd /home/mgtest mkdir public_html/staging tar -xzf ~/magento-files.tar.gz --strip-components=1 -C public_html/staging gzip -dc ~/magento-db.sql.gz | mysql -h localhost -u mgtest -p mgtest_staging
Now it’s time to set the sandbox up:
- Edit the database connection settings in public_html/staging/app/etc/local.xml
- Go to mgtest_staging database, find core_config_data table and change the website’s URL. Say, the old URL was http://mgtest.local/, then the new one will be http://mgtest.local/staging/
- If your Magento store uses Apache rewrites, then add RewriteBase /staging/ in public_html/staging/.htaccess
- Turn compilation off at System / Tools / Compilation
- Disable cache at System / Cache Management
Now the sandbox is ready to be upgraded.
5. Magento sandbox upgrade
Run the following commands in the console:
cd /home/mgtest/public_html/staging chmod +x pear ./pear mage-setup ./pear upgrade -f magento-core/Mage_All_Latest-stable chmod +x mage ./mage config-set preferred_state stable ./mage upgrade-all --force
If the previous command isn’t working, run this one:
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest --force
cd /home/mgtest/public_html/staging rm -fr var/cache var/session var/full_page_cache
To finish the upgrade magento version open the home page so Magento updates the database. This process can be lengthy, so consider doing it with the following command:
cd /home/mgtest/public_html/staging php -f index.php
6. Test, test, test
Carefully check how your website is working. Go to Magento logs at /home/mgtest/public_html/staging/var/log and to web server logs at /var/log/httpd, /var/log/apache2 or /var/log/nginx depending on the distribution kit and the web server you use. Carefully look through the logs to catch any possible errors.
Note: please make sure that you carefully test the performance of your extensions. If you upgrade to the latest and fresh version of Magento, the chance some extensions will work with errors or conflict with each other is rising, because not all Magento extensions providers test their modules right away after the release.
7. Primary Magento upgrade
If the careful research and testing didn’t reveal any malfunctions or you have found how to fix the errors, now it’s time to update the primary website. As the process of upgrade magento version and testing takes certain time, make a fresh backup copy of the primary website, because you don’t want to recover from an old backup copy and lose the latest changes. Before backing up switch your website to maintenance mode and disable cron.
touch /home/mgtest/public_html/maintenance.flag crontab -u mgtest -e
Save a backup copy:
cd /home/mgtest tar -czf magento-files.tar.gz -C /home/mgtest public_html mysqldump --add-drop-table -h localhost -u mgtest -p mgtest_magento | gzip > ~/magento-db.sql.gz
Repeat the Magento update procedure on your main website.
We do not recommend replacing the primary website with the sandbox store, as in that case you’re in risk of losing the data that was changed or added while testing.
Done! The last part is to turn the maintenance mode off and enable cron:
rm /home/mgtest/public_html/maintenance.flag crontab -u mgtest –e
Mission completed! Now your shop is updated to the latest stable Magento version.
Do you have any questions on Magento upgrade process? Welcome to the comments section.
Update: right now the instruction isn’t working because the http://connect20.magentocommerce.com/community link isn’t working and we couldn’t find the replacement of it in Magento docs. As soon as we find one, we’ll update the article.