IT Consultant – Java, J2EE, IBM WebSphere Portal, Lotus Notes/Domino
RSS icon Home icon
  • [Solved] WordPress 2.5 One-Click Plug-in Upgrades – Could not create directory

    (6 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Loading...Loading...
    Posted on 25 April 2008 42 comments

    Some days ago I upgraded my WordPress installation to the new 2.5 release. Being a lazy guy I of course wanted to use the new one-click plug-in upgrade feature to update several plug-ins. Trying to one-click update some of the out-dated plug-ins only resulted in the rather meaningless error message “Could not create directory”. So I started searching the web for possible solutions. I quickly found some posts explaining this issue to be a directory permission problem. Manually creating the /wp-content/upgrade directory and chmoding it as well as the plug-in directories to 777 should solve the problem. Unfortunately not for me. Therefore I rolled up my sleeves and started to debug WordPress…

    To cut a long story short, eventually I came across this PHP bug report #42739 mkdir doesn’t like a trailing slash when safe_mode is enabled and it turned out that this was the issue I was facing with on my hosting account too. The safe_mode option is enabled and WordPress tries to create directories that end with a slash (e.g. /htdocs/wp-content/upgrade/the-plugin/).

    After knowing the reason I could develop a workaround and finally got the one-click updater running. If you are facing the same issue you can try to use my patch too.

    1. Locate and open the file <wp_root>/wp_admin/includes/class-wp-filesystem-direct.php in an editor
    2. Search for “function mkdir
    3. Add the following statements to this method
      function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
      	if( ! $chmod)
      		$chmod = $this->permission;
      
      	// workaround for http://bugs.php.net/bug.php?id=42739 starts here
      	if(ini_get('safe_mode') && substr($path, -1) == '/')
      	{
      		$path = substr($path, 0, -1);
      	}
      	// workaround for http://bugs.php.net/bug.php?id=42739 ends here
      
      	if( !@mkdir($path,$chmod) )
      		return false;
      	if( $chown )
      		$this->chown($path,$chown);
      	if( $chgrp )
      		$this->chgrp($path,$chgrp);
      	return true;
      }
    4. Start one-click updating!

    Update 1:

    1. The patch also works for WordPress 2.5.1
    2. If applying this patch does not lead to success the problem may have a second cause. Therefore also check the permissions on the /wp-content/upgrade/ folder and it’s sub folders, e.g. chmod them to 777. If the upgrade directory does not exist at all it may be sufficient to create it manually.

    Update 2:

    1. In case the patch does not work check if you have the AskApache Password Protect plug-in installed.
    2. If so, try to deactivate this plug-in before you try to upgrade any other plug-in.

     

    38 responses to “[Solved] WordPress 2.5 One-Click Plug-in Upgrades – Could not create directory” RSS icon

    • At first, it still didn’t work for me. Even after adding your workaround code to the ‘mkdir’ function in ‘class-wp-filesystem-direct.php’, I was still getting the “Could not create directory” error while using the automatic upgrade feature for the Akismet plugin.

      I figured it was a rights issue still, even after the code was added. I chmodded all the folders down to the plugin folder and plugin file that I wished to upgrade automatically to 777. In other words I chmodded to 777 the, “wp-content” folder, the “plugins” folder, the “akismet” plugin folder, and the”akismet.php” plugin file. After that, I ran the automatic upgrade on the Akismet plugin from Dashboard, and it worked fine. Re-chmodded everything to 755, and I’m done.

      Still easier than doing it manually, I suppose. :)

      Thanks for figuring this out!

    • Many thanks! Works great for me. I think that’s the first time WordPress didn’t work with safe mode properly.

    • Thank you man. It worked!

    • Thanks but this is not working here. Edited the code, no dice. Changed permissions too, no difference. Must be something else, at least for me…

    • The ‘could not create directory’ message for me turned out to be an attempt to make a wp-content/upgrade directory. Once I made this with the correct permissions (along with setting perms on the plugin directory) things went fine.

    • This solution didn’t work for me, but changing the writes on the plugins dir & all child dirs (not the files, just all dirs) from 755 to 777 did work.

      Thanks.

    • Great !!!

      Thanks Sir!

    • 777 its a bit dangerous…

    • Hey, your solution worked! Thanks a lot!

    • Ey Kollege bei mir hat das Upgrade problemlos funktioniert. Vielleicht sind ja die PHP-Einstellungen deines Provides etwas restriktiver?

    • Thank you so much. Easy update for plugins works now.

    • I’m running on Windows (using XAMP) and creating the directory with appropriate permissions did not work for me, your code hack did though, so, thanks!

    • Bin begeistert – es funktioniert danke dieser “Slash” Lösung

    • Ich musste \wp-admin\includes\update.php in Zeile 123 ändern, damit es funktioniert:

      //$working_dir = $content_dir . ‘upgrade/’ . basename($plugin, ‘.php’);
      $working_dir = $content_dir . ‘upgrade';

    • The code hack didn’t work for me, neither did the permissions. Grrr.. i have a number of blogs running on the same host (VPS) and the rest of them work fine!

      I did have to create the upgrade subdirectory… that didn’t make a difference either. Bleh!

    • I just tried all of the suggested hacks on my other WP site that’s hosted externally. Unfortunately, nothing worked but that maybe because it’s running WP 2.7 RC1.

      Thanks for the tips though!

    • if you can’t change permission for upgrade directory, just delete the files inside it and try again to chmod

    • does not work on wordpress 2.7

    • Thanks. patch + chmod did the works! (WP 2.5.1)

    • Thanks a lot, it not just work for WP 2.5 but also WP 2.8. It’s totally helping me…..Gracias.

    • Thank you SO MUCH – I had tried several solutions.

      You are the one who nailed it, thanks again :-)

      Ben

    • it worked!!! thanks alot!! :D

    • I had hoped you had solved my problems, but unfortunately the suggested solution(s) didn’t work…

      Even if chmodding the directory to 0777 the error remains, despite me using the mkdir fix you suggested.

      Does anyone have any idea what might be causing this? Creating directories and copying files remains a problem despite the liberal file/dir attbs set.

    • Thanks! I’ve been having this problem ever since I installed WordPress, and I’m surprised it hasn’t been fixed after three major updates.

      However, this fix does it every time, and this is the only website I’ve seen so far that has a legitimate fix. All the other sites just say to chmod the folder to 777 (not a good idea all of the time).

    • If you have a VPS or dedicated server you may also want to use the shell to set the permissions. The reason is UMASK. Just because php sets the permissions doesn’t mean that apache has the rights to that folder due to UMASK.

    • I know this thread is a bit old, but I thought I would post my fix to my problem. I have been searching for weeks trying to find out why I could write to or make directory using wp 2.9.2 ubuntu 10.4 new install. The problem turned out to be in the vsftpd configuration where the local user couldn’t write when posting. I performed a manual ftp and couldn’t post the file using cmd ftp client. I couldn’t write. I then got my vsftpd.conf configuration file from the working (old) server and configured the new server just like the old. After that WP work as always. I will post the difference in the configuration shortly.

    • The difference in the /etc/vsftp.conf files was

      # Uncomment this to enable any form of FTP write command.
      #write_enable=YES

      The new server was configured with the #write_enable=YES commented out like the above. I uncommented it and WP worked.

      I use SSH and ftp over ssh mostly and that is why I didn’t notice the ftp write issue earlier.

      Hope this helps somebody.

    • im on 3.2 and nothing works for me

    • tonyawards

      Thank you – this finally worked for me after your script and the chmod -R 777 for wp-content, wp-includes, and wp-plugins – as referenced above by you and Brent Rasmussen.

      And – this was for WordPress 3.0.2 — still an issue, I guess, But fixed with this procedure. Now I can (finally) upgrade and install plugins locally in my lampp installation

      Thanks!

    • I did as you said, and it did get me a step further. Now I get the error.

      Could not create directory. /httpdocs

    • Im on VPS and nothing worked for me. Can someone tell me what can be the issue? It happened to all my websites on VPS.

    • Symmtech, Thank you for posting your solution! I had the same problem issue.

    • I’m having issue with wordpress 3.2.1 what to do

    • For WordPress 3 or later check if the AskApache Password Protect is installed and deactivate it.

    • You’ll never guess what was causing me to get this message? I ran out of disk space on the server :-) Glad it was easy to fix.

    • This worked like a treat for me. Saved me lots of hassle. I’m guessing I’ll have to add this back in EVERY TIME I update my install of wordpress?

    • Oddly enough I had this problem for the very first time with WP 3.5.1 on one of my websites [not the one listed with my information] (but not on any of my other WP sites on the same host).

      I don’t have safe_mode turned on in php.ini, so the mkdir work around would be pointless to implement (I checked multiple times to make sure safe_mode wasn’t on) and I even checked the chmod for the plugins folder (it was already 777).

      I had a suspicion it was probably the cause and used the suggestion given in the comments by the original poster about AskApache Password Protect (disabled it).

      Then I ran the update for that plugin and then re-activated it and then tried to update the other update-pending plugins and theme.

      Now everything is working perfect again and I can continue to work on the site!

      Thanks, Sebastian!

    • Jacob Schooley

      I was able to get plugins installing this way, and I would never had thought of it. I changed the file, then I cd’ed to /srv/www/wp-content and used sudo chmod -R 777 on localhost.

    4 Trackbacks / Pingbacks

    Leave a reply