WordPress: Could not create directory – Theme Install Failed
by admin 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
- 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; - 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
OR
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
1 Trackback or Pingback for this entry
-
30 Day Diary – Day 2 – Setup WordPress | Detention Hall
April 11th, 2011 on 4:16 am[...] There is another approach instead of turning off safe_mode listed at: http://stuff24.de/blog/wordpress-could-not-create-directory-theme-install-failed/ [...]

June 4th, 2010 on 8:36 pm
Thx for posting. Worked perfectly…
June 9th, 2010 on 2:36 pm
I copied the code exactly as you have it… couldn’t get it to work.
June 10th, 2010 on 3:16 am
Incredible article, thank you so much <3
November 9th, 2010 on 5:34 am
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.
July 27th, 2011 on 4:38 am
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.