3π
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')
?>
1π
If the shell_exec
function is allowed on your server, you can use that to run your Python script through Bash. shell_exec
returns the output of the bash call. The only thing you have to make sure of is that shell_exec
isnβt disabled in your serverβs php.ini file (look for the line disable_functions shell_exec
).
If your python script is called mypythonscript.py
and is in the same directory as the PHP file, you can run it like this:
<? shell_exec('python mypythonscript.py'); ?>
- [Django]-Django Rest framework authtoken 'module' object has no attribute 'views'
- [Django]-Best practice β Django multisite
- [Django]-Django caching for web applications
- [Django]-Editing models and extending database structure in Saleor