Forum Moderators: coopster
perhaps there is another way?
/var/www/html/index.php
i can use the chdir and getcwd together to get to the root and actually see it print on screen. i've chdir[ed] it to here
/
in the root, i have a folder which i can store stuff, and i can successfully chdir to it. but when using the include function it is unable to include that file. i can however include files from the /html folder without using any absolute or relative path. just a simple include("file.php") works. technically i am in the root folder, so i thought i;'d need to do something like include ("var/www/html/file.php"), but i dont and it still works, which makes this all so bizarre.
anyone know why this is so?
You may want to try changing your include to require and see if that gives you more information on the error, as require will result in a fatal error as opposed to include that doesnt.
I don't think so. If using the full path works go with that. It's much easier to follow when you are coding, too, if you use the full path.
anyone know why this is so?
If you can include a file in a specific directory using just include("filename.php"), that probably means that PHP's default include_dir is set to that directory. This is the first place that PHP will look for files that are "include"d in your code.
Giving modules (like PHP) access to directories outside of the document root is considered "bad practice" when using Apache - there is most likely a directive somewhere, whether in the httpd.conf, .htaccess or folder permissions that will forbid PHP from accessing the folder that you are trying to access.
It sounds like a permissions issue, since apparently PHP can point to the directory but cannot read from it.
I usually have folders like the one you are describing parallel to the "html" or "public_html" (web root) directory in the user folder:
/usr/home/website/public_html <- Web Root
/usr/home/website/files <- Not web-accessible, but should be able to be read by PHP without a problem.
Hope this helps,
SK
Giving modules (like PHP) access to directories outside of the document root is considered "bad practice" when using Apache
It's considered "best practices" to put files containing certain information outside of the document root, so necessarily, PHP would need to have access to files outside of the document root.
For example, sql connection data (username and password) is almost invariably recommended to be placed in a file outside of the document root and subsequently included from that location.
Paranoid/ignorant web hosts limit perfectly valid tools and claim it's for security reasons when it's actually just a reflection of their lack of understanding about how to secure their systems.
It's considered "best practices" to put files containing certain information outside of the document root, so necessarily, PHP would need to have access to files outside of the document root.
You are correct, sorry about the confusion - I was using "Document Root" in the Apache sense, i.e. the /home directories. I did not mean the first web-accessible directory of a domain to be defined as the "Document Root".
I agree, it is certainly best practice to put data such as database login info outside of web-accessible directories, and it follows that PHP needs to be able to access the directory that the information resides in, but I don't think that this information needs to reside outside of the /usr directory.
In any case, it still sounds as though the original poster is having a permissions issue with PHP on their server, we'll have to see what they discover.