Wordpress: Could not create directory – Plugin Install Failed

by admin 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!

  • Share/Bookmark

Related posts:

  1. Wordpress: Could not create directory – Theme Install Failed
:, , , , , ,

8 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?

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!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...