I am running Ubuntu 14.04 with a locally hosted webpage running on Apache2. I can access index.php fine through my browser, but I want that page to display a graph that is prepared in a python script called graph.py. graph.py will execute fully when the I execute index.php from the terminal, and it will PARTIALLY execute when I access it from the browser. commands from pyplot, used within the graph.py file will not execute when called from the browser.
I have simplified the contents of the files for this question.
Contents of index.php:
<?php
echo exec('whoami');
echo "</br>";
$r = `python graph.py`;
echo($r);
?>
Contents of graph.py:
#!/usr/bin/python2.7
import cgi
import matplotlib.pyplot as plt
print("Initial file parsing successful")
plt.plot([1,2,3,4])
print("File completed operation using pyplot")
The output of index.php from the terminal has what I would expect:
MYUSERNAME</br>Initial file parsing successful
File completed operation using pyplot
The browser never completed the PyPlot operation as shown by its output:
www-data
Initial file parsing successful
After scouring the internet for answers, this post appears to be the most similar to my issue:
Why cannot PHP execute a command from web browser?
As suggested in the responses, it makes sense that I may be dealing with a permissions issue. I used "updatedb" and "locate pyplot" to find every instance the pyplot module appears. On my machine, there are three files in two directories:
/usr/lib/pymodules/python2.7/matplotlib/pyplot.py
/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc
/usr/share/pyshared/matplotlib/pyplot.py
Since pyplot has other dependencies in the matplotlib directory, I set permissions for every file in both of these directories with "chmod 777." I know I will have to restore these for security reasons once I find where I can scale permissions back, but even allowing that level of access, the php file will not execute when accessed from the browser. Does anyone have any ideas what could be catching this?