f_y
f_y

Reputation: 73

shell_exec can not enable on apache server

i want to run a python script from php code using exec or shell_exec. this is php code :

<?php
exec('/usr/bin/python  /var/www/html/test.py');
?>

also this is the python script i want to execute it from browser, name test.py :

#!/usr/bin/env python
import os

f= open("/var/www/html/result","w")
f.write("ok")

script runs from command line correctly, but when i execut it from browser , it dose not work. I searched a lot of things and i did following items to solve the problem :

  1. I add 'www-data ALL=(ALL) NOPASSWD: ALL' and 'apache ALL=(ALL) NOPASSWD: ALL' in /etc/sudoers file.
  2. I give 777 permission to /var/www/html directory
  3. I run 'chown -R www-data:www-data /var/www/html'
  4. Remove all functions in front of 'disable_functions' in /etc/php/7.0/fpm/php.ini and /etc/php/7.0/cli/php.ini files
  5. home.php and test.py are in a same directory in /var/www/html
  6. I login with www-data in commandline and executed test.py and it worked correctly

But still the script dose not work when i visit http://server_ip_address/home.php . I'm new in php and apache. can anybody help me to solve the problem. great thanks

Upvotes: 0

Views: 494

Answers (1)

7011145 Xxx
7011145 Xxx

Reputation: 11

Can you try

<?php
exec('/usr/bin/python3 /var/www/html/test.py');
?>

and

#!/usr/bin/env python3
import os

f= open("/var/www/html/result","w")
f.write("ok")

Upvotes: 1

Related Questions