TL; DR: If you are having permission issues on pset7, you can fix them with the following three commands:
find ~/workspace/pset7/ -type d |xargs chmod 755
find ~/workspace/pset7/ -name *.php |xargs chmod 640
sudo find /var/lib/php5 -name sess_* |sudo xargs chown www-data:www-data
The Long Version:
There is definitely a problem with permissions on PHP sessions for apache50
in version 59 of ide50
. Hopefully, the CS50 folks will fix this in the next version.
Meanwhile, the apache50
log files are accessible at /home/ubuntu/lib/apache2/log/
and you may get a better idea of what is causing this error by restarting the server and watching the error log file via tail -f ~/lib/apache2/log/error.log
while trying to load a URL that gives you a 403 error.
Let's say you are having trouble loading pset7
, like many of us were in my class tonight.
Restart Apache with apache50 stop && apache50 start ~/workspace/pset7/public
and tail the error log in another Terminal tab.
Look for something like this:
[...] (13)Permission denied: [client 10.xxx.xxx.xxx:49208] AH00035: access to / denied (filesystem path '/home/ubuntu/workspace/pset7/public') because search permissions are missing on a component of the path
If you see the "search permissions are missing on a component of the path" error, then you need to make sure that all the directories in the full path to the server's root directory have the execute bit set for user and group. (Click here for the full explanation.) The Apache documentation recommends setting chmod 755
, but trial and error have shown that chmod 710
will suffice.
At first, some of us were messing up our directories by setting overly-lax permissions recursively (i.e., chmod -R 755 ~/workspace/pset7
will help you to load the webpage, but it's overkill.) If you have done this, you can (and should!) restore your permissions to the least possible privileges necessary.
The quickest way to accomplish this is to pipe the output of the find
command to xargs
as shown here:
find ~/workspace/pset7/ -type d |xargs chmod 710
Then, just in case you have already changed the permissions on your PHP files to anything other than 600, use a similar trick to reset them:
find ~/workspace/pset7/ -name *.php |xargs chmod 600
Finally, even after you have fixed the permissions on your files and directories, you may still have a problem with the PHP session files, as we did tonight:
[...] PHP Warning: session_start(): open(/var/lib/php5/sess_8o5fbcbb416acoorfj80egd6p0, O_RDWR) failed: Permission denied (13) in /home/ubuntu/workspace/pset7/includes/config.php on line 24
[...] PHP Stack trace:
[...] PHP 1. {main}() /home/ubuntu/workspace/pset7/public/index.php:0
[...] PHP 2. require() /home/ubuntu/workspace/pset7/public/index.php:4
[...] PHP 3. session_start() /home/ubuntu/workspace/pset7/includes/config.php:24
[...] PHP Warning: Unknown: open(/var/lib/php5/sess_8o5fbcbb416acoorfj80egd6p0, O_RDWR) failed: Permission denied (13) in Unknown on line 0
[...] PHP Stack trace:
[...] PHP 1. {main}() /home/ubuntu/workspace/pset7/public/index.php:0
[...] PHP 2. require() /home/ubuntu/workspace/pset7/public/index.php:4
[...] PHP 3. redirect() /home/ubuntu/workspace/pset7/includes/config.php:31
[...] PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php5) in Unknown on line 0
If you see this warning about session.save_path
, run ls -l /var/lib/php5
and look for the session referenced in the error log. You may find that it is owned by user and group ubuntu:ubuntu
. If so, this is part of the problem.
A temporary band-aid solution would be to sudo find /var/lib/php5 -name sess_* |sudo xargs chown www-data:www-data
so that the apache50
process will have appropriate permissions for the session.
Unfortunately, the real solution is to wait for the ide50
maintainers to correct the permission problems, and then run update50
again.
EDIT: (because I can't comment on mobile!)
@Dash: Are you sure you need to chown
your PHP session file? Are you actually seeing the warning about session.save_path
? I think they fixed this part of the bug with update50
after ide50
version 60 or so.
/home/ubuntu/workspace/pset8/ $ chmod 711 .
. For some reason, I didn't have to do this in problem set 7.