I've got Lighttpd setup on my Raspberry Pi, but I'd like to get server-side code working now. I'm familiar with PHP, but I figure I should try Python as it's supposed to be the "go to" language for the Raspberry Pi. How can I get Python handling server-side code via Lighttpd?
|
|
What you need is CGI support for lighthttpd. Open the lighttpd configuration file (/etc/lighttpd/lighttpd.conf), and uncomment the "mod_cgi" line (remove the # from the beginning of the line if one exists) or add this line if not present.
Add the following to the bottom of the file:
Restart the lighttpd daemon:
Then creatge a cgi-bin directory under your webserver's root directory. Any files ending with .py in this directory will be processed by Python. You can now write Python scripts to handle web requests. You may want to read this tutorial on writing CGI programs with Python. If on the other hand you would rather use a framework to handle some of the low level details and improve developer productivity. I suggest checking out web.py. You can install it using apt:
Lucas at the Cloud 101 Blog has posted a great tutorial on writing web pages using the webpy framework. |
|||||||||||||||||||||
|
|
The accepted answer did not work for me and it also ignores the pre-configured packages that are available for Lighttpd. The correct way to install Python on Lighttpd for the Raspberry is: First enable cgi by
This creates a new configuration file for Lighttpd:
Edit the configuration file
Make sure python 2 is installed by executing:
Now, restart
Good luck! |
|||
|
|