I’d like to make a file on my server be readable by PHP, but not directly accessible with a browser. Say my Apache installation’s root is /apache. I’d like PHP to be able to get the text of /apache/1.txt
, but not allow the user to go to domain.tld/1.txt
and view the contents. I’d still like to be able to read/write the file through FTP/SFTP without root.
What would be the propper chmod
string for this? 642 seems likely, but I’m not sure how PHP accesses the file.
Redirect all request coming to /1.txt
to something else using .htaccess
or apache
configuration. So, if some one will try to access domain.tld/1.txt
, it will redirect.
EDIT
Example:
suku@ubuntu-vm:/var/www/html$ grep info.php /etc/apache2/sites-available/default
RedirectMatch ^/info.php /html/index.htmlsuku@ubuntu-vm:/var/www/html$ sudo cat ../info.php
<?php
phpinfo();
?>suku@ubuntu-vm:/var/www/html$ cat index.html
You redirected to here becuase you tried to access localhost/info.php
suku@ubuntu-vm:/var/www/html$ pwd
/var/www/htmlsuku@ubuntu-vm:/var/www/html$ links http://localhost/info.php -dump
You redirected to here becuase you tried to access localhost/info.phpsuku@ubuntu-vm:/var/www/html$ cd ..
suku@ubuntu-vm:/var/www$ ls -l info.php
-rw-r----- 1 www-data www-data 20 Jan 12 11:25 info.php
Check more discussion of this question.