Looking at how to enable exec function in php.ini?
Exec is a PHP function used to execute an external program like a script.
But the execution of external programs creates a security risk that attackers can misuse.
At Bobcares, we often get requests to enable PHP functions, as part of our Server Management Services.
Today, let’s see how our Support Engineers enable this function. We’ll also discuss the security risk related to the exec function.
What is the exec function?
The exec is an inbuilt PHP function. It replaces a currently running process with the new program. PHP uses the function to execute a program and it returns the last line of the output.
Many WordPress image optimization plugins make use of this function. Hence WordPress users often approach us to enable this function.
Security risk in enabling exec function
PHP has certain dangerous functions that can make a server vulnerable to attacks. These functions include system, passthru, shell_exec, exec, etc.
Hence our Support Engineers always recommend our customers to disable these functions in the server. And these functions will be listed in the disable_functions directive in a php.ini file.
By enabling exec function there is a possible security threat. Attacks may use this function to run programs in servers that can lead to data corruption and data loss.
Considering the security risks, we suggest customers enabling the exec function on a per-account basis. Thus, it gives better tracking of user activity.
How we enable exec function in PHP?
One of the wisest choices is to enable the exec function in dedicated or VPS servers.
Usually, we enable this function via the php.ini file. But for cPanel accounts, we can do this via WHM. Now, let’s see how our Support Engineers enable it.
Using php.ini to enable exec function
To enable this function, we login to the server as the root user.
Then we open the php.ini file and search for exec function. Usually, this function will be disabled. So, we check the disable_functions directive which appears as,
disable_functions = "show_source, system, shell_exec, exec"
Hence we remove exec from the line and save the file. Thus we enabled the exec function in the server.
In addition, if the PHP handler is suPHP or LSPHP, then we have to add the directive in the .htaccess file also.
MultiPHP INI Editor
For cPanel customers we enable the exec function from the WHM. But the change will reflect in all cPanel accounts in WHM. So we don’t use this method to enable exec in one cPanel account.
- To enable the function in all the accounts, we log in to the WHM.
- Then we select the MultiPHP INI Editor from the Software section.
- Next, we enter into the Editor Mode and choose the corresponding PHP version.
- There we remove the exec function from disable_functions directive.
- Finally, we save the changes.
Hence it enables the function server-wide.
[Need more help to enable PHP functions? – We’re available 24/7.]
Conclusion
In short, exec function is usually disabled in a server, as it allows attackers to execute external programs that can crack a server. Today, we saw how our Support Engineers enable exec function in php.ini.
hello, is there any other ways to enable this function without touching php.ini ? i dont have access to php.ini in my host.
Hello Erfan,
Enabling the exec function needs access to the php.ini file. Considering security risks, most Hosting providers control this function at the root access level.
A VPS server with root access allows you to do such customization.