0

I have a PHP script that should run a Python script, what i try. Nothing seems to work. I gived the script and the PHP script full permission (777). The way that i use to execute my Python script in php is:

    <?php 


    shell_exec('python /var/www/html/send.py');
    system('python /var/www/html/send.py');

    ?>

I tried a couple of methodes that are in the code above, but nothing seems to solve the issue. The strange thing is that the command is working fine when i execute it in Putty. So i don't know what could be the problem. The permissions must be right.

I found a few ways on Stack Overflow, but nothing has the same issue as me. This is the code that should be executed:

#!/usr/bin/env python

import sys                              #import sys
import serial                           #import Serial
import time

ser = serial.Serial ("/dev/ttyS0")      #Open onze poort
ser.baudrate = 9600                     #Baudrate instellen

adres = 2
data = 1

print adres                             #Debug Info
print data                              #Debug Info

byte = chr(int(adres))                  # Omzetten adres naar Byte
ser.write(byte)                         # Uitsturen van adres over Serieeel
time.sleep(0.5)                         # Wachten (Atmel kan sloom zijn)
byte2 = chr(int(data))                  # Omzetten data naar Byte
ser.write(byte2)                        # Uitsturen van data over Serieeel

ser.close()                             # Seriele poort sluiten
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

Be sure that you have enabled exec in php.ini and just put into php code this

<?php 
exec('python /var/www/html/send.py');

I think, you should run python from php's tree. For example:

php script
/var/www/run.php

python script:
/var/www/python/send.py

after that everything should be ok

Filip
  • 143
  • 12