Forum Moderators: coopster

Message Too Old, No Replies

include not working

         

newmanity

12:50 am on Nov 13, 2007 (gmt 0)

10+ Year Member



Hi. I'm sure this is not a difficult issue, but I'm a newbie and I'm stumped.

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?

phranque

12:57 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], newmanity!

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]

Marcia

1:04 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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]

newmanity

1:07 am on Nov 13, 2007 (gmt 0)

10+ Year Member



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?

newmanity

1:09 am on Nov 13, 2007 (gmt 0)

10+ Year Member



For security reasons, I have been led to understand that it's better to put password info to databases above the httpdocs directory, which is why I'm trying to do that.

Marcia

1:23 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The way you have it in your first post, you're trying to replace httpdocs with another directory name, and you can't do that on virtual hosting. The server is set up so that httpdocs MUST be the root for the domain. It has to be /httpdocs/higherdirectory/filename.php

phranque

5:59 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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!)

PHP_Chimp

8:47 am on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a suspicion that you problem lies within trying to include an echo statement.
As the include file inherits whatever scope is within the line it is called on. So unless you have something like
$test = include(.....); // and im not even sure this would work
you are calling an echo statement part way through a set of code. This echo statement is not attached to anything. So im guessing that you error is something along the lines of "unknown T_STRING at line ..."?
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
?>

From the manual. Seeing as you havent told us what the error is Im only guessing...It does make it a lot easier to guess the problem when you let us know what the error is ;)

newmanity

12:00 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



The error log is giving me the following errors:

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

newmanity

12:06 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



Marcia, I have root access to the server and am able to create directories above the virtual host web root httpdocs directory. Is it still not possible to include files from somewhere other than a subfolder within the httpdocs directory?

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.

phranque

3:47 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you probably have to set up safe mode for your php config and the safe mode include directory.

newmanity

5:46 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



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?

thanks.

Marcia

5:53 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you intend to replace the http_docs directory with another name, thereby eliminating http_docs, where do you intend to put the homepage of the site, instead of it being in the default root for the domain (http_docs)?

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]

newmanity

9:32 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



Hi Marcia.

I'm not trying to replace the httpdocs directory, I simply want to include/require a single file residing outside of it. The site (including the file that will include the other) will be under the httpdocs directory.

phranque

12:53 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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].

newmanity

1:50 am on Nov 14, 2007 (gmt 0)

10+ Year Member



that's hysterical, phranque...totally untrue I'm sure, but hysterical!

phranque

1:53 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



100% true!

i am actually pretty fluent in perl but for some reason i end up answering way more questions in the php forum - go figure!