• I’m running WP on RHEL7 using apache 2.4 and PHP-FPM 7.0 installed from the EPEL repo.
    Our production site is running multisite WP 4.9.9 and our test site is running 5.0.3.
    The problem that I’ve observed is that on our test system (WP 5.0.3), any media
    uploaded does not display in the media library. In the media library it looks
    like an icon with a broken link for the image; no thumbnail. If I go out to the
    filesystem (WP_ROOT/wp-content/blogs.dir/’blog_id’/files/%Y/%M/) the files are
    present with the correct permissions, but if I try to display them from the link
    given in the media library, I get a 404 error.

    Obviously, the first thing I tried was disabling all of the plugins. All plugins
    were disabled and the problem persisted. I next tried changing the permalinks,
    first to plain and then back to “Month and name”; neither resulted in a successful
    display of the JPG file in the media library. I tried creating a new post and
    that was successful. I next tried installing and activating the “Health Check &
    Troubleshooting” plugin. In the section on “REST API availability”, I get the
    error message

    The REST API request failed due to an error.
    Error encountered: (0) cURL error 28: Operation timed out after 10001
    milliseconds with 0 out of -1 bytes received

    Our production system that is running WP 4.9.9 gives a similar REST API error
    when running the Health Check plugin but all media thumbnails are displayed
    in the media library as is the actual media within a post.

    Therefore, given that the two systems are identical except for the running
    version of WP, and that this behavior is observed when all plugins are
    disabled, is it possible that the problem is with the REST API? If so, how
    would it be disabled and how can I enable it?

    Thanks,
    Mike

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Quick question, might solve the problem: Do you have any code on the site, in any plugin, theme, anywhere at all, that calls session_start()?

    If you can do a global search of your site’s code, then that would be the first thing I would look for.

    Thread Starter 1337mirth

    (@1337mirth)

    Thanks, Otto.

    I ran the following command:
    find . -type d \( -name blogs\.dir -o -name \.snapshot \) -prune -o -print | grep ‘session_start()’

    (in essence, this just prints the name of all the files in the /var/www/html directory except for the files in ‘blogs.dir’ and ‘.snapshot, and then checks if the string ‘session_start()’ is in that file). It looks as if no code on my site calls ‘session_start()’. Is that good or bad?

    Thanks again.

    Mike

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Try it without the parentheses, but if it’s not in there, then it can’t be the underlying problem. Worth a shot anyway.

    Thread Starter 1337mirth

    (@1337mirth)

    Also ran the same query without the parens. Same thing, no results.

    Could it be a PHP problem? If so, any suggestions on what to look for in the ini files that might prevent connections to the API?

    Mike

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Okay, so, your REST API isn’t working. That is a definite problem. So the goal is to figure out why.

    The 10 second delay suggests a timeout, which is why I thought the sessions problem might be the cause, but failing that, I would look for interference from security plugins, bad .htaccess rules, maybe some mod_security problems if that’s active on the server, and so forth. I’d also look in the server error logs for anything that indicates an issue with requests containing “wp-json” in them. Also caching plugins could be interfering.

    The other problem you mention is this:

    If I go out to the
    filesystem (WP_ROOT/wp-content/blogs.dir/’blog_id’/files/%Y/%M/) the files are
    present with the correct permissions, but if I try to display them from the link
    given in the media library, I get a 404 error.

    Quite simply, that shouldn’t happen. Images and the like are served by the server, not going through WordPress at all… normally. The blogs.dir indicates an old style setup, where the images were routed through ms-files.php.

    So perhaps you should examine the URL for these images and why they’re not routing to the actual image files. If you’re missing the blogs.dir rule in your .htaccess then that would be a definite problem. The blogs.dir should rewrite to ms-files.php which does the routing of those.

    Thread Starter 1337mirth

    (@1337mirth)

    Otto:

    Thanks for sticking with me.

    Making some progress. It looks like my .htaccess file was missing the blogs.dir rule. I added this to .htaccess

    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]

    And all the media started showing up and displaying … PROBLEM SOLVED!

    However, I ran the Health check plugin and I still get the error connecting to the REST API. However, I’m using the Gutenberg editor and all the tags, blocks, etc are showing up and everything is completely functional. Also, I’m able to publish posts without any problems. (I’ve read that the Gutenberg editor requires the use of the REST API.)

    Also, no errors associated with wp-json in any of the server/php log files.

    Is it possible I’m still having issues with the REST API?

    Thanks,
    Mike

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    It’s possible that your server doesn’t have DNS enabled, so it can’t look up it’s own name, so that the loopback request that Health Check is making doesn’t work. The API would be fine in such a case, but the server can’t send an HTTP request back to itself, so the test fails.

    If the Health Check also reports the wp-cron as failing, this is more likely.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unable to display media in media library in 5.0.3’ is closed to new replies.