I downloaded (mdldec_linux_amd64) and (mdldec_linux_i386)
and placed them somewhere in cPanel / Files Manager / HTML folder
How to call this program from Call.PHP ?
I try something like below
shell_exec ("mdldec_linux_amd64 parameter1 parameter2");
can someone help me on this?
2
Answers
Executing commands from php is not recommended, this might bring security issues. If you don’t have an option here are 2 examples:
You should try to use the full path for the file you want to execute:
Assuming that the file is the /usr/local folder
Also you can use exec and get the last returned line from the executed command. and also the full output
And you might be able to debug better and have more information
Executing a binary from PHP employing shell_exec or analogous functions is clear-cut and your example nearly has it. There are a handful of considerations and requisites that need to be taken into account:
File Permissions: Certify that the PHP process possesses execution rights on the binary. You may need to
chmod +x mdldec_linux_amd64
orchmod +x mdldec_linux_i386
to grant execution permissions.Absolute Path: Utilize the absolute path to the binary within your shell_exec call. PHP might not know where to locate your binary if you don’t inform it explicitly. For instance, instead of
"mdldec_linux_amd64 parameter1 parameter2"
it would be"/full/path/to/mdldec_linux_amd64 parameter1 parameter2"
.Safe Mode: Inspect if PHP is operating in Safe Mode (this is a configuration in php.ini). If it is, then the binary must reside in the directory specified via the
safe_mode_exec_dir
setting.Disabled Functions: Furthermore, ascertain that
shell_exec
function isn’t disabled. Some shared hosts deactivate potentially dangerous functions. You can verify this in the "disable_functions" directive within the php.ini file.Assuming your PHP setup permits you to use
shell_exec
, your PHP code would appear something like this:Replace
/full/path/to/
with the actual path where you uploaded the file, andparameter1 parameter2
with the actual parameters you desire to pass to your program.Employing functions such as
shell_exec
can be perilous, because they allow PHP to execute arbitrary commands on the server. So only utilize them when absolutely necessary, and ensure to validate and sanitize all inputs to prevent potential security hazards.