Back to Writing

Set PHP Include path via .htaccess file

How to set the PHP include path per-site using an .htaccess file, keeping multiple websites on one Apache environment from referencing each other’s files.

Eli Geske 3 min read
htaccess include_path php_include
PHP logo

When working with many websites on one development environment using Apache you may run into the issue where one website references a different website’s files. This usually happens if you have a PHP include path set in your ini file for one site and not the other. A quick way to keep this from happening is using an .htaccess file to set your PHP include path for each site. (Personally I think this is just an easier way to maintain them.)

Either create an .htaccess file or edit an existing one in the website root. Please note that for my development environment I use vhosts in my Apache config settings so I can call my sites directly by a URL and NOT using localhost. Therefore I can set an individual include path in each site’s directory.

Here is what you need to add to the htaccess file:

Windows:

php_value include_path "C:/yourpath/mywebsite"

Linux:

php_value include_path "/yourpath/mywebsite"

Legacy Archive

This post originally appeared on eligeske.com in 2012 and has been recovered from the archives.

Legacy Comments Archive

This post originally appeared on my old site and has been recovered from the archives. Below are the original comments from the community.

V
Vanessa
December 3, 2012

I am very interested in learning how to do this. My particular reason is that I read an article on creating a private web page, and it sounds like I need to start by creating an .htaccess file, which I do not know how to do.

That article says this will only work on Linux, but I don’t mind using either Linux or Windows, since I have them both on my computer. Whatever is easier (and/or more effective) in your opinion is what I will use.

Is Apache the software I need to download in order to create an .htaccess file?

e
eligeske Author
December 3, 2012

Apache is actually the web server. Linux would be the operating system installed (similar to Windows). Apache would be similar to IIS on Windows.

As long as where you are hosting your website is Linux, 99% of the time they use Apache. With that being said, you can use an .htaccess file by putting it in your root directory of your website.