Matt Elhotiby
Matt Elhotiby

Reputation: 44066

PHP file permissions

I just launched an ec2 server and put all the php code on the server and I need to change the permissions so that a user cant go to the site like http:example.com/admin and see the list of php files....Do I need to change the permissions on the entire folder or each file or is there a recursive -R command that will work ...I think they are all currently 777 ...which is bad

Upvotes: 1

Views: 262

Answers (3)

Mayank
Mayank

Reputation: 1

Try inserting this PHP code:

<?php
if ($_SERVER['HTTP_CLIENT_IP'] == "insert_your_clientip_here") {
  echo "";
} else {
  return;
}

or use a password

<?php
$password="mypasswordhere";

if (isset($_GET[$password]);) {
  echo "";
} else {
  return;
}

then go to admin.php?mypasswordhere (this isn't brute force proof so use a very strong password)

Upvotes: 0

Jeff Parker
Jeff Parker

Reputation: 7507

Assuming you want to disable just the listing of files, and not access to the files themselves, then you'll want to disable the INDEXES option in Apache for that folder. Something like this in the apache config would probably be best.

<Directory /www/somefolder>
    Options -Indexes
    AllowOverride None
</Directory>

Upvotes: 1

JamesHalsall
JamesHalsall

Reputation: 13485

If your website is in an admin folder in the root of your webserver you can drop a .htaccess file in the admin root containing:

IndexIgnore *

Upvotes: 0

Related Questions