Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web server that we use, apache, centos5, php

I have a file called 'include.php' that I need to include in multiple sites.

Eg. I have a site called, now in the index.php i want to include the include.php file, the include.php is not in the root of,

Now i created another folder includes in the web root directory which contains include.php

my code looks as follows in

require_once '../includes/include.php';

if i run it can't detect include.php. Is there a certain server setting I need to change in order to include this file?

My directory structureof


Hope this makes sence

share|improve this question
up vote 3 down vote accepted

Keep in mind that when using require '../[something]', you're referring to the working directory of PHP, not the path of the actual script. I prefer to always use


This way, I know I am requiring a file relative to the file that the require statement is in

So in that case, your include would be:

require_once( dirname(__FILE__).'/../includes/include.php');
share|improve this answer

This was asked long ago, but for anyone finding it via google, the correct answer is to make sure this file is in the PHP include_path that is set in the php.ini OR add your path to the php include_path via the php.ini or at runtime via set_include_path() php function [ ]

You file can then be accessed via include('myfile.php') or require('myfile.php') that both search the PHP include_path as well as the current directory for the file to be included.

You might also look into __autoload() in php 5.2 or lower or SplAutoloadRegister() in php 5.3 and 5.4 to have create functions to autoload your classes from files based on how you want via creating that magic function or in the latter case registering a autoload function.

Hope this will help someone along the way.

share|improve this answer

Makes perfect sense.

Well, far as I can see it should work: I use similar directives all the time. I'd check all the directory permissions and ownership, and the file permissions, and if those are all right, I'd check for a rogue .htaccess file or some other piece of lock-downery that may be tripping you up.

If Apache's document root is /var/www/html, then you shouldn't have any trouble pointing at something in /var/www/html/includes/ unless there is some specific directive (or permission issue) blocking it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.