PHP include path for LAMP server

Hello,

Over the last couple of days I have switched from Ubuntu 10.10 to OpenSUSE 11.4_x86_64bit. I really love it and am impressed that Google chose this platform for their ChromeOS. My question is this: I just finished installing my LAMP server and I’m getting results from the files I had saved from my Ubuntu LAMP server. However, I can’t seem to get the file string right for my PHP include functions. With Ubuntu the path was written like this <?php include("file:///var/www/test/RHphp/titleheros.php. After getting everything running I would have suspected that the path on OpenSUSE would be <?php include("file:///srv/www/htdocs/test/RHphp/titleheros.php but this doesn’t seem to be working when I browse localhost. I don’t recall ever having to configure the php.ini file or anything like that. Can someone help me with what I’m missing please?

Thank you,

Scott~

That kind of absolute path is poor PHP programming. Just remove the full path and use a relative path, assuming the app is called RHphp:

include “titlehereos.php”;

Or better still, use require_once, which is more resilient:

require_once “titlehereos.php”;

Hi there,

Welcome to the forum!

Key Yap is right, really the best approach is not to use full path names, and there is no reason to do so here.

However, what you are trying to do will in fact work fine - there is no difference in behavior between Ubuntu and Suse here.

include(“file:///srv/www/htdocs/test/RHphp/titleheros.php”);

Should work fine - but really, just use relative paths instead.

You can also trun on PHP warnings to help debug any issues with path names, permissions, etc. like this:

<?PHP

ini_set('display_errors',1);
error_reporting(E_ALL);

echo "This is an include test:";

include("file:///srv/www/htdocs/something.php");

?>

Thank you all for your suggestions!

I will be practicing more with my PHP scripts. I picked up the long path strings from a friend of mine and never took the time to research a different way of doing it. It’s a pain when I transfer the test files from my LAMP server to my live DNS and have to change all the paths around accordingly.

Here’s an idea though that seemed to work. Try setting the file permissions right Scott, so that the server can GET to your PHP files. (DUH!) :\

If you have to use absolute paths, say because the included files are in a library, at least use a defined constant for the path so that it can be edited in one place.

include LIBRARY_PATH . “somelib.php”;

Remember to put a trailing slash in LIBRARY_PATH in this case.