I am trying execute python script from php, on my local server it works fine. But after hosting on web i am getting error like this:
"Warning: shell_exec() has been disabled for security reasons in/home/a1608290/public_html/searc2.php on line 58"
Is there a way to execute python script in php web server???
link to my website:http://wikiquery.comuf.com/index.php
in php this how i am running my python script:
$tmp =`/usr/bin/python2.7 wiki.py .$var`;
or
$tmp = exec("python wiki.py .$var");
for both ways i am getting the similar error
Thankz in advance
-
1I don't think 000webhost will allow you to run python scripts on their servers. Their free hosting does not include executing python scripts. If you want to do this you will have to buy a hosting service that allows this.Jerodev– Jerodev2014年10月16日 08:30:49 +00:00Commented Oct 16, 2014 at 8:30
1 Answer 1
Reason
Your PHP configuration doesn't allow the shell_exec() function. This is one of the functions disabled when PHP is run in Safe Mode.
Solution
Generally speaking, I discourage you to disable safe mode for a production environment. You can use ini_set to enable shell_exec in current session, so that you will not expose your server in a danger position.
<?php
$old_settings = explode(',', ini_get('disable_functions'));
$new_settings = implode(',', array_diff($old_settings, ['shell_exec']));
ini_set('disable_functions', $new_settings);
?>
Here is the documentation.