• Resolved mkrause

    (@mkrause)


    Hi, I have several sites with FS_METHOD set tossh2. It used to work fine with WP-Optimize, but version 4.0 broke every single page on every site. There seem to be two issues. The first is a fatal error when accessing the FS_CHMOD_FILE constant:

    PHP Fatal error:  Uncaught Error: Undefined constant "FS_CHMOD_FILE" in wp-content/plugins/wp-optimize/includes/helpers/class-wpo-file-system-helper.php:59

    I haven’t defined the constant yet, and I may be wrong, but it seems to me that it’s not mandatory in WordPress.

    But even after adding the constant to wp-config.php there are still problems. The plugin says it cannot write to wp-content/advanced-cache.php and the site cache config in the wp-content/wpo-cache/config/ folder. But I checked that both files are writable for both the nginx user and the user configured for ssh2 FS_METHOD in wp-config.php (I was able to edit the contents of the files under both of them). The ssh2 method also works in other cases, such as updating the plugin or WordPress itself, so the configuration is correct. It seems to me that until now, WP-Optimize relied on permissions and direct file access, which worked in my case. The latest version seems to try to use configured FS_METHOD to access those files, but it fails for unknown reason.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support vupdraft

    (@vupdraft)

    The error you are getting is due to the?WP_Filesystem()?function either failing and/or WordPress not being set up properly (thus resulting in the FS_CHMOD_… constants not getting defined).

    When determining how to best read/write to files, WordPress will write a dummy file to the wp-content dir. It will then check to see if the file owner of the newly created file (which should be the user that the webserver is running as) matches the file owner of the wp-admin/includes/file.php file. If they don’t match, then WordPress tries to access everything via ftp or something similar instead of just reading/writing to the filesystem directly. Would you be able to check if this is the case in your install?

    Thread Starter mkrause

    (@mkrause)

    Hi, thank you for your reply. I can check everything you recommend, but I’m not sure what exactly to check at the moment? As far as I can tell, WordPress is configured according to the official documentation, ssh2 access works fine for updating plugins, themes etc, and other plugins (including WP-Optimize before 4.0) are able to write directly to their specific folders if I manually set the required permissions for them. At the moment, I would prefer not to make the whole WordPress installation writable by the web server process directly (as these sites are mostly managed from the command line with wp cli), but I also want to prevent WP-Optimize from using ssh2 access, as this would be a performance disaster – the opposite of its purpose.

    Plugin Support vupdraft

    (@vupdraft)

    1. Could you also share your site’s health information? That would help us diagnose a few things. Here’s how you can do that:
      1. Go to your WordPress dashboard.
      2. Navigate to?Tools > Site Health.
      3. Click on the?Info?tab at the top.
      4. At the bottom of the?Info?tab, click?Copy site info to clipboard.
      5. Paste the copied information into a service like?Pastebin?and share the link with us here.
    2. As per your error log, the issue is coming from file?wp-content/plugins/wp-optimize/includes/helpers/class-wpo-file-system-helper.php?on line 59. If you’re comfortable editing PHP files, you can try replacing the following line:
    return $filesystem->put_contents($filename, $data, FS_CHMOD_FILE);

    With this:

    return (bool) $filesystem->put_contents($filename, $data, FS_CHMOD_FILE);

    And let us know if this resolves the issue on your website (and if not, I’d be interested to check for any new entries in the error log). However, proceed only if you are comfortable making this change.

    Note: We refactored our filesystem operations to use WordPress’s native Filesystem API in version 4.0.0. However, this is unlikely to be the root cause – it may be related to the server environment or a conflict.

    Thread Starter mkrause

    (@mkrause)

    1. Here’s the info about the site (I anonymized paths and domains, but didn’t change any other data) in it: https://pastebin.com/1qbh6rfj
    2. I changed the line as you mentioned, but it doesn’t change anything. Without explicitly defining the FS_CHMOD_FILE constant in wp-config.php, the site crashes with the same error as before (Undefined constant…). If I define it in the config, the site does not crash anymore, but it is not possible to enable caching because plugins throw this error: The request to write the file /home/wp/www/mydomain.xyz/wp-content/advanced-cache.php failed. These errors appear in the log after attempting to enable caching
    PHP Warning:  file_put_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/advanced-cache.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 285
    PHP Warning: file_get_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/advanced-cache.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 258
    PHP Warning: file_get_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-config.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 258
    Could not turn off the WP_CACHE constant in wp-config.php
    PHP Warning: file_get_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/advanced-cache.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 258
    PHP Warning: file_get_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/advanced-cache.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 258
    PHP Warning: file_put_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/wpo-cache/config/config-www.mydomain.xyz.php): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 285
    PHP Warning: file_get_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/uploads/wpo/logs/cache-1956f685704ef8774d64.log): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 258
    PHP Warning: file_put_contents(ssh2.sftp:///home/wp/www/mydomain.xyz/wp-content/uploads/wpo/logs/cache-1956f685704ef8774d64.log): Failed to open stream: operation failed in /home/wp/www/mydomain.xyz/wp-admin/includes/class-wp-filesystem-ssh2.php on line 285
    - Full Cache Purge triggered by: WPO_Page_Cache::disable
    Plugin Support Kowsar Hossain

    (@kowsar89)

    Hi @mkrause,

    This is Kowsar from the development team. Thanks for sharing the Site Health info.

    1. I think you can try the following line to avoid defining FS_CHMOD_FILE explicitly:
    return (bool) $filesystem->put_contents($filename, $data);
    1. According to your Site Health report:
    ### wp-filesystem ###
    
    wordpress: not writable
    wp-content: not writable
    uploads: writable
    plugins: not writable
    themes: not writable
    fonts: not writable

    The wp-content directory is not writable. However, WP-Optimize needs it to be writable to work properly. Can you change that and see if it solves the issue for you?

    Thread Starter mkrause

    (@mkrause)

    Hi Kowsar, changing the line as you recommended has the same effect as defining the constant in the config – i.e. WordPress stopped crashing with fatal error, but caching still cannot be enabled because WP-Optimize says it cannot write to wp-content/advanced-cache.php. This doesn’t change when I make wp-content writable – WP-Optimize still uses ssh2 to access the file and fails for unknown reasons (and sorry to repeat this, but WordPress is still able to install or update plugins via the ssh2 FS method in wp-content without any problems). Here are the folder and file permissions:

    drwxrwxr-x 11 wp www-data 15 13.?feb 16.26 wp-content/
    -rw-rw-r-- 1 www-data wp 2721 13.?feb 16.27 wp-content/advanced-cache.php

    nginx process runs under www-data and ssh2 FS is configured to use the user wp. Under both users, I can create files under www-data and edit existing files including advanced-cache.php.

    Plugin Support Kowsar Hossain

    (@kowsar89)

    @mkrause We’ve released an update (v4.0.1) which should fix this issue. Kindly check. Thanks

    Thread Starter mkrause

    (@mkrause)

    Hi Kowsar, thanks a lot! I tested the new versions on the first website and it seems to work fine. I will update all my sites in the next few days. I will let you know if I run into any problems.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.