Selbständiger IT Berater – Java, J2EE, WebSphere Portal, Lotus Domino
RSS icon Home icon
  • [Behoben] 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 30 comments

    Vor einigen Tagen habe ich meine WordPress Installation auf das neue 2.5 Release aktualisiert. Aufgrund meiner Trägheit im Hinblick auf administrative Tätigkeiten wollte ich natürlich auch die neue on-click plug-in upgrade Funktion nutzen um ein paar Plug-ins zu aktualisieren. Allerdings scheiterten alle meine Versuche die Funktion zu nutzen mit der ziemlich nutzlosen Fehlermeldung “Could not create directory”. Daher begab ich mich auf die übliche Netzsuche und bin relativ schnell auf einige Beiträge gestossen, welche die Ursache in unzureichenden Berechtigungen auf bestimmte Verzeichnisse ausmachten. Das manuelle Anlegen des Verzeichnisses /wp-content/upgrade und das “chmodden” auf 777 dieses selben sowie der Plug-in Verzeichnisse würden das Problem lösen. Leider nicht bei mir. Daher blieb mir nichts weiter übrig als die Ärmel hochzukrempeln und WordPress zu debuggen…

    Lange Rede, kurzer Sinn, ich bin schließlich auf den PHP Bug Report #42739 mkdir doesn’t like a trailing slash when safe_mode is enabled gestossen und es zeigte sich, daß dies genau das Problem war, welches sich mir auf meinem Hosting Account entgegenstellte. Die PHP Option safe_mode ist dort aktiviert und WordPress versucht vergeblich mit Schrägstrich endende Verzeichnissepfade anzulegen (z.B. /htdocs/wp-content/upgrade/the-plugin/).

    Nachdem mir der Grund also bekannt war, konnte ich einen Workaround entwickeln und endlich den on-click plug-in updater nutzen. Für alle die das gleiche Problem haben, hier meine Lösung:

    1. Die Datei <wp_root>/wp_admin/includes/class-wp-filesystem-direct.php lokalisieren und in einem Editor öffnen
    2. Nach “function mkdir” in der Datei suchen
    3. Die nachfolgenden Codezeilen in die Methode einfügen. 
      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. Mit der Ein-Klick-Aktualisierung beginnen!

    Nachtrag:

    1. Die Änderung funktioniert auch mit WordPress 2.5.1
    2. Falls diese Änderung nicht zum gewünschten Erfolg führen, kann der Fehler noch eine zweite Ursache haben. Daher sollten die Berechtigungen des Verzeichnis /wp-content/upgrade/ und dessen Unterverzeichnisse überprüft und gegebenenfalls per chmod auf 777 gesetzt werden. Falls das upgrade Verzeichnis gar nicht existieren sollte, reicht es vielleicht schon dieses einfach manuell anzulegen.
     

    30 responses to “[Behoben] 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. sanadi

      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.

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

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

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

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

    Leave a reply