How To Easily Enable The exec() Function In PHP-FPM via SSH

I recently moved some websites to a new VPS server & a handful of them that were built on WordPress & had some image compression plugins enabled started throwing errors stating that exec() needed to be enabled for them to function correctly.

I remember the same happening to me in the past, but couldn’t for the life of me remember how to enable exec() in PHP-FPM which meant I had to do a bit of Googling to find the answer.

Thankfully I did eventually find the answer and in this post, I’m going to share it with you.

How To Enable exec()

1. The first thing you need to do is connect to your server via SSH.

2. Once you’re logged in as the root user via SSH, run the following command to find out your PHP version:

php -v

That command will report back your PHP version, e.g. “PHP 7.4.6”.

3. Once you’ve figured out what PHP version you’re running, you’ll need to open up the configuration file in an editor by using the following command (making sure to change the PHP version & domain accordingly):

vi /opt/cpanel/ea-php74/root/etc/php-fpm.d/domain.tld.conf

The above example would load up the configuration file for PHP 7.4 for the domain “domain.tld”.

4. When the editor opens up the configuration file you’ll then see that exec() is listed as a disabled function, as shown below:

php_admin_value[disable_functions] = exec,passthru,shell_exec,system

As we’re using the VI editor, simply press “i” to switch to insert mode then erase “exec” from the list of disabled functions. Once erased, press the escape key on your keyboard to exit insert mode & finally save the changes by typing “:wq” (without quotes) and hitting return.

5. The exec() function will now be disabled, but in order for the changes to take effect you’ll need to restart PHP-FPM which can be done by using the following command:

/scripts/restartsrv_apache_php_fpm

To check it’s worked simply head back to your site & see if the exec() warnings have disappeared. They should have done. 🙂

Important Note

Apparently, if you decide to disable PHP-FPM for your website & reenable it, it’ll wipe any custom configuration rules that you’ve added which will mean that you’ll need to repeat the above steps again.

Leave a Comment