9

I want to set the PHP include path to another directory. I tried putting this in an .htaccess file, but that didn't work. The only thing I see is the include path's I set in httpd.conf, but not the one I tried to add.

<IfModule mod_php5.c>
php_value include_path ".:/var/www/mywebsite/"
</IfModule>

What am I doing wrong? I did a2enmod mod_php5, but it was already running, so I suppose PHP5 is already running as Apache module.

[EDIT] In my vhost config I have this:

<Directory ~ "^/var/www/.*">
        AllowOverride All
        Options FollowSymLinks -Indexes -MultiViews
        php_value include_path ".:./include:./.include/:/var/www/.include/:/var/www/"
</Directory>

More info (phpinfo()):

Loaded Modules  core mod_log_config mod_logio prefork http_core mod_so mod_alias mod_auth_basic mod_auth_mysql mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_deflate mod_dir mod_env mod_mime mod_negotiation mod_php5 mod_reqtimeout mod_rewrite mod_setenvif mod_status

include_path    .:./include:./.include/:/var/www/.include/:/var/www/    .:/usr/share/php:/usr/share/pear

Regards, Kevin

10
  • If you're using it as a php module it should work. Double check you have to the mod_php5.c module installed and double check the path. phpinfo() is your friend. Commented Jun 28, 2011 at 14:57
  • Thanks, I'll post my phpinfo() soon ;). Commented Jun 28, 2011 at 15:05
  • Slightly offtopic, but if you have common config file, you can use set_include_path() to modify include_path at runtime. Commented Jun 28, 2011 at 15:06
  • Yeah, I'll take that option in consideration. But I first want to be sure wether it is possible. I still prefer one single .htaccess line ;). Commented Jun 28, 2011 at 15:08
  • Does your .htaccess reside in document root? Commented Jun 28, 2011 at 15:10

3 Answers 3

7

Apache must be configured to allow settings to be overridden via .htaccess. Check your Apache config file (httpd.conf) for an override for your directory:

<Directory "/directory/containing/your/htaccess/file">
    AllowOverride All
</Directory>

Place this within the vhost definition for your site.

If this is a global change, you should change the include_path setting in your php.ini file instead of using .htaccess.

Both of these changes will require an Apache restart.

EDIT:

This is a quote from the Apache Core features page:

"Suppose that the filename being accessed is /home/abc/public_html/abc/index.html. The server considers each of /, /home, /home/abc, /home/abc/public_html, and /home/abc/public_html/abc in that order. In Apache 1.2, when /home/abc is considered, the regular expression will match and be applied. In Apache 1.3 the regular expression isn't considered at all at that point in the tree. It won't be considered until after all normal s and .htaccess files have been applied. Then the regular expression will match on /home/abc/public_html/abc and be applied."

I think, based on this information, that your php_value include_path statement is being evaluated after the .htaccess file. If that is the case, the value you use for include_path in the .htaccess is being overwritten. Can you try removing the include_path line from <Directory> temporarily to test this theory?

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I do have AllowOverride, but that doesn't work. Or is the capital the problem? (See edit) No, it's not global.
Kudo's for you, it kind of works =D! But, how can I use my 'overall' include directories? In php.ini I guess?
@Kevin: There are at least two possibilities: 1. Don't use a regex in your <Directory> directive, or 2. Include the full path in your .htaccess files.
1

have you tried this in your PHP code (on the top of your code):

<?php
$path = "../folder/folder/file_name.inc.php";
require_once($path);
?>

1 Comment

For large sites this can become almost impossibly unmanageable!
0

You can try to use chdir() in your php file to use another location as base location for all file functions, including includes =)

3 Comments

Thnx ;), but it would be too much work, and it's not so generic; if I rename this folder, I must change all the PHP files pointing to this folder.
it's not so much work if you use one base bootstrap script =)
Yeah :), but I still prefer one single .htaccess line :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.