Executing python script from php

Hi everyone,

I am new to PHP and I am currently doing a project using a raspberry pi. A camera module is connected to the raspberry pi and I have a Python script to take a picture when the script is being run. I also have a PHP page where I will display the picture taken. I would like to make the PHP page be able to run the script when someone visits the PHP page. Is it possible to do so?

Google is your friend.

Tested on Ubuntu Server 10.04. I hope it helps you also on Archlinux.

In PHP:

<?php $command = escapeshellcmd('/usr/custom/test.py'); $output = shell_exec($command); echo $output; ?>

In Python file ‘test.py’ verify this text in first line: (see here the reason):

#!/usr/bin/env python
Also Python file should have correct privileges (execution for user www-data / apache if Php script runs in browser or through curl)

chmod +x myscript.py


Sponsor our Newsletter | Privacy Policy | Terms of Service