Cronjob reports "The exec function is disabled" while it's enabled for that user

Phuturist

Verified User
Joined
Dec 30, 2018
Messages
14
Cronjob reports "The exec function is disabled" while it's enabled for that user

I have a VPS with CustomBuild DirectAdmin running several websites using PHP-FPM. I have the secure_php feature turned on but some website do need exec() or shell_exec() permission. For these users I edit /usr/local/directadmin/data/users/solide/php/php-fpm7x.conf and add the php_admin_value[disable_functions] = directive without exec() and shell_exec. Works just fine and I can see it works with phpinfo(). I can also do these edits straight from DirectAdmin under "Custom HTTPD Config" of course.

But I run into an issue where the log from a cronjob script (Magento 2) reports me that it can not fully run because "The exec function is disabled". Well, the exec() function is enabled for the user under which the cronjob is run through the above method. Still it gives me this error. I am already using the "-d disabled_function=" parameter in the cronjob. I have also tried specifically setting the php version under which the cronjob should run. I have tried using a custom php.ini for the cronjob with the exec() and shell_exec() functions excluded from the disable_functions directive. All has been to no avail. The script keeps reporting "The exec function is disabled" and I dont know where to look anymore after spending hours on this already.

Setting cronjob to use /usr/local/php72/bin/php and editing /usr/local/php72/lib/php.ini and removing exec() from disable_functions results in the script running succesfully. But of course I do not want to (partially) disable the secure_php option serverwide again as it serves a purpose. By the way, setting the cronjob to use /usr/local/php72/sbin/php-fpm72 does not work, the script does not run. Not sure why that is.

So the question is, how can I get this cronjob to run for specific users using Magento 2 without running into the "The exec function is disabled" error?
 
Last edited:

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,818
Location
GMT +7.00
Hello,

There are two possible solutions:

1. Use different php.ini for CLI and FPM processes: where disable_functions will be enabled for FPM processes
2. Run the cronjob task without loading php.ini or use a separate php.ini for it.
 

Phuturist

Verified User
Joined
Dec 30, 2018
Messages
14
Hello,

There are two possible solutions:

1. Use different php.ini for CLI and FPM processes: where disable_functions will be enabled for FPM processes
2. Run the cronjob task without loading php.ini or use a separate php.ini for it.
Thanx for the quick response. Not sure why but I tried it again with the -c parameter in the cronjob task and set a seperate php.ini for the cronjobs and the error does not return. I'm pretty sure I had already tried that and it did not work before. Not sure what changed but this is resolved now.
 
Top