Skip to content

Setting the PHP Include Path

The PHP include path tells PHP where to look for files when using functions like include() and require(). By configuring the include path, you can centralize commonly used code and ensure PHP can locate libraries such as PEAR. On ruachost.com, you can set the include path in several ways.

  • Centralize reusable code (e.g., libraries, configuration files).
  • Ensure PHP can locate external packages like PEAR.
  • Improve maintainability by avoiding long relative paths.
  • Enhance security by keeping sensitive files outside public_html.
  1. Log in to cPanel.

  2. Go to Software → Select PHP Version.

  3. Click the Options tab.

  4. Locate the include_path option.

  5. Enter your desired path (separate multiple directories with a colon :). Example:

    .:/home/username/include
  6. Changes take effect immediately.

  1. Create or edit a php.ini file in your account.

  2. Add the following line (replace username and include_directory):

    include_path = ".:/home/username/include_directory"
  3. Save the file.

  4. PHP will now use this include path for scripts in that directory.

Method 3: Use the set_include_path() Function

Section titled “Method 3: Use the set_include_path() Function”

Set the include path directly in a PHP script:

<?php
set_include_path(".:/usr/lib/php:/usr/local/lib/php:/home/username/php");
?>
  • Effective only for the duration of the script’s execution.
  • Does not affect other scripts.

If PHP runs as an Apache module, you can set the include path in .htaccess:

php_value include_path ".:/path/to/include"
  • Place this in your site’s root .htaccess file.
  • Effective for all scripts in that directory.