PHP can't run python file. NO Module Error - php

I'm trying to run a python script through my PHP page. when the script runs the output states that my modules does not exist. I am using exec("python3 sciprtname.py arg1 arg2") I have installed these modules using pip3. when I write the same command in terminal it runs properly.
ModuleNotFoundError: No module named 'pdfkit
I have tried several approaches but none succeeded:
tried escapeshellcmd() shell_exec()
#!/usr/bin/env python
chmod +x myscript.py
Any Help would be appreciated. Thanks in advance.

You need to check if pdfkit is already installed or not. To install it with pip3
pip3 install pdfkit

Related

Run Bash command from PHP 7.0

I've been trying to run the php script:
shell_exec("bash /etc/example.sh")
from the browser but it does not work. This bash file creates a new one on the /etc directory.
I've also tried the functions exec() && system() but they don't work either. The weird thing happens when I run other Linux commands on these php function like:
shell_exec(rm -r /etc/fake);
they work fine, I have also tested my bash file on the linux command line and it works great.
I am sure this is not a permission issue, since I previously set the 777 permission on the file i am trying to execute.
shell_exec("bash /etc/example.sh")
I am using php7.0.33 and Debian 9, so I suppose this may be an issue with this PHP version 7.0.
Thank you for the help.

How to exec a command installed with `npm` command in PHP using `exec()`?

In PHP running on Ubuntu, I can run exec('npm -v') and the output is good,
but I can't run exec('gitbook xxxx').
gitbook is a npm package I installed by
npm install gitbook -g
I can run gitbook xxxx in the Ubuntu terminal, how can I run it from my PHP code?
If you run php by nginx or apache (for example, visit url example.com/index.php), sometime you need to export the PATH
exec("export PATH=/usr/local/bin && gitbook build);
after I added export PATH, everything works fine.
I tried once like this on UNIX-based OS:
You can run shell commands via the exec() function:
// make an php file to execute shell script
exec("node yourscript.js &", $output);
Well output here become array of each line of output along with process id. You can kill process by processid also.
exec("kill " . $processid);
This how I was did. Other then this you can use node supervisor. Hope it will help you. Try your also with node command.

How I can execute python virtual environment files with php shell execute?

I have tried to run the Github: https://github.com/atbaker/wikipedia-question-generator
I have created the virtual environment using the following instruction: https://github.com/atbaker/wikipedia-question-generator#installing-with-python-34
$ pyvenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python -m textblob.download_corpora
Install the command line tool so you can use the tool easily:
$ pip install -e folder_name
Now the environment is completed.
My code ran properly on the commandline using the following:
wikitrivia 'tony'
Now I have tried to use it using php shell script as follows:
<? php
$out = shell_exec('wikitrivia "tony" ');
echo $out;
?>
But there is nothing on the output screen. I tried to run the command php -v and have shown the version. But the command wikitrivia "tony" is not working. I am using AWS Ubuntu environment.
My php version is 7 and the python version is 3.5
Hope this helps. Kindly, let me know what I can do?
I did it recently as a cron task.
You need to execute script from working dir with interpreter from venv.
Somethin like that:
<? php
$out = shell_exec('cd FULL_YOUR_PYTON_WORKING_DIR && YOUR_VENV/bin/python FULL_PATH_TO_YOUR_SCRIPT.py "tony"');
echo $out;
?>

run php file from shell script in openwrt

I am trying to run a php file from shell script file or terminal in open-wrt platform. I have executed php files in crontab and those are running perfectly. i need to run a php file without putting it into crontab.I am trying it with the following command
chmod 777 /www/api/*
cd /www/api
php myphp.php
but it showing -ash: php: not found
I have also try it putting the following command on top of the script
#!/usr/bin/php
but it is not working. i could not figure out the problem!!!
You must install php-cli package, after you can run the script by
php-cli script.php

shell_exec command cannot find libraries

I am trying to execute a shell command via shell_exec (text to speech). The command works well from the shell and the paths are set correctly, but when executed from PHP it doesn't find certain libraries. This is the command
shell_exec('echo "nice voice" | text2wave -o /path/output.wav -eval "(voice_selected_voice)" 2>&1 ');
and this is the output that I get:
/usr/bin/festival: /opt/bitnami/common/lib/libstdc++.so.6: version 'GLIBCXX_3.4.11' not found (required by /usr/bin/festival)
/usr/bin/festival: /opt/bitnami/common/lib/libstdc++.so.6: version 'GLIBCXX_3.4.9' not found (required by /usr/bin/festival)
/usr/bin/festival: /opt/bitnami/common/lib/libstdc++.so.6: version 'GLIBCXX_3.4.11' not found (required by /usr/lib/libestools.so.2.1)
... and so on ...
It looks like it cannot find those libraries, but they are exactly there
Thanks
When you run these commands via shell_exec command, you are running them with the apache user permissions. You need to sudo it via root (modify the sudoers file a bit).

Categories