WordPress: Could not create directory – Theme Install Failed

by on Feb.10, 2010, under Wordpress

This error appeared every time I wanted to install a theme automatically, even in the current version (2.9.1) of WordPress:

Downloading install package from http://wordpress.org/extend/themes/download/sample-theme.zip.
Unpacking the package.
Installing the theme.
Could not create directory. /var/www/html/web999/blog/wp-content/themes/sample-theme/
Theme Install Failed.

This is caused by an error when running the php function mkdir() under safe_mode on certain versions of PHP (I’m using PHP Version 5.2.5). The bug is already tracked and probably will be fixed in the next version of WordPress…

There are two solutions to fix this by your own

  1. Solution – Edit class-wp-filesystem-direct.php
    Add the marked lines in your wp-admin/includes/class-wp-filesystem-direct.php (Line 281):

    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
       // safe mode fails with a trailing slash under certain PHP versions.
       $path = untrailingslashit($path);
       if ( empty($path) )
          $path = '/';
       if ( ! $chmod )
          $chmod = FS_CHMOD_DIR;
  2. OR

  3. Solution – Turn safe_mode off
    I do not recommend this solution! But you can use it e.g. temporarily if you want to install a few themes in a row and turn safe_mode on again afterwards. If you are using Confixx you can edit these settings easily. Otherwise you have to edit your php.ini manually. How to do this? Check that: Customizing PHP Safe Mode

Now your Theme installation process should give you a response like this:

Downloading install package from http://wordpress.org/extend/themes/download/theme.zip.
Unpacking the package.
Installing the theme.
Successfully installed the theme Sample Theme.

Did this work for you? Tell me!

Incoming search terms:

:, , , , , ,

5 Comments for this entry

  • Jackie

    Thx for posting. Worked perfectly…

  • Joel

    I copied the code exactly as you have it… couldn’t get it to work.

  • Pedro Normoyle

    Incredible article, thank you so much <3

  • Nishad

    We have created our own theme for WordPress but it fails to install.
    i got the error message as follows.

    Unpacking the package…

    Incompatible Archive. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature.

  • Anthony

    I tried this but it didn’t work. In fact, when I opened up class-wp-filesystem-direct.php, your fix was already there. Guess I’ll keep hacking away, I’ve tried assigning /wp-content/upgrades to chmod 777 and writing both SSH and FTP connections into the wp-config.php file but neither seem to change the output (which is the error exactly as you described it). For anyone wondering, I’m hosting with NearlyFreeSpeech.

1 Trackback or Pingback for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!