I was having trouble loading files for practice through apache, then found out in the discussions that there is a problem in the chmod commands and used the following 2 commands

cd ~/workspace/myfolder
find . -type d | xargs chmod 711
find . -name *.php | xargs chmod 640

And then used chmod 755 for the folder of the above mentioned directory and now im seeing the list of files through chrome but wanna know if seeing a .php file is normal? Cuz shouldn't the php files b hidden?


You are correct, the PHP files should be hidden.

More precisely, you should not have permission to view a directory listing for the Apache2 server's root directory and its subdirectories in a web browser.

Attempting to do so should display an HTML page that says something like this:


You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at ide50-your-username.cs50.io Port 443

If, instead, you see a directory listing that starts off with:

Index of /

... this is a security problem. It means two things.

First of all, Apache's root directory does not have an index.php or index.html file. It should have one. You can prevent Apache from generating such a list by creating your own index file.

Second of all, you have just discovered the real difference between using chmod 711 and chmod 755 for directories. I suggest that you immediately try setting the permissions of the root directory to:

chmod 711 ~/workspace/myfolder

and tell me whether you can still see your PHP files listed.


Can't reply in comments now (because mobile) but the answer to your questions are:

  • permissions for directories should be chmod 711, not chmod 755.
  • permissions for PHP files should be chmod 640.
  • the permission error is a good thing! You actually don't want to give all the Bad People of the Internet permission to see a listing of your PHP files!
  • if your file is called foo.php, you can view it in the browser by appending /foo.php to the default site URL.
  • if you want the default site URL to load a page, you must change the PHP file for the default homepage to index.php. But you can't rename all your files index.php, so you will also need to understand URLs and pathnames. (Hopefully, you have already done server.c, so you'll have some understanding of abs_path and query parsing.)

Hope this helps!

  • 1
    I was seeing files in "Index of" of form, with all html and php files visible but after chmod 711 ~/workspace/php/practice I am seeing nothing just the forbidden error you mentioned earlier, what command do I use if I am practicing a webpage to see thru chrome? should I use chmod 755 that make all the files visible or do i rechange the name of the website I make to index.html with chmod 711? Sep 12 '16 at 13:30
  • Thanks for accepting my answer. Does it make more sense to you now? Sep 16 '16 at 10:39
  • Not yet, did it for house keeping, having a lot of troubles at the moment on pset7 Sep 16 '16 at 15:27

You must log in to answer this question.

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