Skip to content

web server

Frank Bauernöppel edited this page Dec 7, 2018 · 13 revisions

The lighttpd web server is already included in the rpi-image-avg with JavaScript plus PHP. This is achieved by adding few packages to the image recipe:

IMAGE_INSTALL_append += " \
  lighttpd \
  lighttpd-module-fastcgi \
  php-cgi \
  php-cli \
"

When entering the raspi IP address in a web browser (like http://raspberrypi3.local or a numeric IP), a test page shows up, saying It works.

Note that lighttpd is quite modular. Not many modules are installed in the the rpi-image-avg image by default. You may add more modules by installing the corresponding packages or by adding more modules into the image recipe and re-baking the image.

PHP

PHP is a server-side technology for dynamically generating HTML.

For testing PHP, add a new file phpinfo.php to the web root folder /www/pages/ with the following content:

<?php phpinfo(); ?>

(see http://php.net/manual/en/function.phpinfo.php)

And change the /etc/lighttpd.conf config file as shown in the next sections:

enable fastcgi module

in the server.modules section add/uncomment the fastcgi module:

server.modules              = (
                               ...
                               "mod_fastcgi", 
                               ...

configure fastcgi server

fastcgi.server             = ( ".php" =>     
                               ( "localhost" =>
                                 (           
                                   "socket" => "/tmp/php-fastcgi.socket",
                                   "bin-path" => "/usr/bin/php-cgi"
                                 )           
                               )              
                            )       

enable files & folder listings

only if your web app needs it:

dir-listing.activate      = "enable"
dir-listing.hide-dotfiles = "enable"
dir-listing.encoding      = "utf-8"

Finally, restart the web server (sysvinit shell command: /etc/init.d/lighttpd restart).

When you enter in the browser http://raspberrypi3.local/phpinfo.php, a lengthy php info page shows up.

JavaScript

JavaScript is a client-side scripting language for HTML. It should already be enabled in lighttpd.

Add a test file hello_js.html to the web root folder /www/pages/ with the following content:

<!DOCTYPE HTML>
<html>
<body>
  <p>Before the script...</p>
  <script>
    alert( 'Hello, world!' );
  </script>
  <p>...After the script.</p>
</body>
</html>

(Example taken from https://javascript.info/hello-world).

Now, enter http://raspberrypi3.local/hello_js.html in your web browser. The page shows up with the first text line and a message box. After pressing OK in the box, the second line shows up too.

SQL Server

The MariaDB SQL server fits in nicely.