How to Enable exec() in PHP-FPM on cPanel / WHM

November 30, 2022 / Web Development

On cPanel servers, PHP-FPM is commonly used to improve PHP performance. However, in some cases, PHP functions such as exec() may not work when PHP-FPM is enabled. This usually happens because the function is listed under disabled functions in the PHP configuration, not because PHP-FPM itself blocks it.

This guide explains how to enable the exec() function in PHP-FPM on a cPanel/WHM server.

Note: Enabling exec() can pose security risks. It should only be enabled if your application explicitly requires it and the server is properly secured.

Steps to allow exec() in PHP-FPM:

  1. To begin, make sure PHP-FPM is enabled on the domain that is experiencing the issue. Follow the steps below:
    1. Log in to WHM.
    2. You can check if your domain uses PHP-FPM by navigating to MultiPHP Manager.
    3. You can verify whether PHP-FPM is being used by the domain on that page.
  2. Your server now has PHP-FPM installed. To enable exec() in PHP-FPM, follow the steps below:
    1.  Connect via SSH to the server.
    2. Use the following command to check the PHP version of the server.
      #php -v
    3. Open the PHP-FPM configuration file.
      # vi /opt/cpanel/ea-php70/root/etc/php-fpm.d/blah.domain.tld.conf
    4. You will find the exec() function in the disabled function list.
      php_admin_value[disable_functions] = passthru,shell_exec,system
    5. Remove “exec” from the upper line.
    6. Use the following command to restart PHP-FPM.
      # /scripts/restartsrv_apache_php_fpm

On cPanel/WHM servers, exec() may not work under PHP-FPM if it is disabled in the PHP-FPM configuration. Updating the domain-specific PHP-FPM configuration file and restarting the service successfully enables the function.

If you need further assistance, don’t hesitate to get in touch with our support team.

Spread the love