Wordpress image editor not working on LEMP 16.04

February 27, 2017 153 views
LEMP WordPress PHP Ubuntu 16.04

Can't get image editor to work in WordPress Media, only shows this error message "Could not load the preview image. Please reload the page and try again."

I went to see if I have both gd & imagick installed and enabled

Running both these commands I can see that they are enabled and installed

php -i | grep -i gd
php -i | grep -i magick

and reloading using

sudo service ph7.0-fpm restart

it still doesn't work. Also enabled debugging/debug log in wp-config.php to see if anything shows up but nothing in the error log.

2 Answers

@greensociety

Have you checked user permissions on your files and directories? By default, PHP-FPM runs as the www-data user, so all files and directories would need to be owned by that user in order for PHP to be able to read/write.

You can cd to your root directory (where ./wp-config.php is) and run:

ls -al

... and that should give you the user and group that owns the files. If it's root or another user, you can run:

chown -R www-data:www-data /path/to/root

... and that'll change permissions to www-data, thus allowing PHP to read and write to files.

From what I can tell, you need to dig into your PHP error logs (might show up in Nginx error logs).
This is usually caused by a WP plugin (or theme) that has a space after the code, which results in a "header already sent" error from PHP.
Try disabling all your plugins and changing theme to default 2017 and see if that helps. If yes, then active one-by-one.

  • @greensociety

    Having white-space and closing tags (i.e. ?>) at the end of files can definitely cause some rather strange behavior, so that would be the next thing I'd look at as well.

    I'd check functions.php as well as other files in your theme, as well as any custom code and make sure that you remove any white-space at the end as well as any closing tags.

Have another answer? Share your knowledge.