Forum Moderators: coopster

Message Too Old, No Replies

goto root directory

how to?

         

d40sithui

3:34 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



does anyone know how to goto the root dir on a LINUX server. I mean like go to parent directory of public_html. i want store a really secure file there and then use the iinclude function to get it when i need it. is this even possible. are there limitations for using the "../" command in include functions? i've obviously tried something like
include("../../../home/mydir/my_secure_script.php"); //doesnt work

perhaps there is another way?

eelixduppy

3:43 pm on Jul 24, 2007 (gmt 0)



Use the full path to the file; don't try to use a relative path.

d40sithui

6:28 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



yea. so heres my directory structure

/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?

PHP_Chimp

7:33 pm on Jul 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no limit to the use of ../ in your include path, so as long as you can access that directory then you can include files from it.

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.

d40sithui

11:37 am on Jul 25, 2007 (gmt 0)

10+ Year Member



yea i used ../ a lot, it hasnt worked. could this be a rights issue from parent directories.

eelixduppy

5:59 am on Jul 27, 2007 (gmt 0)



>> could this be a rights issue from parent directories

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.

d40sithui

5:24 pm on Jul 27, 2007 (gmt 0)

10+ Year Member



yea it doesnt lol or maybe im doing it wrong. could you give an example.

StudioKraft

6:04 pm on Jul 27, 2007 (gmt 0)

10+ Year Member



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

whoisgregg

9:05 pm on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

StudioKraft

12:29 am on Jul 28, 2007 (gmt 0)

10+ Year Member



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.