Aakash Yadav
Aakash Yadav

Reputation: 615

Deny php script to access parent directories

I have created an online php compiler. The problem is that it makes my server vulnerable to the hackers. So i want to give the compiler a separate directory and restrict php script access to that directory only. I have tried this

<Directory /parentDirectory/childDirectoryOne>
  php_admin_value open_basedir "/parentDirectory/childDirectoryOne"
</Directory>

But this created another problem. I was no longer able to open than page of website. It gave me internal server error. If I can restrict php to read, edit or delete files outside the directory that will also work or if I can restrict php to read, edit or delete all files with one exception. I have cpanel for website so I can only do that through .htaccess.

Upvotes: 0

Views: 102

Answers (1)

user1589416
user1589416

Reputation:

This can be done at the operating system level. Create a new user and only give them access to the coding directory and launch the PHP process as that user.

But your code is wrong open_basedir "/parentDirectory/subDir" means even the PHP engine executing your index.php script can not run if it isn't in subDir. You could static code the parentDirectory or use my solution above. Storing open_basedir value in an apache file does not prevent execution by PHP-CLI or the command line.

Upvotes: 1

Related Questions