Configuring Lighttpd on Shunya OS¶
Getting Started¶
Installation¶
To install lighttpd run the following command:
sudo opkg install lighttpd
Note
As we are an Embedded OS base lighttpd is minimal. You can install it’s modules as you require it
Configuration¶
Lighttpd configuration files are located in /etc/lighttpd.conf. Lighttpd server root is located in /www/pages/
Configuring lighttpd for php using fastcgi¶
For using php with lighttpd you need to install the following modules: php php-cgi lighttpd-module-cgi lighttpd-module-fastcgi
This can be done through the following command
Step 1:Installing necessary modules
sudo opkg install php php-cgi lighttpd-module-cgi lighttpd-module-fastcgi
Step 2:Setting server.modules to include mod_fastcgi mod_cgi
In/etc/lighttpd.conf do the following changes
In the server.modules section uncomment the beginning of the lines(line24 and line29) to enable mod_fastcgi and mod_cgi
- mod_fastcgi
- mod_cgi
Step 3:You need to extend /etc/lighttpd.conf to load the fastcgi module and use php-cli:
This is achieved by the lines in the /etc/lighttpd.conf. You can simply uncomment the lines #### fastcgi module section.
Warning
If you are uncommenting the lines under the fastcgi module section don’t forget to change the bin-path of php-cgi to /usr/bin/php-cgi
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
)
)
)
Step 4:Write a php script in /www/pages/
For testing purpose we created a minimal file /www/pages/index.php and removed(renamed) the previously created file /www/pages/index.html.
The test .php file contains a single line:
<?php phpinfo(); ?>
Step 5:Restart lighttpd server
systemctl restart lighttpd
Step 6:Test
To test this on the browser type the following in the URL: localhost/filename.php (in our case it was localhost/index.php)
Configuring lighttpd for cgi-bin¶
For using cgi-bin with lighttpd you need to install the following modules: lighttpd-module-cgi lighttpd-module-fastcgi
This can be done through the following command
Step 1:Installing necessary modules
sudo opkg install lighttpd-module-cgi lighttpd-module-fastcgi
Step 2:Setting server.modules to include mod_fastcgi mod_cgi
In/etc/lighttpd.conf do the following changes
In the server.modules section uncomment the beginning of the lines(line24 and line29) to enable mod_fastcgi and mod_cgi
- mod_fastcgi
- mod_cgi
Step 3:Enable cgi.assign by uncommenting the lines under #### CGI module and add “.sh” => “/usr/ bin/sh”
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl",
".sh" => "/bin/sh")
Step 4:Write a cgi-script in /www/pages/cgi-bin/
Note
If the folder cgi-bin is not present you should make it
Here is a sample shell script that we tested.
#!/bin/sh
printf "Content-type: text/html\n\n"
printf "Hello World!\n"
Warning
Don’t forget to make the file executable or the script will not get executed
Step 5:Restart lighttpd server
systemctl restart lighttpd
Step 6:Test cgi-bin
To test this on the browser type the following in the URL: localhost/cgi-bin/name-of-script