• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

require_once Path Error in PHP and Apache

I'm developing a moderately sized website using Dreamweaver CS4 and I've run into a problem with PHP and Apache.  I'm using the most current release versions of each program and I've divided my site into folders primarily for organization.  The problem is that if I have any php files that include php files that include other php files if the base php files are located in a sub directory the includes usually work but in the site root Apache complains in the error log that the files being included in the first included file cannot be found. I've included the relevant PHP files but cut out all the html and php functions to keep them reasonably sized.  The default.php is the default page that opens up when the site is typed in, rotator.php is a php file that include functions for a banner ad type system, and the connBDBannerAds.php is the automatically generated MySQL connection file by Dreamweaver.  Dreamweaver is just fine with all the links but Apache outputs this when it runs:

[Fri May 22 22:42:10 2009] [error] [client] PHP Warning:  require_once(../Connections/connBDBannerAds.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test\\PHP\\rotator.php on line 1
[Fri May 22 22:42:10 2009] [error] [client] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '../Connections/connBDBannerAds.php' (include_path='.;C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test') in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test\\PHP\\rotator.php on line 1

I'm using relative links right now but I've also tried site root ones as well where Dreamweaver changes all the require_once lines with virtual.  I also tried prefixing all the paths with / to make it use the site root but that didn't work either.  
This is my first post so if I forgot to put something in or put too much in please let me know.  Thanks in advance for your time.
<?php require_once('Connections/connBDCustomers.php'); ?>
<?php require_once('PHP/rotator.php'); ?>
if (!function_exists("GetSQLValueString")) 
     .... Other php stuff ....
<?php require_once('../Connections/connBDBannerAds.php'); ?>  <-Problem Here I think
function rotator()
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connBDBannerAds = "localhost";
$database_connBDBannerAds = "bdbannerads";
$username_connBDBannerAds = "root";
$password_connBDBannerAds = "test";
$connBDBannerAds = mysql_pconnect($hostname_connBDBannerAds, $username_connBDBannerAds, $password_connBDBannerAds) or trigger_error(mysql_error(),E_USER_ERROR); 

Open in new window

  • 2
1 Solution
Todd MummertCommented:

The paths are not relative to where they're stored, but relative to the include path.

I don't fully understand your layout, but if the directories PHP and Connections are in the same directory, you could probably change your the path to Connections/connBDBannerAds.php

You could also change the include path, or use something based off of DocumentRoot.   See


for a similar problem and solutions
William-BAuthor Commented:
Thanks for your  quick response I had set the include directory to point to the site root pretty much, so i took out all of the ../ and / in the require statements and that seems to work just fine.  I had done that before, but it messes up all the recordset and other server behaviors in Dreamweaver so I had undone it thinking I messed something up.  Do you know of anyway to make it so Dreamweaver recognizes custom include paths for php scripts?  At any rate what you suggested did solve my problem, which I appreciate very much so I'm just going to mark this as solved.
William-BAuthor Commented:
Thank you for your prompt solution.  It worked great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now