PHP shell exec not working in HTML browser but working on cmd prompt

✔ Recommended Answer

Check the permissions to run it as a server. You can run this as owner, but there can be no possibilities to run it as other user - in your example as apache.

Method #2

The shell_exec() function in PHP is often disabled by default for security reasons, as it allows execution of arbitrary shell commands on the server. Therefore, it's possible that the function is not enabled on your server when running PHP scripts through the web server.

To enable the shell_exec() function in a PHP script executed through the web server, you need to check the disable_functions setting in the php.ini configuration file. If shell_exec is included in the list, you will need to remove it from the list and restart the web server for the changes to take effect.

However, it's generally not recommended to enable shell_exec() in a web context, as it can be a security risk. Instead, consider using other PHP functions or libraries that provide the necessary functionality in a more secure manner. For example, if you need to execute system commands, consider using the proc_open() function instead.


Most Popular

PhpStorm, return value is expected to be 'A', 'object' returned

Remove Unicode Zero Width Space PHP

Laravel file upload returns forbidden 403, file permission is 700 not 755