For most cases the recommended web server for the Raspberry Pi is lighttpd. But when I entered the command sudo apt-get install php
to add php to the Pi, I was surprised to find apache2 was a dependency of php7. I didn’t need apache2. I wasn’t sure if it would interact with lighttpd and I didn’t need all the code that came with it. I partly understand the reasoning but it didn’t solve my problems. I did some Google searches and found a few out-dated how-tos so I collected the current steps here.
To start, make sure your system is fully updated with the standard:
sudo apt-get update
sudo apt-get upgrade
Also, you will need lighttpd installed
sudo apt-get install lighttpd
Next is the php7 install. These commands install the specific php packages to work with lighttpd.
sudo apt-get install php7.0-fpm php-cgi
The last step is to enable the php module for lighttpd and restart the web server.
sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
That’s it. To verify it is simple. Create a file (info.php for example) in you web directory /var/www/html with the contents below.
<?php
phpinfo();
and then browse to that page (on my network is was http://raspberrypi/info.php). You should be greeted with more php information that you will ever need.