So I was having issues with Root not being able to use fopen/fwrite through PHP and tried typing this hoping it would help (found it on another site)

chmod -R 766 /var/www/html

Andddd now I can access the domain through my web (http://x.x.x.x) but can no longer get to http://x.x.x.x/foldername or anything inside it

Sorry for the stupid question but how do I fix this? I'm new with Ubuntu stuff

up vote 0 down vote accepted

You need to grant both read and write permission to the protected directory with sudo. I suggest you do this on just the project not the whole /var/www/html directory. Here you go, on your terminal type sudo chmod -R 777 /var/www/html and then it should ask you for password because you used sudo, enter your system's password, you most likley won't see the password as you're typing, that's also fine just carry on and hit enter. Then run your php project again.

  • This worked, thank you so much!! Hopefully helps others with the same problem – TTT Dec 7 at 11:29

I`ll explain about correct file permissions for www. First find what user and group apache is using. Www files should have owner is user who edit the files, and group from apache. Permissions should be "rw" for user, "r" for group, and folders should also have X permission. For folders used by php to write something add "w" permission for group.

Find user name used by apache: ps -aux|grep apache You`ll see something like www-data

Change ownership to you and group: sudo chown -R yourusername:www-data /var/www

Change permissions: chmod -R u=rwX,g=rX,o= /var/www

Add write access for scripts to certain folders, what used as cache or similar: chmod -R g+w /var/www/html/templates_cache Do it for each folder what in need for write access.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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