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!
Related posts:


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