问题描述
我使用Amazon EC2的obunto微实例。我已经写了执行蟒蛇code和呼应的结果,是一个简单的字符串一个PHP code。当我执行它obuntu终端它显示的结果完美,但是当我通过浏览器访问它不显示任何东西。我不知道为什么。其实这不能执行python脚本。
I am using Amazon ec2 obunto micro instance. I have wrote a php code which executes a python code and echo the result which is a simple string. When I execute it on obuntu terminal it shows the result perfectly, but when I access it through the browser it doesn't show anything.And I have no idea why. Actually it cannot execute the python script.
$ TMP = EXEC('的/ usr / bin中/ Python的/var/www/similarity.py员工/失业/服务员');
$tmp = exec('/usr/bin/python /var/www/similarity.py employee/unemployed/ waiter');
如果anyonw能帮助我,我真的很AP preciate它。PS:我使用的是Mac亲书,当我用同样的codeS在我的电脑上的一切localhost的完美的作品
If anyonw can help me I would really appreciate it.PS: I am using a mac book pro and when I use the same codes in the localhost of my computer everything works perfectly
推荐答案
这是权限问题,访问Python文件。当你运行它通过服务器python脚本访问作为apache用户(最可能是WWW的数据)。因此Apache用户不具有权限才能执行的Python文件。
This is permission problem to access python file. When you running it through server python script access as apache user(most probably www-data). So apache user doesn't having privilege to execute the python file.
您可以做的是运行这个命令sudo的,并添加所有必要的访问Apache用户(WWW的数据)在/ etc / sudoers文件,如下示例。
What you can do it is run this command as sudo and add all necessary access to apache user(www-data) in /etc/sudoers file as below sample.
www-data ALL=NOPASSWD:/var/www/similarity.py
www-data ALL=NOPASSWD:/usr/bin/python
这仅仅是样品,你应该改变这一行根据您的环境。
This is just the sample, you should change this line as according to your environment.
这篇关于PHP和Python在Amazon EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!