//1.php
<?php
$order = 'python /home/python/1.py';
$data = shell_exec($order);
var_dump($data);
?>
//1.py
#!usr/bin/env python`
import os
f = open('/home/python/1.txt','w')
print('OKOKOK')
f.write('OK')
f.close()
1.以上可以成功调用执行py
//2.php
<?php
$order = 'python /home/python/2.py';
$data = shell_exec($order);
var_dump($data);
?>
//2.py
#!usr/bin/env python`
import requests
import os
r = requests.get('http://ip.taobao.com/service/getIpInfo.php?ip=0.0.0.0')
print(r.text)
f = open('/home/python/2.txt','w')
f.write(r.text)
f.close()
2.以上不能调用执行(文件权限同样都是777)
centos
php环境: PHP7 (未禁用任何高危险的函数)
python默认环境: python 3.6 ( requests模块已经安装 )
Anaconda路径: /root/anaconda3
常用环境是需要执行命令 source activate python36
$PYTHONPATH /root/anaconda3/bin/python3.6
问题已经找到
PHP执行的是 python 2.7
后来重定向python
ln -s /root/anaconda3/bin/python3.6 /usr/bin/python
ln -s /root/anaconda3/bin/python3.6 /usr/bin/python2
n -s /root/anaconda3/bin/python3.6 /usr/bin/python3
结果PHP不能执行py了~~
你是不是没有安装requests模块