Read Aaron Hawks' blog post for the original idea for this gist.
While this process should theoretically work to upgrade the core/default files that come with Magento from any old version to the most recent version (as long as they're in the same distribution, i.e., Community to Community or Enterprise to Enterprise), you should always refer to Magento's release notes and upgrade paths for the version you're upgrading to for full details and work flow. This is the process I used to go from Magento EE 1.12.0.2 to Magento EE 1.13.0.1 directly ( skipping over 1.13.0.0 due to the instructions outlined in this Magento article and release notes ).
Below is an excerpt of the pre-requisites I followed from Magento's upgrade instructions
This section discusses how to get ready for your upgrade by backing up the database and customizations on the file system. The steps that follow do not affect your current production system. You can continue serving customers with no downtime.
To get ready for your upgrade:
- Get the Magento installation archive as discussed in Getting Magento CE 1.8 or EE 1.13.
- Set up a parallel system for deploying and testing the upgrade; in other words, set up a system identical to the one you have now.
- The system must meet the Magento system requirements.
- Magento strongly recommends you observe the following guidelines when you set up the Magento database in your development environment:
- Magento for the first time uses MySQL database triggers to improve database access during reindexing. Magento does not support any custom triggers in the Magento database because custom triggers can introduce incompatibilities with future Magento versions.
- Familiarize yourself with these potential MySQL trigger limitations before you continue.
- If you use MySQL database replication, Magento does not support MySQL statement-based replication. Make sure you use only row-based replication.
- Review the MySQL recommendations for MySQL password security.
- Complete the tasks discussed in the following sections in the order shown:
Complete the tasks discussed in the following sections in the order shown:
- Enabling Exception Logging
- Setting All Indexers for Update on Save
- Backing Up the Database
- Archiving Customizations and Extensions
- Restoring Configuration Settings
Before you start your upgrade, you should enable exception logging so it will be enabled on the development system. Without exception logging, it will be more difficult to diagnose errors during your upgrade. You can disable exception logging after you've exported the Magento database.
To enable exception logging:
- Log in to the Admin Panel as an administrator.
- Click System > Configuration.
- In the ADVANCED group, click Developer.
This enables you to enable exception logging so you'll see exceptions in the development environment after the upgrade.- In the right pane, click Log Settings to expand it.
The following figure shows an example.
This section applies to Magento EE 1.13 only. Skip this section if you're using Magento CE.
Because of the changes to indexing in Magento EE 1.13, you must set all indexers to update on save before you upgrade; otherwise, unpredictable performance will result. You can revert indexer settings after you've exported the Magento database.
To set indexers to update on save:
- Click System > Index Management.
- On the top left corner of the row, click Select All to select all indexers.
- From the Options list, click Change indexing mode.
The Index Mode list displays.- From the Index Mode list, click Update on Save.
The following figure shows an example
- At the top right corner, click Submit.
- Make sure all indexers are now set for Update on Save as the following figure shows.
Back up your database using mysqldump or another tool. mysqldump
syntax follows:
# mysqldump syntax for large database dumps
mysqldump --opt -Q --order-by-primary -u root -p my_magento_db > my_magento_db_dump.sql
To archive your custom themes and extensions:
- Archive the Magento media directory and all subdirectories. For example,
cd magento-install-dir && tar -czf media.tgz media
- Archive any custom theme packages in the
magento-install-dir/app/design/frontend
andmagento-install-dir/skin/frontend
directories.
You may also need to check themagento-install-dir/js
directory for files related to local or community modules. - Archive any customizations or extensions in the
magento-install-dir/app/code/local
andmagento-install-dir/app/code/community
directories. - Transfer the archives you just created to the development environment.
- Copy magento-install-dir/app/etc/local.xml and magento-install-dir/app/etc/session.xml (if any) to your development upgrade environment.
After you've exported the Magento database and extensions, you can revert the configuration changes you made as discussed in these sections:
- Enabling Exception Logging
- Setting All Indexers for Update on Save (EE only)
Make sure that logging is disabled again when in the production environment
In your development enviroment:
- Start a new feature or topic branch in your version control system of choice. We use
git-flow
so you should do the following:
git flow feature start enterprise-1.13.0.1
and obviously replaceenterprise-1.13.0.1
name with an appropriate branch name of your choosing.
DO NOT EVEN THINK ABOUT DOING THIS IN THEdevelop
branch! IF you do, you are on your own for fixing whatever issues may come from it. Seriously. - Back up your development database. Refer to the Backing up the database section above or do something along the lines of
mysqldump --opt -Q --order-by-primary -u root -p my_magento_dev_db > my_magento_dev_db_dump.sql
- You may also consider setting up a new database that we'll import the production database into. It's up to and completely optional
Upgrade your Magento installation by completing all of the following tasks in the order shown:
- Upgrade Requirements
- Upgrading Assets on the Magento File System
- Upgrading the Magento Database
- Finishing the File System
Before attempting your Magento upgrade, complete all the tasks discussed in:
- Getting Ready for Your Upgrade (refer to the section towards the beginning of this gist)
- Getting Magento CE 1.8 or EE 1.13
Now comes the fun part of updating Magento's file system while avoiding overwriting your customizations and extensions. The easiest way I've found to do this is with Aaron Hawks' Creating a diff file to upgrade Magento blog post. Keep in mind that it's typically easier to upgrade if you have been good about updating with each release of Magento, but you may be able to jump a couple versions if it's safe to do so. Again, refer to Magento's upgrade path instructions for your version of Magento.
To create a diff file between two different versions of Magento you'll need to do the following:
- Make sure you have
diff
installed on your machine.- if you're using Linux or Mac OS X, you will most likely already have it installed
- if you're using Windows, let me google that for you
- Download clean copies of both versions
- Magento Community Edition Release Archive (click on the Release Archive tab to see available releases)
- Magento Enterprise Edition — either you or the client will need to have an account with access to Magento's Enterprise Edition download section.
- Un-zip and un-tar the files and optionally rename the directories
tar -zxvf enterprise-1.12.0.2.tar.gz
mv magento magento-1.12.0.2
tar -zxvf enterprise-1.13.0.1.tar.gz
mv magento magento-1.13.0.1
- Now you should have 2 directories... diff them and then you will have your diff file that we'll use to "patch" your Magento installation.
diff -ruN magento-1.12.0.2 magento-1.13.0.1 > enterprise-1.12.0.2-1.13.0.1.diff
- Next you are going to need to patch your current code using the diff file you just created and replace with the appriately named paths to your Magento project directory and diff file. Remember, this should be done in a feature or topic branch instead of your main branch (e.g.,
develop
).
cd /path/to/my/magento/project
patch -p1 < /path/to/my/enterprise-1.12.0.2-1.13.0.1.diff
If you created your diff file from two clean copies of Magento, then your patch file should only affect files/assets distributed by Magento and leave all customizations and extensions alone. You'll still need to test the upgrade, but we'll address that a bit later.
Before you import your production database dump into either your existing development database (which you should have backed up by now) or a new temporary development database you need to run a couple search and replace commands to set the unsecure web/unsecure/base_url
and secure web urls web/secure/base_url
(and any other config data that's specific to your project).
The following is perl's search and replace syntax. It's the quickest and easiest search and replace method I've seen or used so far.
Syntax:
perl -pi -e 's/oldstring/newstring/g' target_file
- The
s
tells perl we're doing a search and replace - The forward slashes
/
separate the strings we wish to search and replace from thes
command andg
arguments. Use back slashes\
to escape characters (i.e.,/ . : ? *
). - The
g
is the argument that tells to perl to do a global search and replace for the strings throughout the target_file - The
target_file
is the file you wish to make the changes to (e.g.,my_magento_db_dump.sql
)
Example:
perl -pi -e 's/http\:\/\/example\.com/http\:\/\/magex\.dev/g' my_magento_db_dump.sql
perl -pi -e 's/https\:\/\/example\.com/http\:\/\/magex\.dev/g' my_magento_db_dump.sql
It's important that you search for the full urls and not just the domain name or you will end up affecting email addresses as well.
You can now import your production database into the development database.
- Check your app/etc/local.xml still has valid connection parameters.
- Fix file permissions
find . -type f -exec chmod 644 {} \;
- Fix directory permissions
find . -type d -exec chmod 755 {} \;
- Make the
var
andmedia
directories and subdirectories world-writable
chmod -R 777 media var var/.htaccess
You should refer to the Magento directions for detailed instructions as that can vary from version to version. For example, read the instructions for Magento EE 1.13.0.1