Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing python script from a PHP site -- do I need Django? Can it be done on a raspberry pi? [closed]

I'm working on a program that utilizes Python scripts that pull information from a MySQL database. The MySQL database is managed from a PHP site interface (so HTML forms and buttons and the such). I have this all set up on a raspberry pi and it works. But I want to add some more functionality.

Specifically I want to be able to execute certain python scripts from the PHP site. I want it to be as simple as a press of a button, literally.

Is this a scenario where I should use Django? I've never used it before but have read about how it connects Python with the web. I found an answer to a similar question but I'm wondering If I need to set up anything special on my apache server: https://stackoverflow.com/a/31811462/5609876

I even made a little picture for a visual representation of my program incase my explanation wasn't good enough:

enter image description here

like image 700
E.Arrowood Avatar asked May 31 '26 07:05

E.Arrowood


1 Answers

No, you do not need django at all.

If all you want to do is execute a Python script from PHP - assuming you have already written the script and stored it somewhere:

First, assign execute permissions on the Python script to the user that is running the PHP code. Normally, this is the same user that is running Apache. Usually this is called www-data or apache or something similar. The user will be listed in the Apache configuration file.

Then, on your PHP side, all you really need is exec:

<?php

    exec('/path/to/python /path/to/your/script.py')

?>
like image 97
Burhan Khalid Avatar answered Jun 01 '26 20:06

Burhan Khalid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!