1

I had issues with accessing my website at cs50.io, but thanks to great help I received here I have managed to set up correct permissions to all files and folders and thus access the site. Although I have set up correctly all permissions, including for the vendor folder and CS50.php, I get errors when I try to run search.php:

Warning: require(../vendor/library50-php-5/CS50/CS50.‌​php): failed to open stream: Permission denied in /home/ubuntu/workspace/pset8/includes‌​7;config.php on line 20; 

Fatal error: require(): Failed opening required '../vendor/library50-php-5/CS50/CS50.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/pset8/includes/config.php on line 20

Here are my permissions for the vendor folder, CS50.php and config.json

drwx--x--x 3 ubuntu ubuntu 4096 Oct 26 2015 vendor/ 

-rw-r----- 1 ubuntu ubuntu 13919 Oct 31 2015 CS50.php
-rw-r----- 1 ubuntu ubuntu 150 Aug 17 08:16 config.json

I will be grateful for your help! I don't understand what's happening with these permissions. I am among less comfortable, so I do get frustrated by these type of issues, though I do my best to search for possible solutions. Thank you very much!

2 Answers 2

3

@Vitale: I feel your pain! Permission errors can be really frustrating. You are impatient to get back to work, and in your haste, you reach for chmod -R 777 *, the biggest sledgehammer in your toolkit.

It probably feels like you have solved your problem, because the permission errors have gone away. Now you can get back to work!

But chmod -R 777 * is never the right thing to do, despite all the bad advice on the Internet urging you to do it.

If you make a habit of "solving" your permission issues this way, you may someday find that the PHP ZenCart instance you set up with sloppy permissions for your first business client has been hacked, and all of your client's customers have had their credit card info stolen.

This is a golden opportunity to learn how to do things the right way. For future reference, here's how you should react to this error message:

Warning: require(../vendor/library50-php-5/CS50/CS50.‌​php): failed to open stream: Permission denied in /home/ubuntu/workspace/pset8/includes‌​7;config.php on line 20; 

The permission error is triggered by line 20 of config.php, which is trying to require(../vendor/library50-php-5/CS50/CS50.‌​php):. Therefore, there is a problem with either the permissions on the CS50.php file, or one of the directories in the path to that file.

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:

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

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 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.

To set up correct permissions for a freshly-unzipped pset8, the following commands may help:

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

Note: I have just tested these exact commands on my own pset8 directory and can confirm that the Mashup still loads in my browser.

To restore your permissions to sensible defaults after using chmod -R 777 *, the following commands may help:

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

Note: I have not tested these exact commands on my own pset8 directory, because I have not used chmod -R 777 * on it, but I believe that they will help to repair the damage without causing trouble with the Mashup website.

By the way, if this helps you to resolve your issue, please let me know by clicking on the green checkmark. Otherwise, this will forever haunt the forum as a zombie unanswered question.

1
  • 1
    I totally agree with you and I understand that I should never use chmod 777 in "real life", but i got so confused with these permissions that I, far from being a professional yet, assumed that this issue is beyond my current capacity. I will follow your advice, and I will reset all my previous permissions, which I have set correctly thanks to your great help, and then see what's happening with access to CS50.php. Thank you!
    – Vitale
    Aug 22, 2016 at 16:32
-1

Solved by setting chmod to 777 for all folders and files in pset8. I have no idea what is going on with the IDE, but being less comfortable I can't find another way to proceed with this pset. At least now I see the object and can move on )

1
  • This is bad advice. Please see my answer for a more detailed explanation. Aug 22, 2016 at 0:27

You must log in to answer this question.

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