mardi 28 juin 2016

PHP exec() not working...Can't find permission error

I am trying to make a simple web application that utilizes MySQL, PHP, and python on my mac. Basically what I am trying to do is run a python script that creates a gzip formatted file from some information in my database (a mysqldump). The script runs fine in the terminal and produces the file correctly, it's just when I run the shell_exec() or exec() it doesn't seem to work. Here is what the code looks so far:

$a = shell_exec("/usr/bin/python test.py 2>&1 &");

when I echo back this execution I get the following error message:

sh: mysqldump: command not found sh: file_2016-06-26-06:32.gz: Permission denied -- file_2016-06-26-06:32.gz

however whenever I echo commands such as "ls", "/usr/bin/python --version", or "pwd", it seems to work. Likewise when I run this command in terminal through php -

  php -r 'echo shell_exec("/usr/bin/python test.py 2>&1 &");'

It runs the script and produces the file fine. I have also tried adding "php-cli" to beginning and removing "2>&1 &" but it just doesn't seem to work to also.

Any ideas here? I would assume it would be a permissions error but all my PHP scripts and python scripts are read and write to everyone.

The python code is:

  import ConfigParser
  import os
  import time
  import getpass

  def get_dump():

user = 'root'
password = 'password'
host = 'localhost'
database = 'dogs'


filestamp = time.strftime('%Y-%m-%d-%I:%M')
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (user,password,host,database,database+"_"+filestamp))

 if __name__=="__main__":
   get_dump()

Aucun commentaire:

Enregistrer un commentaire