• Resolved kadbar

    (@kadbar)


    When trying to update plugins/themes/WP, it says: Update Failed: Unable to locate WordPress content directory (wp-content).
    Does it have anything to do with my installation path?
    My wordpress folder is available by SFTP through the following path
    /public_html/wordpress/wp-content/plugins
    so it has a /public_html/ in the path, which is the topmost folder I have access to. Is that something the plugin may find an obstacle?
    And where can I set the default path?
    Best regards,
    Barnabas Kadar

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author David Anderson

    (@davidanderson)

    You can try experimenting with the constants FTP_BASE, FTP_PLUGIN_DIR, FTP_CONTENT_DIR, as described here – https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants – they are active for this plugin’s login method.

    David

    I had the same error.
    Changing the sshd config to make WP’s root the starting directory of the users SFTP login solved it.
    e.g.

    Match User wordpress
     ChrootDirectory /home/wordpress/public_html
     ForceCommand internal-sftp

    The mentioned settings have not helped to remedy this problem. I doubt they get evaluated when logging in via SFTP. I set just FTP_BASE or both FTP_BASE and FTP_CONTENT_DIR.

    This has to be a bug either in this plugin or in core.

    I activated debugging, but did not find any entry in the debug log related to this plugin.

    • This reply was modified 5 years, 5 months ago by tgoeg.
    • This reply was modified 5 years, 5 months ago by tgoeg.

    Coming to think of it:
    This is solution at all for core updates, as the chroot has to be root owned. Therefore, the user won’t be able to write files in the webroot.
    The FTP_BASE has to be honored. There’s no other solution.

    Using define( 'WP_CONTENT_DIR', 'whatever/dir/wp-content' ); finally solved this.

    This should definitely be made part of the documentation. I think most people will try to separate users with chroots!

    The only thing missing for a proper, secure setup is to make wordpress use a 0027 umask so the files get sane default permissions (using setgid as well).

    However, that seems impossible.

    A hack is mentioned here (I would not call that a solution):
    https://wordpress.org/support/topic/fail-to-make-wp-set-the-umask-i-want/

    Plugin Author David Anderson

    (@davidanderson)

    Hi,

    All the logic for locating WP is inside WordPress core. This plugin just provides an SFTP connection method for the connection itself (i.e. doesn’t have any of the ‘find WP’ logic).

    David

    Then something’s broken inside core.
    And define( 'WP_CONTENT_DIR', 'whatever/dir/wp-content' ); made plugins deactivate over night. That’s also pretty ugly.
    So I’m still without a solution.

    Is my setup possible? I.e. having no write permissions for the apache user (except the upload directory) and having updates work in the backend by using proper credentials/permissions for an SSH user and using this plugin?

    Plugin Author David Anderson

    (@davidanderson)

    Can you clarify your situation? I haven’t very well understood the current problem, because your first post said that you’d solved it. Which part is solved and which is unsolved?

    Sorry for not being clear enough.
    In fact nothing is solved.

    The WP install is owned by user:www-data and mode 2750 for directories and 0640 for files.

    So user can read and write and www-data can only read.

    The group sticky bit makes new files have www-data as owner as well.

    I’d like to use this plugin to do the updates via the WP backend so it uses SFTP as “user” to change/write files.

    The problem is that after this plugin correctly authenticates the user (I can see 4 successful logins in sshd’s log) the backend says "Update Failed: Unable to locate WordPress content directory (wp-content)." as the original author of this issue states.

    If I enable debug logging, nothing relevant shows up in the log, but the fact that there is content in it really is strange, as wp-includes/load.php has the following line:
    ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
    So somehow WP_CONTENT_DIR has to be correctly set (and the website works flawlessly apart from updates, which also makes me think the WP_CONTENT_DIR has to be found correctly. In fact it is at its default location.

    The only thing probably coming into play here is that “user”‘s SFTP base directory is NOT the web root.

    (I need to chroot the user, and the directory to chroot to has to be root owned: http://man.openbsd.org/sshd_config#ChrootDirectory
    There is a wwwroot directory in the “user”‘s home which is bind-mounted to /var/www/wordpress)

    Reading the documentation I’d assume that setting
    define( 'FTP_BASE', '/home/user/wwwroot/' );
    should solve this, which it does not.

    If I set
    define( 'WP_CONTENT_DIR', '/var/www/wordpress/wp-content' );
    the updates work flawlessly, but something in this configuration made wordpress deactivate all plugins in the night after setting it without any admin interaction (the page still worked after the updates – maybe this was just a caching issue and the page was actually already broken after the updates; I was not able to reactivate the plugins. Only after unsetting WP_CONTENT_DIR I have been able to reactivate them again.

    I am searching for a solution to basically just leave my wp-config and file permissions as they are (which definitely works when using wp-cli for updates, but I need to enable updates in the backend for an external agency). However, SSH SFTP Updater does not seem to work with only touching the FTP_* variables as it seems..

    I hope I have been clearer now 🙂

    Thanks for your continued help!

    I am on php7.2

    This could be
    https://core.trac.wordpress.org/ticket/41831
    or
    https://core.trac.wordpress.org/ticket/35517

    If so, it should be stated that this plugin is currenty not compatible with php7.x in the given setup.

    I’ll see whether some mentioned workarounds fix this.

    Plugin Author David Anderson

    (@davidanderson)

    Hi,

    I’m not an expert on what WP does in regard of trying to find files after an (S)FTP login; I’ve not studied that part if WP core. This plugin just sets up the SFTP connection itself; I took it over when the previous maintainer had no more time for it. If you believe you have a demonstrable bug concerning trying to find the files, then it’s best to raise it in Trac, because as I say, the code for that is in core and isn’t in this plugin.

    David

    I seems this is not a bug in this plugin, so no, I cannot demonstrate the malfunction in it.

    However, I think users should be made aware that chrooted SFTP setups won’t work on php 7+ . (FWIW, FTP(S) won’t work either).

    Do you know of a working setup on php 7+ ? If so, please provide details of the webroot’s file/dir permissions and/or whether it is chrooted.

    I think this would have to be some other sort of setup, either with an SFTP server implementation that can chroot to a directory not owned by root (or the directory would need to be writable for group or others, which should be avoided) or simply one that does not chroot (which should be avoided as well).

    If I can find a workaround by patching core, I’ll definitely provide info here so others can be spared the troubleshooting.

    andyg5000

    (@andyg5000)

    I’ve been using this plugin for a while on my hosting setup. Recently updates stopped working. In inspecting wp-admin/includes/class-wp-filesystem-base.php, I realized that the FTP_* constants are only applied when the FS_METHOD contains the string “ftp”. Hacking core with the following change fixes this issue, but I don’t want to do that.

    if ( stripos( $this->method, 'ftp' ) !== false || $this->method === 'ssh2') {

    I’m not a WP dev, so I don’t know the best way to resolve this. Hopefully that will help someone point us in the right direction.

    Plugin Author David Anderson

    (@davidanderson)

    Hi,

    Good find! Please can you try the just-release version 0.8.2 ?

    David

    That definitely fixes it, w00t!

    I had to define the following variables:

    define( 'FTP_USER', 'user' ); #most likely not necessary, can be entered in the web form as well
    define( 'FTP_HOST', '127.0.0.1:22' );
    define( 'FTP_BASE', 'wwwroot' ); #the bind mounted directory to /var/www/wordpress, necessary b/c we chroot
    define( 'FTP_CONTENT_DIR', 'wwwroot/wp-content/' ); #the *relative* path as seen after an sftp login
    define( 'FTP_PLUGIN_DIR ', 'wwwroot/wp-content/plugins/' ); #see above
    define( 'FS_METHOD', 'ssh2' );

    Thanks a lot!
    If possible, please add this to the manual, as all examples I have seen online use absolute paths, which does not work.
    Trying with sftp from the commandline also helps to understand why.
    Additionally, if your SSH setup is hardened and does not accept all ciphers/MACs, an exception has to be added to /etc/ssh/sshd_config:
    MACs [..],hmac-sha2-256

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Update Failed: Unable to locate WordPress content directory (wp-content).’ is closed to new replies.