I am working on a small college project using Raspberry Pi. Basically, the project is to provide an html interface to control a sensor attached to the Pi. I wrote a very simple Python code attached with a very basic html code also. Everything is done in this path /var/www/NewTest. However everytime I try to access it throws a 500 internal error. I tried simple "Hello World" examples that worked with me and tried to do this example the same way but didn't work.
led.py
from gpiozero import LED
from time import sleep
from flask import Flask, render_template
app = Flask(__name__)
ledr = LED(17)
ledg = LED(27)
ledb = LED(22)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/red/')
def red():
ledr.off()
ledg.off()
ledb.off()
ledr.on()
return ' '
@app.route('/green/')
def green():
ledr.off()
ledg.off()
ledb.off()
ledg.on()
return ' '
@app.route('/blue/')
def blue():
ledr.off()
ledg.off()
ledb.off()
ledb.on()
return ' '
if __name__ == '__main__':
app.run(debug=True)
led.conf
<virtualhost *:80>
ServerName 10.0.0.146
WSGIDaemonProcess led user=www-data group=www-data threads=5 home=/var/www/NewTest/
WSGIScriptAlias / /var/www/NewTest/led.wsgi
<directory /var/www/NewTest>
WSGIProcessGroup led
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</virtualhost>
index.html
<!doctype html>
<title>Test</title>
<meta charset=utf-8>
<a href="/red/">RED</a> <br/>
<a href="/green/">GREEN</a><br/>
<a href="/blue/">BLUE</a>
any ideas? Thanks!
The problem was in led.conf. The user needs to be pi.
<virtualhost *:80>
ServerName 10.0.0.146
WSGIDaemonProcess led user=pi group=www-data threads=5 home=/var/www/NewTest/
WSGIScriptAlias / /var/www/NewTest/led.wsgi
<directory /var/www/NewTest>
WSGIProcessGroup led
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</virtualhost>