User Level PHP Handling Customization

Started by Sudhakar, Jun 23, 2009, 01:27 AM

Previous topic - Next topic

Sudhakar

When PHP 4 and PHP5 are both enabled and served using the CGI, DSO, or SUPHP configurations, the Cpanel interface will contain a selector for setting the version of PHP that will act as the default for the account. The version of PHP selected will process .php files for all domains assigned to the account.

The interface is available on the X3 theme under Software/Services -> PHP Configuration. Available settings are PHP4, PHP5, and System Default. The chosen value is reflected in the .htaccess file in the user's home directory. If the user requires that file extensions other than .php are processed by the selected version of PHP, add those file extensions after .php to the AddHandler line in the .htaccess file.

The administrator has a command line tool available for managing these settings called update_php_mime_types. It is located in the /usr/local/cpanel/bin/ directory. Run the following command for detailed information on 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 EasyApache 3 installation process. It will update or remove PHP AddHandler directives in .htaccess files down to three levels deep within users home directories. To prevent this update from occurring, create a file named "/var/cpanel/easy_skip_update_php_mime_types".
NAME

update_php_mime_types – Update user level PHP-MIME mappings

-help
Brief help message
-man
Full documentation
-recurse=#
Recurse depth for finding .htaccess files
-strip
Remove all PHP AddHandler directives
-user=
Only check the specified user
-force=<4|5>
Force the PHP version to the one specified
-directory=


Force the PHP version in this directory
-verbose
Display actions as they are performed

Sudhakar

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.

Options

–help
Display a brief help message and exit.
–man
Display the manual page and exit.
–recurse
Depth to recurse inside home directories. The default recurse depth is 2, meaning that subdirectories within public_html will be checked.

Valid range is 0 to 100.
–strip
Remove any PHP AddHandler directives that are found rather than updating them.
–user
Only check the .htaccess files of the specified user.
–force
Set the main .htaccess file for the user to the specified PHP version. No changes will be made to .htaccess files in sub-directories. The –user flag must be specified in conjunction with this one.

To reverse this operation without changing any of the PHP MIME mapping in subdirectories, use –user= –strip –recurse=0
–directory
Used in conjunction with –force and –user.

Sudhakar

Set the PHP MIME type in the specified directory instead of globally for the user. See CAVEATS for information on maintenance problems this may create.
–verbose
Display information about each action performed during the execution of this script.

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 their specified preferences to the correct current MIME types.

This program will NOT update any .htaccess files that are symlinks. It will also comment out any PHP AddHandler lines that are not immediately proceeded by the marker comment:

# Use PHP# as default

The mime type used is based on this comment.

This program may also use this program to set the global PHP mime map- ping 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 setup a single deeply nested directory to parse .php files with a particular version of PHP, the preferred method is to sym- link /usr/local/apache/conf/php#.htaccess to .htaccess in that directory. This will ensure that the MIME type will always be correct one when it is possible to select between PHP4 and PHP5. If using a sym- link for the .htaccess file is not possible, use the marker comment specified above and run this program with a suitable -recurse argument each time you change the PHP configuration in the WebHostManager or via rebuild_phpconf.