2

I am working on PSet 8, and I have done all the chmod steps as per the specification, but when I try to open my website, I get:

Forbidden

You don't have permission to access / on this server.

Apache/2.4.7 (Ubuntu) Server at ide50-username.cs50.io Port 443

where username is my username.

I am unsure as to how to proceed because I have tried the chmod steps multiple times, and still cannot gain permission to my own site.

In addition, when I try to open my phpmyadmin, I get this error:

phpMyAdmin - Error
The mysqli extension is missing. Please check your PHP configuration. See our documentation for more information.

I have tried the update50, and am running version 65 of the ide50.

Any help would be very much appreciated!

2 Answers 2

6

According to this post on the CS50 Reddit, the permissions have changed since a recent update50, and the documentation has not been updated to reflect the changes.

In my experience, you'll need a minimum of chmod 711 for directories, chmod 640 for PHP files and config.json, and chmod 644 for HTML, CSS, JavaScript, images and font files.

Open a Terminal tab in the IDE, and execute the following commands:

cd ~/workspace/pset7
find . -type d | xargs chmod 711
find . -name *.php | xargs chmod 640
chmod 644 public/css/*
chmod 644 public/img/*
chmod 644 public/fonts/*

If that does not work, execute the following commands for troubleshooting purposes:

cd ~/workspace/pset7
ls -l
ls -l public

Copy and paste the output of these commands into your original question above, then highlight the whole thing and press Ctrl-K (or click the Code Sample button in the editor, which looks like { }). Please don't paste your permissions in the comments -- edit your original question. Thanks!

EDIT: for Problem Set 8

Open a Terminal tab in the IDE, and execute the following commands:

cd ~/workspace/pset8
find . -type d | xargs chmod 711
find . -name *.php | xargs chmod 640
find . -name *.js | xargs chmod 644
chmod 644 public/index.html
chmod 644 public/css/*
chmod 644 public/img/*
chmod 644 public/fonts/*

I think that should be sufficient. I'm on mobile now and can't test this out. Please let me know whether or not it works!

Also, I've answered many similar questions in greater detail, so feel free to poke around in my Answer history for more info.

EDIT2: Here's a more detailed explanation, based on an answer I wrote elsewhere:

To resolve the issue, you can spend a long time tinkering around with individual permissions on files and directories, which probably sounds like a big waste of time.

Luckily, there is a better way. You can very rapidly use the Linux find utility to find all the files that need changing:

find ~/workspace/pset8 -type d
find ~/workspace/pset8 -name *.php

Try it yourself! That's exciting, isn't it? Note that the first command returns all the directories, and the second one returns all the PHP files. But then we need to "pipe" the output of that command to xargs, which will execute a command using that output as its input.

In this example, we will list the permissions of all the PHP files:

cd ~/workspace/pset8
find . -name *.php | xargs ls -l

Note that this trick doesn't work the same way with directories. Think for a moment about what would happen if you executed find . -type -d | xargs ls -l, or just try it for yourself. It doesn't show you the permissions on the directory!

Luckily, it is easy to use the find | xargs pipeline to set the permissions:

cd ~/workspace/pset8
find . -type d | xargs chmod 755
find . -name *.php | xargs chmod 644

This version does work as expected, both with regular files and with directories.

Try that, and you will see how quick and easy it can be to resolve these permission issues in the future.

Unfortunately, once you have used chmod -R 777 *, it's not so easy to reverse the damage. Imagine that you have a magic wand that can make anything change color to a single color of your choosing. You can use your magic wand to turn a rainbow all red! But you cannot use the same wand to make it change back to "rainbow" -- you can only make it all blue, or all yellow, or all green.

4
  • In your answer, you used pset7, so I was wondering if this would work also for pset8.
    – user11799
    Commented Aug 28, 2016 at 15:07
  • It works! Thank you so much! The only thing is, if you have time, could you explain what you did?
    – user11799
    Commented Aug 29, 2016 at 2:41
  • Sure, no problem! I think I explained it pretty well over here, and I can edit my answer above to contain part of that explanation. Commented Aug 29, 2016 at 12:35
  • 1
    Thank you very much for this post!! Commented Oct 19, 2016 at 6:23
2

Based on the above from Matt Obert, I created the following bash script - bashPermsv2.sh - in the pset8 folder. Ran it from the terminal with:

'~/workspace/pset8/ $ sh bashPermsv2.sh'

and it resolved the Forbidden problem. My first use of a bash script.

'#!/bin/bash
find . -type d | xargs chmod 711
find . -name *.php | xargs chmod 640
find . -name *.js | xargs chmod 644
chmod 644 public/index.html
chmod 644 public/css/*
chmod 644 public/img/*
chmod 644 public/fonts/*
echo "\nPermissions changed\n"'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .