I'm working on a PHP site and I have my database password file behind
the server root directory.
I can reference the password file by include("../
database_password.inc.php"), but I would like to make the code more
portable and not have this relative path reference. Is there a way I
can know for certain what the home directory is called?
As i'm developing this project in version control, I sometimes
checkout a development branch. I want to interact with this branch, so
I put it in its own directory under the web root directory. E. g.
/home/user/website-root
hosts the site, and
/home/user/website-root/development-branch
is where I'm testing my development.
Of course, this breaks the relative path reference in the development
branch.
I could set up another parallel site, e.g.
/home/user/development-webhost-root/
and that would properly reference the password file, but I'd rather
just have my checkout under the web root. That way my code is more
portable, and I could deploy it
I could make a configuration file where I specify the reference, but
that adds an extra step when I do a checkout or export from source
control -- I need to copy in my local configuration file. It would be
great if I could have a "zero-configuration" app ( provided that the
password file already exists in the home directory).
I could try to figure out the home directory from the script path, but
that is based on the assumptions of the directory layout that this
particular hosting provider is using. If we deploy on another host, I
would have to have this "just work".
If could do something like include($_HOME . "/password.inc.php"); that
would make things so much simpler. Is this possible?