I can't do shell_exec using PHP

#1
Hello,

I'm new here. I've just created a new Wordpress OpenLiteSpeed Droplet on DigitalOcean. When I use PHP to call a python script using shell_exec it doesn't show anything. I've checked the php.ini file and looked for disable_function but there isn't shell_exec there.

Please let me know how to solve it.

Many thanks,
Anh Pham
 

Pong

Administrator
#2
why your PHP needs to call Python? Your OLS may not configure to run Python script yet.
suggest you just use PHP to call the shell command to run directly within PHP code.
 
#3
Yes I tried to use PHP to call the shell command using shell_exec but it doesn't show anything. I tried shell_exec('echo "hello world"') to test if shell_exec is enable but it isn't.
 

Cold-Egg

Administrator
#4
Hi,

`cat test.php`
Code:
<?php
    $command = escapeshellcmd('python3 /opt/test.py');
    $output = shell_exec($command);
    echo $output;
?>
`cat /opt/test.py`
Code:
print("Hello World")

`php test.php`
Code:
Hello World
It seems working fine from my test. Please confirm if this is a valid testing to you.

Best,
Eric
 
Top