User-Level PHP Handling Customization

When PHP 4 and PHP 5 are both enabled and served using the CGI, DSO, or suPHP configurations, cPanel lets the user select the default PHP version that processes .php files for all domains assigned to that account.

This interface is available in cPanel’s X3 theme under Software/Services >> PHP Configuration. Available settings are PHP 4, PHP 5, and System Default.

The chosen value is reflected in the .htaccess file in the user’s home directory. If a user requires file extensions other than .php to be processed by the selected version of PHP, add those file extensions after .php to the AddHandler line in the .htaccess file.

The update_php_mime_types Script

There is a command line tool for managing these settings called update_php_mime_types, located in the /usr/local/cpanel/bin/ directory. Run the following command for detailed information about how this tool works:

  • /usr/local/cpanel/bin/update_php_mime_types --man


The update_php_mime_types script is run automatically as part of the EasyApache3.EasyApache installation process. It will update or remove PHP AddHandler directives in .htaccess files down to, by default, 3 levels deep within users’ home directories.

note Note: You can configure the depth for update_php_mime_types from the Tweak Settings page.

To prevent this update from occurring, create a file named:

  • /var/cpanel/easy_skip_update_php_mime_types

Command line options

  • --help -- Displays a brief help message
  • --man -- Full documentation
  • --recurse=# -- Depth to recurse inside home directories. The default recurse depth is 2, meaning that subdirectories within public_html will be checked. This option can accept values between 0 and 100.
  • --strip -- Remove all PHP AddHandler directives
  • --user=<user> -- Only check the .htaccess files of the specified user.
  • --force=<4or5> -- Set the main .htaccess file for the user to the specified PHP version. No changes will be made to .htaccess files in subdirectories. The --user flag must be specified in conjunction with this one.
    • note Note: To reverse this operation without changing any of the PHP MIME mapping in subdirectories, use --user= --strip --recurse=0
  • --directory=<dir> -- Set the PHP MIME type in the specified directory, instead of globally for the user. This option must be used in conjunction with --force and --user.
    • note Note: See the Caveats section below for information on maintenance problems this may create.
  • --verbose -- Display information about each action performed during the execution of this script.

Examples

  • update_php_mime_types --verbose
    • Update all user .htaccess files that already contain PHP MIME mappings.
  • update_php_mime_types --user=fred --force=4 --verbose
    • Set Fred's main .htaccess file to use PHP 4 by default.
  • update_php_mime_types --user=fred --strip --verbose
    • Remove all PHP AddHandler lines and marker comments from Fred's .htaccess files.

Description

This program will read the contents of /usr/local/apache/conf/php4.htaccess and /usr/local/apache/conf/php5.htaccess to determine the current MIME type mappings for PHP 4 and 5. It will then go through each account's home directory, updating the specified preferences to the correct current MIME types.

This program will NOT update any .htaccess files that are symlinks.

It will comment out any PHP AddHandler lines that are not immediately preceded by the marker comment:

  • # Use PHP# as default

The MIME type used is based on this comment.

You may also use this program to set the global PHP MIME mapping for an account by specifying the --user and --force flags together. This will not change any PHP MIME types in subdirectories, only the .htaccess file in the user's home directory.

Caveats

  • If you need to set up a single deeply nested directory to parse .php files with a particular version of PHP, the preferred method is to symlink /usr/local/apache/conf/php#.htaccess to the .htaccess file in that directory.
    • This will ensure that the MIME type will always be the correct one, when it is possible to select between PHP 4 and PHP 5.
  • If using a symlink for the .htaccess file is impossible, use the marker comment specified above, and run this script with a suitable --recurse argument each time you change the PHP configuration in WHM or via rebuild_phpconf.
Topic revision: r2 - 08 Jun 2009 - 15:32:07 - Main.JustinSchaefer
EasyApache3.UserLevelPHPCustomization moved from Sandbox.UserLevelPHPCustomization on 08 Jun 2009 - 14:45 by Main.JustinSchaefer - put it back
 

Copyright © cPanel 2000-2009.