If you want to run the command through the file url, example http://exemplo.com/teste.php and in this test.php has its shell_exec, you need to make sure that the Apache have permission to execute this command.
To give permission to Apache just know the user, it will depend on the Linux distribution you are using. If you are using Hundreds will be Apache even if you are using Ubuntu will be www-data.
After knowing this check which file path is where the files you want to execute the permission sudo by the Apache, then you edit the sudoers
vim /etc/sudoers
and add the following line.
apache ALL=(root) NOPASSWD: /caminho/da/sua/pasta
or
www-data ALL=(root) NOPASSWD: /caminho/da/sua/pasta
Basically you will be telling the server that your Apache is allowed to run the files from this folder as root.
Without you putting what appears in the error log, it is difficult to know. It would be nice [Edit] and add this relevant information.
– Bacco
Some commands are disabled by default. If you update the question using the real command, not an example, it will be easier to get help.
– Jonathan Lamim Antunes