Forum Moderators: coopster
This is test.php (which is in the httpdocs directory):
<html><head></head><body>
<?php
require_once('/srv/www/vhosts/website/httpdocs/aboveroot.php');
?>
</body></html>
This is aboveroot.php (which is also in the httpdocs directory):
<?php echo 'it works';?>
This works fine. But what I want to do is put the aboveroot.php file in the folder /srv/www/vhosts/website/otherthanroot/ directory (for better security) and update the test.php file accordingly...yet this does not work. I've changed the permissions of the otherthanroot directory and still no luck. Is this a configuration file problem?
what error messages are you getting in the server logs?
what are the permissions and ownership of the directory and the file.
under what user is the server running?
[edited by: eelixduppy at 1:12 am (utc) on Nov. 13, 2007]
[edit reason] fixed link [/edit]
require_once('/srv/www/vhosts/website/httpdocs/aboveroot.php');
/httpdocs/ is the root directory for the domain (on shared *nix hosting), so any other directories have to be relative to that in the filepath. Like this:
/httpdocs/includes/aboveroot.php
<?php require_once("includes/aboveroot.php");?>
[edited by: Marcia at 1:05 am (utc) on Nov. 13, 2007]
I'm afraid I don't know how to find out the answers to questions 1 and 3, but I set the permissions to both the file and the directory it is in to 777 just to make sure that that wasn't the problem.
Where might I find the erro logs and server user info?
the error logs are specified for each virtual host and/or the server itself with the ErrorLog directive in the httpd.conf file.
to get the server user info, you could try something like "ps -aux¦grep httpd" and see what's in the user column.
(change the broken bar above to a solid vertical bar!)
Example 16.9. include() and the return() statement
return.php
<?php
$var = 'PHP';
return $var;
?>
noreturn.php
<?php
$var = 'PHP';
?>
testreturns.php
<?php
$foo = include 'return.php';
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
?>
PHP Fatal error: main() [<a href='function.require'>function.require</a>]: Failed opening required '/srv/www/vhosts/website/otherthanroot/aboveroot.php' (include_path='/usr/share/php5') in /srv/www/vhosts/website/httpdocs/test.php on line 3
(line 3 being the require_once statement)
PHP Warning: main() [<a href='function.main'>function.main</a>]: open_basedir restriction in effect. File(/srv/www/vhosts/website/otherthanroot/aboveroot.php) is not within the allowed path(s): (/srv/www/vhosts/website/httpdocs:/tmp) in /srv/www/vhosts/website/httpdocs/test.php on line 3
PHP Warning: main(/srv/www/vhosts/website/otherthanroot/aboveroot.php) [<a href='function.main'>function.main</a>]: failed to open stream: Operation not permitted in /srv/www/vhosts/website/httpdocs/test.php on line 3
The whole reason I'm trying to do this is that I want to store a mySQL database access script outside of the website directory structure in order to make it more secure.
Will you be changing the whole filepath structure of your server?
Added:
security for php includes at php.net [google.com]
[edited by: Marcia at 5:56 pm (utc) on Nov. 13, 2007]
thanks phranque, but I'm not kidding when I say newbie: how do I put it into safe mode, etc. what specifically do I need to change and where?
you're calling yourself a newbie?
i've actually never written a line of php code.
in five minutes or less you can know as much or more than i know about php safe mode [us3.php.net].