Reputation: 121
I already did a lot of research on including files outside of public_html but none have been working, so that is why I am posting.
My file structure is like this:
>home
>username
>includes
resources.php
>public_html
index.php
On index.php, I want to include resources.php so I have this:
include_once("/home/username/includes/resources.php");
However it does not work. If I change it to this for example (and also put another 'resources.php' in public_html) then it does
include_once("/home/username/public_html/resources.php");
Why doesn't the absolute path using 'includes' work? How can I use an absolute path for files outside of public_html?
Thanks in advance, and sorry if this would be considered a duplicate (I couldn't find anything specific like this).
Upvotes: 0
Views: 876
Reputation: 3896
It's very likely that the account the webserver & php runs as has no access to your home directory, so /home/username/includes/resources.php won't work.
You can check this with ls -l /home/username You'll probably see that the web server doesn't have any permissions to "includes".
If you check /home/username/public_html, I'll bet you find that the permissions do allow access by the web server, which is why it does work.
Upvotes: 0
Reputation: 511
For security reasons, PHP is usually restricted inside public_html, and has no access outside of that path.
Generally speaking, you should put all directories that you need access from PHP inside public_html, and also use relative paths.
Upvotes: 1