简体   繁体   English

如何在php Web服务器中使用python脚本

[英]How to python script in php web server

I am trying execute python script from php, on my local server it works fine. 我正在尝试从php执行python脚本,在我的本地服务器上工作正常。 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??? 有没有一种方法可以在php Web服务器中执行python脚本???

link to my website: http://wikiquery.comuf.com/index.php 链接到我的网站: http : //wikiquery.comuf.com/index.php

in php this how i am running my python script: 在php中,这就是我运行python脚本的方式:

$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 预先感谢

Reason 原因

Your PHP configuration doesn't allow the shell_exec() function. 您的PHP配置不允许shell_exec()函数。 This is one of the functions disabled when PHP is run in Safe Mode. 这是在安全模式下运行PHP时禁用的功能之一。

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. 您可以使用ini_set在当前会话中启用shell_exec ,这样就不会使服务器处于危险位置。

<?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 . 这是文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM