How can I set php’s include_path

Question:

How can I set php’s include_path?

Answer:

Quck fix for any version

With any version of php you can add this to the top of your script:

ini_set ( “include_path”,”.:/home/your_username/www/:/home/your_username/www/dir/subdir/” );

This is a good fix if for some reason you cannot get other methods to work.

In general though, you should use one of the next two methods:

When using cgi-based php
If you are using one of the cgi-versions of php, you can set this by editing

/home/your_username/etc/php.ini

If this is your first time editing php.ini you may need to create the etc/ dir and upload a default php.ini

When using mod_php php

If you are using the mod_php version, you can set this in a .htaccess file with :

php_value include_path ".:/home/your_username/www/:/home/your_username/www/dir/subdir/"

Still having problems?

If you get a 500 error, then there is a syntax error in your .htaccess file.

If the pages loads but you do not get the intended result, make a page with just:


< ? phpinfo(); ?>

in it. When you load this page it will show you all the php vars for the page. Make sure the path is set how you wanted it. If it is but your scripts still do not work you’ll need to adjust them or your scripts until you get what you want. It can be hard to get the right path since your scripts may be operating differently from what you expect.

Keep in mind:

Your base dir on the filesystem is always:

/home/your_username/

Your web base dir is (unless you’ve customized your base dir):

/home/your_username/www/

Leave a Reply

Your email address will not be published. Required fields are marked *