WordPress: Could not create directory – Plugin Install Failed

by on Feb.10, 2010, under Wordpress

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

Downloading install package from http://downloads.wordpress.org/plugin/sample-plugin.zip.
Unpacking the package.
Installing the plugin.
Could not create directory. /var/www/html/web999/blog/wp-content/plugins/sample-plugin/
Plugin 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 plugins 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 Plugin installation process should give a response like this:

Downloading install package from http://downloads.wordpress.org/plugin/sample-plugin.zip
Unpacking the package.
Installing the plugin.
Successfully installed the plugin Sample Plugin.

If you still have problems with the installation of a wordpress plugin, read this.

Did this work for you? Tell me!

Incoming search terms:

Share
:, , , , , ,

19 Comments for this entry

  • rob

    Hey – your code changed my error from

    “…
    could not create directory. /var/www/html/web999/blog/wpcontent/plugins/sample-plugin/
    Plugin Install Failed.”

    to

    “…
    Incompatible Archive
    Theme Install Failed.”

    However. I tracked down this post at WordPress Multiuser from a week ago: http://mu.wordpress.org/forums/topic/16777 that has isolated my problem to a function call in /wp-admin/includes/class-wp-filesystem-ftpext.php.

    He provides this one line edit: change the line

    “$list = @ftp_rawlist($this->link, ‘-a ‘ . $path, false);”

    to

    “$list = ftp_rawlist($this->link, $path, false);”

    It fixed my problem! Thanks for your help! This was driving me effing crazy.

  • Peter Pavey

    I tried your solution 1.
    I pasted the code into the class-wp-filesystem-direct.php file.
    Rebooted my system, went through install plugin but now get:

    Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION in /var/www/wp/wp-admin/includes/class-wp-filesystem-direct.php on line 374

    the file only goes up to 371…. any ideas?

  • Dave Smith

    I had the same problem Peter.

    In the original class-wp-filesystem-direct.php file (before you modified it) search for

    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {

    Then, directly underneath that line put

    // safe mode fails with a trailing slash under certain PHP versions.
    $path = untrailingslashit($path);
    if ( empty($path) )
    $path = ‘/’;

    That worked for me

  • illimar

    Downloading update from http://downloads.wordpress.org/plugin/akismet.2.2.9.zip…

    Unpacking the update…

    Could not create directory. /

    Actions: Return to Plugins page

    I’m trying with a new and clean install of WP3 RC1.

  • Chais meyer

    Hey “illimar” I’m trying a clean install of wp3 rc1 and getting a similar error on a godaddy IIS7 server. Error “Could not create directory. D:/Hosting”, any luck yet?

    I’ve modified the above files (if needed) and to no avail. :(

    Would love a fix!

  • oposiciones

    I had the same problem in wp 3.0 but it was my fault, I have in my own server and i just needed to do this in the folder of my wordpress:

    chown -R apache:apache *
    or
    chown -R www-data:www-data *

    apache:apache user of apache server:group of apache server

    I hope it can help to other users.

  • LinuxUser

    oposiciones is correct! if you are using your own apache server you need to grant ownership of the files in your wordpress folder to your FTP user. THANKS!

    You shouldn’t have to do this on a hosted solution such as godaddy, etc.

  • allen

    Hey oposiciones, that’s what got me going after horsing around with this problem for a while. I wonder if there’s some log or other facility that would provide some information to speed-up the process of deciphering the fact that it’s a permissions or ownership issue?

  • Leah

    I was having some issues with a host where the only way I could upload images from within WP was to have the uploads folder CHMOD to 777 which is not safe. Even more annoying, plugins were going to the uploads folder no matter how I set paths. I found an awesome plugin, WP Easy Uploader. Once this is installed, you can keep your folders locked down,not have to monkey with permissions or paths, and best of all, no longer have upload failures. I hope this helps someone.
    http://wordpress.org/extend/plugins/wp-easy-uploader/

  • sasha

    I looked at this file and the lines you mention are already included.
    Still I get this error and it started to occur after I installed a wordpress multisite in the root. The admin panel etc.. is up but I cant install any theme or plugin.

    Before that I the latest version at its own db working just fine.
    Now both of them give the error. I tried it on other domains and getting the same.

  • MikeM

    I was getting this error when trying to do a full WordPress upgrade (via the dashboard).

    None of the above worked for me in making that error message go away, but I discovered it worked great once I manually deleted the wp-content/upgrade directory.

    Previously my ftp user had had full rwx access to this directory. I’m guessing it was left behind (with nothing in it) by a previous upgrade, and for whatever reason the mkdir logic wasn’t smart enough to notice the directory already existed. That’s just my guess, however.

  • Joe

    I had similar problems. After scratching my head and trying so many solutions. I remembered I had installed askapache plugin which password protects certain directories.

    Soultion: Deactivate it > upgrade > Reactivate.

    It worked for me…

  • Alistair

    Excellent, Joe! Deactivating AskApache worked for me.

  • lupee

    Could not create directory. /home/luthfi/public_html/staractoractress.com/wp-content/upgrade/google-analytics-for-wordpress.tmp/google-analytics-for-wordpress

    how do I fix??

  • name32

    Perhaps it works, open your PHPmyAdmin,
    Search in database: “path”
    Browse .. match(es) inside table wp_options
    Edit value : upload_url_path

  • Nano

    I had this problem but it was all due to wordpress being installed on a local machine. In this case a Mac running Mamp. The fix was to run this command in terminal to chown -R _www:staff wordpress

    replacing wordpress with the location of wordpress installation

  • Rômulo

    I fix this issue by configuring the local ftp server write permitions

  • Kenya Web Design

    Deactivating AskApache worked for me! Thanks

  • peter kenneth

    it works like a wonder … hey thank you a ton :)
    AskApache deactivated :D !!..

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!