Question

imagemagick can't overwrite files on Ubuntu 16.04

I’m overlooking something to do with permissions for imagemagick. I set up a new Ubuntu 16.04 droplet exactly as per the DO guide, giving my new user root privileges etc. Ditto for the LAMP stack, exactly per the DO guide and everything ran well.

I install imagemagick. It works fine, I can do various commands with it, it’s resizing and saving images I upload, until…

It won’t overwrite any of the existing images it had previously saved. It throws:

object(ImagickException)#2 (7) { ["message":protected]=> string(105) "unable to open image `/var/www/public_html/images/abcd.jpg': Permission denied @ error/blob.c/OpenBlob/2712"

This is running fine on with the same code on my local LAMP development server, so I’m pretty sure it’s a permissions issue (as well as it stating so in the error). What I don’t understand is that I can write to the folder ok, just not overwrite? All images, their folders and parents have 755 permissions. I’m a bit lost.

I have nothing else unusual going on in terms of users. PHP executing a userinfo request on the page states the user is www-data.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

In order for imagemagick when running as part of a PHP script to write files you would need to give permissions to the www-data user and/or group. If you uploaded these files with your user account or as root you would need to set these permissions manually. For example, if your web root is the default of /var/www/html then you could run:

chown -Rf www-data:www-data /var/www/

Ryanpq, me has llevado a conseguir la solución; Ya lo solucioné, el error era por que yo había subido una imagen para hacer la prueba, pero la subí con el usuario root, y al intentar convertir la imagen con el apache desde php me generaba el error, y lo que hice fue subir la imagen por medio de php y ahora si me deja convertirla. Muchas gracias.