Tuesday, March 1, 2011

WordPress themes installation stuck at Unpacking Error

A lot of people get this strange error when wordpress seems to get stuck at the "Unpacking the package step. This can happen with both automated admin installations and manual FTP theme uploads. This is a very frustrating error because "unpacking" or unzipping the same theme files locally works just fine, it's just wordpress that doesn't seem to be able to handle them. This gets even more frustrating when we realize that wordpress is supposed to throw a timeout error after 30 seconds, but in this case it just freezes with no debugging messages whatsoever.

Anyways, the reason it happens for in only a few select cases is because of the memory limitation imposted by the host, and as you can see, all we need to do is to increase the total amount of memory available to fix this. Below are the steps to fix it -

Step 1: Connect to your wordpress FTP and drill down to wp-includes folder.
Step 2: Locate and open default-constants.php file in your favorite text editor.
Step 3: Look for the following term - WP_MEMORY_LIMIT (normally it's at line 23).
Step 4: Change define('WP_MEMORY_LIMIT', '32M'); to define('WP_MEMORY_LIMIT', '64M');

Please note that there will be more than one lines with the "define('WP_MEMORY_LIMIT',..." code and we're looking for the one that says 32M and not the one that already is set to 64M.

Please also note that these settings are no longer available in the wp-settings.php file that is located in the wordpress root folder - Earlier this settings file indeed contained this code but since the last upgade, wp-settings.php calls the function wp_initial_constants() and that function is now located in default-constants.php file. It is this function that updates the WP_MEMORY_LIMIT variable depending on whether the wordpress site is multisite (via is_multisite() function) and this is what we change in the default-constants.php -

Below are the before and after code snippets for your reference -

BEFORE:
function wp_initial_constants( ) {
global $blog_id;

// set memory limits
if ( !defined('WP_MEMORY_LIMIT') ) {
if( is_multisite() ) {
define('WP_MEMORY_LIMIT', '64M');
} else {
define('WP_MEMORY_LIMIT', '32M');
}
}

AFTER:
function wp_initial_constants( ) {
global $blog_id;

// set memory limits
if ( !defined('WP_MEMORY_LIMIT') ) {
if( is_multisite() ) {
define('WP_MEMORY_LIMIT', '64M');
} else {
define('WP_MEMORY_LIMIT', '64M');
}
}

Now, it should work but I've also noticed that at times I've to restart the webserver to get it going, this seems to be especially true when you've a windows (as opposed to linux) hosting running on IIS 7. Also, just to avoid confusion - some hosting companies (including godaddy) refer to it as restarting or recycling application pools, implying they restart that particular process running your website (so to say) and not the entire webserver. It frees up any clogs and is the same thing as far as this issue is concerned.

Hope this helps!

3 comments:

  1. This was perfect. Thanks for walking me through it. Worked like a charm.

    ReplyDelete
  2. Thanks, this is genious

    ReplyDelete
  3. This solution doesn't work. I have multiple WP sites on my server and suddenly they all started having this problem.
    Windows 2008 R2, WP 3.9.1

    ReplyDelete