i'm almost done with the pset7 and this happend , something has gone wrong and cant figure it out . first i couldn't get the apache50 to start then i found this on web "echo > ~/lib/apache2/log/error.log" after that the apache50 worked but got an 403 error when loading the page then chmod 775 the pset7 directory now again stuck with this ."Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
CS50 course materials will tell you that the permissions need to be set as follows:
chmod 711 for directories
chmod 600 for PHP files.
In general, this is the correct advice.
However, if you have run
update50 recently, you should know that there is a bug requiring
chmod 640 instead for PHP files.
I've posted this elsewhere, but the quickest way to get what you want is to change directory to your project's workspace (in the example below,
~/workspace/pset7 ) and execute the following commands:
find . -type d | xargs chmod 711
find . -name *.php | xargs chmod 640
Hopefully, that will do it!
EDIT: In your case, you might also need to make certain that all the directories in the full path to your pset7 folder are set to
chmod 711. The full path to your directory should be
/home/ubuntu/workspace/pset7, so you should reset the permissions of the following directories:
chmod 711 /home/ubuntu/workspace/pset7
chmod 711 /home/ubuntu/workspace
chmod 711 /home/ubuntu
And, if necessary:
sudo chmod 711 /home
sudo chmod 711 /
(These last two should not be necessary, but I'm including them just in case!)
chmod 640 config.json
config.json does not need to have the execute bit set for user, group, or world. In particular, it should never be world-readable, world-writable, or world-executable. This file contains your database authentication credentials in plaintext. You don't want that info in the wrong hands! So, in the real world, you would set this to
chmod 600 just like your PHP files. However, in the current situation,
chmod 640 is temporarily required due to a bug.
EDIT THREE (2016-08-05):
Looks like the
ide50 maintainers have released version 60! Go ahead and run
update50 and hopefully it will fix all of the permission problems!
If this helps you to resolve your issue, please click the green check mark to accept my answer. Otherwise, the forum will forever list this question as unanswered!
It looks like the permissions have changed permanently (at least, the group read access will still be required for PHP files and config.json) and the problem specifications will need to be updated to reflect the new permissions. See this post on the CS50 Reddit for more info.
Setting aside the issue of whether the new permissions are "better" or "worse" than the old ones, I actually think this situation could be a blessing in disguise, since it's a great opportunity to teach people about debugging site permission issues with the Apache2 error log -- something you will spend many hours doing if you pursue a career as a professional web developer! ;)
THE LAST WORD:
This question seems to have become a magnet for traffic on this topic, so I'm updating it to announce that I've collected my advice on this topic from several sources into a catch-all document called 403 Forbidden / permissions / chmod -- the definitive guide on the CS50 Reddit.
Next time you see a 403 Forbidden error when you try to load a page, watch the Apache error log in the Terminal by executing the following command:
tail -f ~/lib/apache2/log/error.log
before reloading the page in the browser. You may find a more specific error message there. Meanwhile, don't lose heart! This process of reading Apache logs and PHP error messages to help resolve permission errors or other issues is actually something you'll do all the time as a professional web developer, so think of it as valuable practice rather than a waste of time!