olliz
By:
olliz

PHP error log issue chmod 777

July 30, 2015 1.7k views
PHP Apache

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!

2 comments
  • 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.

  • thank you very much !
    I had to change it to:

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

    And then it worked.

1 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

Have another answer? Share your knowledge.