I have a website at /var/www/html, and i have a PHP script which uploads user selected image to /var/www/html/images. The script will not work unless I change permissions on on /images folder to write.

What would be the best option to allow the script to have write permissions on this folder? Or, it's something better done via PHP code, so that the PHP code opens the folder to writing everytime it's executed?

Or, maybe put the images folder outside /var/www and give it 777 permission there? (Or that's also not good)


The web-server must have write permission for the directory where the image is to be stored. There are 3 options:

  1. Let the web-server be the owner of the directory and set owner permissions on the directory to u=rw (644)

  2. Let the web-server's group be the group of the directory and set the group permissions on the directory to g=rw (664)

  3. Set the permissions for others on the directory for o=rw (666)

The first option is usually the best way to secure the directory.

But if you have no root access to the server it could be difficult to delete, move or rename files when accessed by FTP. If this is a serious problem, option 2 is justifiable.

There is usually no need to use option 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.