How to Set Allowed PHP File Extensions Globally

While .php is the most common extension for modern PHP websites, in some cases, websites may be coded to use non-standard extensions such as .phtml or .php3.

Setting these options globally can only be completed by a server administrator.

Information on how to set allowed PHP file extensions for a single domain via SiteWorx can be found here.

Warning

Setting these options globally is not recommended, as it could lead to lower overall security on the server. Best practices would dictate that System Administrators only allow additional PHP file extensions when absolutely required by a domain. Please proceed with caution.

To Set Allowed PHP File Extensions Globally

  1. Log in to the server at the CLI as root, either via SSH or from the terminal

  2. At the CLI, use the following command to set the FPM_LIMIT_EXTENSIONS configuration, replacing each {.ext} with a desired file extension, separated by spaces. Make sure the period is included:

    ~iworx/bin/config.pex --set --name FPM_LIMIT_EXTENSIONS --global --value "{.ext} {.ext} {.ext}"
    

    Example, using .php .phar .html:

    ~iworx/bin/config.pex --set --name FPM_LIMIT_EXTENSIONS --global --value ".php .phar .html"
    

    The current configuration can be seen with the following command:

    ~iworx/bin/config.pex --get --name FPM_LIMIT_EXTENSIONS --global
    

    Example:

    [root@interworx ~]# ~iworx/bin/config.pex --get --name FPM_LIMIT_EXTENSIONS --global
    .phar .php .html
    [root@interworx ~]#
    
  3. At the CLI, use the following command to set the HTTPD_PHP_FILES_MATCH configuration, replacing each {ext} with a desired file extension. Each extension should be separated by a | character. Periods should not be included:

    ~iworx/bin/config.pex --set --name HTTPD_PHP_FILES_MATCH --global --value "{ext}|{ext}|{ext}"
    

    Example, using php|phar|html:

    ~iworx/bin/config.pex --set --name HTTPD_PHP_FILES_MATCH --global --value "php|phar|html"
    

    The current configuration can be seen with the following command:

    ~iworx/bin/config.pex --get --name HTTPD_PHP_FILES_MATCH --global
    

    Example:

    [root@interworx ~]# ~iworx/bin/config.pex --get --name HTTPD_PHP_FILES_MATCH --global
    php|phar|html
    [root@interworx ~]#
    
  4. At the CLI, use the following command to set the HTTPD_PHP_EXTENSION_LIST configuration, replacing each {.ext} with a desired file extension, separated by spaces. Make sure the period is included:

    ~iworx/bin/config.pex --set --name HTTPD_PHP_EXTENSION_LIST --global --value "{.ext} {.ext} {.ext}"
    

    Example, using .phar .php .html:

    ~iworx/bin/config.pex --set --name HTTPD_PHP_EXTENSION_LIST --global --value ".phar .php .html"
    

    The current configuration can be seen with the following command:

    ~iworx/bin/config.pex --get --name HTTPD_PHP_EXTENSION_LIST --global
    

    Example:

    [root@interworx ~]# ~iworx/bin/config.pex --get --name HTTPD_PHP_EXTENSION_LIST --global
    .phar .php .html
    [root@interworx ~]#
    
  5. At the CLI, use the following commands to rewrite all vhosts and php-fpm pools:

    ~iworx/bin/httpd.pex --write-vhosts-all
    ~iworx/bin/php-fpm.pex --write-files --restart-fpm