The complete Magento upgrade guide

Posted: November 9th, 2012 | Author: | Filed under: Magento, MySQL, PHP | No Comments »

After having upgraded several Magento sites and having read alot of online upgrade guides, I decided to write my own manual. Many people search for how-to’s for specific Magento versions, but it actually doesn’t really matter what version of Magento you are upgrading. The only difference is that you need to upgrade to 1.4.2 if you are running a version below that. Magento stopped using PEAR as of version 1.4.2.

Preparations

First of all, backup your production site and create a staging environment. After setting the new database connection in app/etc/local.xml, manually change the website urls in the database:

UPDATE
   `core_config_data`
SET
   `value` = REPLACE(`value`, "//www.yourwebsite.com", "//staging.yourwebsite.com");

Now login to the new staging Admin panel and disable all cache under Cache Management and delete the var/cache and var/session folders in your root directory. It is important to clean up and reduce the size of the database before we start the upgrade process, since large databases take forever to upgrade and corrupt databases can cause headaches when debugging.

If you have the Magento Compiler enabled, run the following commands to remove all compiled files and to disable the include path.

$ php shell/compiler.php disable
$ php shell/compiler.php clear

Make sure that the staging website maintains all proper file and folder permissions. If this is not the case you can reset them by following this guide.

Cleanup the database

Since Magento logs alot, let’s clean up a bit first. Enter the following command to view how much data Magento has been logging until now.

$ shell/log.php status

This displays the size of the `log_` and `report_` tables. If you haven’t enabled Log Cleaning in the Magento Admin (System > Configuration > System > Log Cleaning), this can quickly grow to a couple of hundred MB or maybe some GB’s!
You can manually cleanup these tables by running this command:

$ shell/log.php clean

However there are more tables that can be emptied. You can safely run this query:

TRUNCATE `catalog_compare_item`;
TRUNCATE `dataflow_batch_export`;
TRUNCATE `dataflow_batch_import`;
TRUNCATE `log_customer`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `log_visitor_online`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `report_compared_product_index`;
TRUNCATE `report_event`;
TRUNCATE `sales_flat_quote_item`;

You could also truncate the `core_url_rewrite` table, which can grow pretty large too if you have alot of products and websites/stores-views. Attention: When emptying this you will lose all old url redirects for products, categories, cms pages, etc, but it greatly increases the speed of the upgrade process. Of course it is safe to do this when the website is not yet in production in the first place.

This should leave us with a pretty slimmed down version of the database.

Now reindex the database to be sure

$ php shell/indexer.php reindexall

Clear cache again if Magento somehow managed to create some (you can’t do this enough! :) )

$ rm -rf var/cache var/session

Important reminder: do not access the staging website in your browser! As this will initiate the upgrade process too early

Fix corrupt database (don’t skip this step!!)

Check for corrupt structure

It’s possible that the database structure has been changed after the moment is was installed, due to plugins or custom code. Magento has released a tool that can fix corrupted databases: The Magento Database repair tool. It adds missing table columns, foreign keys and indexes. Download the php script and upload it to the root of your staging website. Now create a fresh install of Magento of the same version as your current shop, so we can compare it’s database-structure with our staging database.

Run the tool and see if it makes some changes. If an error occurs, just run the tool again until it says there is nothing more to change.

Check for corrupt data

Besides the structure of tables, it’s also possible that some data is corrupted. I’ve had cases that duplicate order records existed that messed up the upgrade process. Run this query to find out whether there are duplicate records and delete them.

SELECT `increment_id` FROM `sales_flat_order` GROUP BY `increment_id` HAVING COUNT(*)>1;
SELECT `increment_id` FROM `sales_flat_order_grid` GROUP BY `increment_id` HAVING COUNT(*)>1;

More info on this can be found in this thread.

Personally I’ve never had other tables that contained duplicate records.

Upgrade the Magento core files

As mentioned earlier, if you are running Magento 1.4.1.x or lower you need to upgrade to 1.4.2 first.

$ chmod -R 777 lib/PEAR
$ ./pear mage-setup
$ ./pear upgrade -f magento-core/Mage_All_latest-stable
$ chmod 550 ./mage
$ ./mage mage-setup
$ ./mage sync

If pear displays errors, if may have to be upgraded.

$ ./pear channel-update pear.php.net
$ ./pear upgrade --force PEAR

Repeat this step if it shows any errors

The following steps apply to all versions of Magento (1.4.2 and higher) that want to upgrade to the latest stable version (currently 1.7.0.2). Reminder: unfortunately it’s not possible to upgrade to a version other than the latest release. If you really need this, you need to manually download the specific version of Magento and connect the older database to initiate the upgrade process.

View which packages can be upgraded

$ ./mage list-upgrades

Configure Magento to upgrade to the latest stable version, as we do not want a bèta version. (Bèta state is default!)

$ ./mage config-set preferred_state stable

Upgrade all packages! This will also upgrade any plugin installed via SSH if possible. Magento will replace all php files in the app/code/core and in the app/design/base/default map
Custom theme files and php files from app/code/local remain untouched!

$ ./mage upgrade-all --force

The filesystem has now been fully upgraded.

Upgrade the database

Since all package files on the server have been upgraded. Magento will check for version changes when a page is loaded in the browser. All packages will execute the upgrade php scripts which change the database structure. Now open the staging website in your browser and Magento will start the upgrade. You can monitor this progress via SSH:

$ mysql -h YOUR_DB_HOST -u YOUR_DB_USER -D YOUR_DB_NAME -p
> SHOW FULL PROCESSLIST;

Depending on your database size, this process can be ready in a few minutes or can take up a few hours. I usually like to refresh the processlist every 10 minutes to see what Magento is up to. If anything goes wrong, you’ll at least know where to look :) . It is important not to open the site in another browser during the process, so be sure that no-one else does too.

When the process is finished (no more activity in the mysql processlist), close the browser and clear cache.

$ rm -rf var/cache var/session

Finishing up

To be sure the database upgrade was succesful, run the Magento Database Repair tool again. Now you’ll need a fresh database of the latest Magento version to compare against, so create this first.
If the upgrade went ok, the tool shouldn’t find any differences.

The last step is to reindex everything again!

$ php shell/indexer.php reindexall

The upgrade is now complete! You can safely open the website in the browser and see if everything still works. Remember: All errors are almost always related to corrupt database structure, custom theme files, incompatible plugins or custom code (app/code/community and app/code/local).


IE, SSL and file downloads

Posted: June 21st, 2012 | Author: | Filed under: PHP | No Comments »

A small reminder for everyone developing applications using SSL (Secure Sockets Layer) for data encryption: When downloading files Internet Explorer has to use it’s cache in order to be able to open the file. http://support.microsoft.com/kb/316431 states:

In order for Internet Explorer to open documents in Office (or any out-of-process, ActiveX document server), Internet Explorer must save the file to the local cache directory and ask the associated application to load the file by using IPersistFile::Load. If the file is not stored to disk, this operation fails.

When Internet Explorer communicates with a secure Web site through SSL, Internet Explorer enforces any no-cache request. If the header or headers are present, Internet Explorer does not cache the file. Consequently, Office cannot open the file.

This means that IE should always be forced to cache the file before opening. In PHP this is achieved by sending the following HTTP headers,:

// Do not use header("Pragma: no-cache");
header("Pragma: private");
// Do not use header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: cache");

 


Remove admin-bar WordPress 3.1

Posted: March 18th, 2011 | Author: | Filed under: Wordpress | No Comments »

WordPress 3.1 is released and comes with many new features. One of them is the extra admin bar visible at the front-end of your website when user are logged in:

adminbar

Not everyone is happy with this new feature. Here is the way to disable it for project:

Open functions.php and add:

// Disable admin-bar from showing on your blog
wp_deregister_script('admin-bar');
wp_deregister_style('admin-bar');
remove_action('wp_footer','wp_admin_bar_render',1000);

Disable resizing textarea’s in Chrome and Firefox 4

Posted: March 18th, 2011 | Author: | Filed under: CSS | No Comments »

When I was building a new form for a new project today I was having some problems with the resize option for textarea’s in Chrome (update: and Firefox 4). Every form with a textarea messes up the entire website layout by resizing this field.

Example:

textarea {
	resize: none;
}

I know this can be an usability thing for Chrome and Firefox users, but I think when you make your textarea large enough there should be no problem at all.


Facebook PHP SDK for Canvas and FB Login

Posted: January 10th, 2011 | Author: | Filed under: Facebook, PHP | Tags: , , , | 3 Comments »

This is a short article on how to best implement the Facebook PHP SDK for two integration methods: Canvas applications and external websites offering Facebook Login to their visitors. The difference is not very well documented in the example provided with the SDK. Read the rest of this entry »


Htaccess redirect with a space in the URL

Posted: April 6th, 2010 | Author: | Filed under: Etcetera | No Comments »

I discovered something new today how you can use a space in a htaccess file:

How can you safely redirect web site traffic from your old pages to the new pages without losing your high search engine rankings?
You can do this by using a “301 redirect“.

But what do you have to do if there is a space in the old URL:

^about nostylesheets.html$

Normally I would use this to make the URL working:

^about%20nostylesheets.html$

But this doesn’t work.
To make an URL working you just have to use quotes to make this URL working:

"^about nostylesheets.html$"

The jQuery/PHP Validator

Posted: April 6th, 2010 | Author: | Filed under: JS, PHP | 1 Comment »

Check out our demo which uses the jQuery as well as the PHP validator:
http://open-source.yes2web.nl/php-validator/demo1/validator-form.php

We the developers already know about the famous jQuery validator and about all the wonderful things it is capable of. But we also know that this validation is only on the client side.

What about server side validation on form input? Isn’t that important too? Of course it is. And that is exactly why we’ve come up with the following solution for this issue: The php validator. This validator consists of a class which contains a collection of methods similar to the jQuery validator. This way, we have validation on both client- and server sides using exactly the same rules and error messages.

Our PHP validator is based on the bassistance jQuery validator found at: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Read the rest of this entry »


Thoughts on php’s print_r

Posted: March 25th, 2010 | Author: | Filed under: PHP | No Comments »

Just a quick quick question: Why does php’s print_r function, which is pretty usefull to all, feature a $return (optional) argument? Not a question about it’s usefulness, but rather the choice to include this into the print_r. I would prefer to see an sprint_r variant behaving like

function sprint_r($sIn){
     return print_r($sIn, true);
}

to conform to choices made for (s)printf. While on the subject, why not include a fprint_r as well (useful perhaps for logging):

function fprint_r($oFP, $sIn){
     return fwrite($oFP, sprint_r($sIn));
}

and perhaps a vprint_r to complete the symmetry, though I have no clue as to what it should do :) .


Character encoding in MySQL

Posted: February 27th, 2010 | Author: | Filed under: MySQL | No Comments »

Just a quick note on character encoding in MySQL, use the following to force MySQL into using UTF-8 for ever!

PHP

In your PHP, always use the following immediately after you set up your connection.

  • mysql_set_charset(‘utf8′, $oDB);
  • mysql_query(‘SET NAMES \’utf8\”);

The tricky bit lies in your MySQL configuration file:

my.cnf

Add the following lines:

[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-collation = utf8_general_ci

This tells MySQL that the client (which is either PHP or the system) expects UTF-8. If you don’t tell MySQL this, a mysqldump will produce ANSI and an import from the command line will result in double encodings.

And don’t forget to use utf8_general_ci for all databases, tables and fields!


Mobile web – introduction

Posted: July 31st, 2009 | Author: | Filed under: Mobile Browsers | No Comments »

I’m not a marketing specialist, but I can see a lot of things change very quickly when we talk about mobile devices. Since its invention the mobile phone became indispensable in our lives. The mobile phone is used mainly for business purposes, but this is changing day by day: The market is moving fast to consumers too. With more people using a high-end phone, the capabilities for mobile web design give developers the opportunity to focus on this group of people as well.

Many people think it’s hard to make their website suitable for mobile devices, but this isn’t the case at all. In this article I’ll introduce a couple of things you should consider before developing a mobile website. In a future article I’ll give some hands-on advice on where to start. Read the rest of this entry »