bitnuts.de logo   Downloads About Contact

Install Lighttp and PHP 7 on your Raspberry Pi

This is a very quick walk through and I assume you are fimliar with the Linux shell.

First we update Raspbian, uninstall Apache and then install Lighttpd:

sudo apt-get update
sudo apt-get upgrade

sudo apt-get remove apache2

sudo apt-get install lighttpd

You can now test the web server by first obtaining your IP address

hostname -I

and then trying to browse to http://YOUR_IP. You should see a preset page, but you can easily change it by opening nano:

sudo nano /var/www/html/index.html

Now let us install PHP version 7 by doing

sudo apt-get install php7.0-fpm

sudo lighttpd-enable-mod fastcgi
sudo lighttpd-enable-mod fastcgi-php

You now have to change the fastcgi configuration file, enter

sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf

and change the file so, that it looks like:

# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/var/run/php/php7.0-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

This basically utilizes the PHP-FPM socket file. You should now force Lighttpd to reload its service:

sudo service lighttpd force-reload

You can place .php files in the /var/www/html folder and they should then be executed. You can test it by editing

sudo nano /var/www/html/index.php

and adding the following line

<? php phpinfo() ?>

If you then call http://YOUR_IP/index.php, you should see some basic information about the PHP engine.