IT Freelancer – 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

    (5 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Loading ... Loading ...
    Posted on 25 April 2008 26 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 on-click plug-in upgrades 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!

    Addendum:

    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.

     

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

    1. 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!

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

    3. Thank you man. It worked!

    4. 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…

    5. [...] un poco encontre el blog de Sebastian Thomschke que nos da la solucion que encontrĂ³ en un [...]

    6. 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.

    7. 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.

    8. Great !!!

      Thanks Sir!

    9. 777 its a bit dangerous…

    10. Hey, your solution worked! Thanks a lot!

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

    12. [...] e continuou da mesma forma. Então, consegui encontrar a solução no sebthom.de A solução para seus problemas pode estar aqui embaixo. Funcionou comigo. Tome [...]

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

    14. 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!

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

    16. 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’;

    17. 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!

    18. 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!

    19. [...] ?????????????? ?????????? ????????? ?????? ???????? ???????? ?????? [...]

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

    21. does not work on wordpress 2.7

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

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

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

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

      Ben

    25. it worked!!! thanks alot!! :D

    26. 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.

    Leave a reply