Run Python script from PHP

2020-02-15 08:55发布

I want to run Python script from PHP. The script's syntax is good, when I run it from command line it generates an image file next to it. When I run the PHP file (contains Python exec) from command line it generates an image file. It's good. The problem is: when I use browser and run PHP it isn't generate any image file. I use Xubuntu OS.

标签: php python
2条回答
家丑人穷心不美
2楼-- · 2020-02-15 09:07

The problem was the matplotlib backend setting. I changed to 'Agg' and the plot function worked fine.

查看更多
Evening l夕情丶
3楼-- · 2020-02-15 09:08

Does the script that you are trying to run requires sudo privileges? If so, you will need to add the user "www-data" or web user with the command (full path) to the sudoers file (Ubuntu /etc/sudoers or execute visudo command).

More info here https://help.ubuntu.com/community/Sudoers

Another thing to look at is at memory_limit in your php.ini directive. You might be using all memory allowed to use.

查看更多
登录 后发表回答