I have a Python file, which is an automation script from GitHub. I want that script to be executed by a PHP page.
For example, I have an index.php page, and it has a button saying Start script. Upon clicking the button, a Python script, instabot.py, should be executed. Is this possible in cPanel? My web host is Hostgator.
-
you can use ftp to copy your .py file to your host.joel goldstick– joel goldstick2016年07月06日 12:52:45 +00:00Commented Jul 6, 2016 at 12:52
1 Answer 1
Using information from another StackOverflow post, you might wanna use exec() to run a Python script from PHP. Like:
exec('python /path/to/file/instabot.py');
According to Hostgator's documentation, Python scripts should have permissions set at 755.
Uploading your Python scripts will be the same as uploading any file to a web host, through the use of FTP or cPanel itself.
2 Comments
exec(), use shell_exec(). So to print the output, do, $output = shell_exec(...); echo $output;.