Question

PHP error log issue chmod 777

So I am trying to get PHP save error logs automatically to the directory where the script containing error is. But the problem is that error logs are not written unless I set permission 777 to all directories manually. And that is something I wouldn’t want to do due to security issues.

So I tried this

chgrp www-data /var/www
chmod g+w /var/www

But, unfortunately, it didn’t help. Any other advice?

Thank you!

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Ryan Quinn
DigitalOcean Employee
DigitalOcean Employee badge
June 10, 2016
Accepted Answer

This question was answered by @ryanpq:

Without a bit more information it’s difficult to know the exact problem but I do have a thought on how you might resolve this. Assuming that 1.) You are on Ubuntu and 2.) That this script is running via Apache or nginx you can set the ownership of the directory to www-data which is the user that the web server process is running as. Doing this should allow your script to write properly without setting 777 permissions.

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

This will set the permissions for the entire default Apache web root.

View the original comment

This is quite old question, but asking here anyway since it’s strongly related. So the problem is that I need to use above command (chown -Rf www-data:www-data /var/www) every time after creating a new directory. Is it possible to make new directories automatically get the same ownership as the parent directory so that I wouldn’t need to manually run the command?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.