Build Lighttpd server in Raspberry Pi
Posted May 27, 2020 • 2 min read
Lighttpd, like Ngnix, is designed to run on devices with low memory and low CPU load. They are all very suitable for running on the Raspberry Pi.
This article will explain how to run the basic configuration of Lighttpd on the Raspberry Pi and how to use it with PHP-FRM.
First, we first ensure that our Raspberry Pi software is up to date:
$sudo apt-get update
$sudo apt-get upgrade
We also need to remove Apache2, if your system has been removed, you can skip this step.
$sudo apt-get remove apache2
Next, you can install Lighttpd.
$sudo apt-get install lighttpd
After Lighttpd has been installed correctly, we need to first determine whether it is working properly. Use any browser and enter the LAN address of the Raspberry Pi to access. If you don't know the LAN address, you can use the following command to get it:
You will see the following page:
If you think this page is too ugly, you can modify it yourself:
$sudo vim /var/www/html/index.html
In this tutorial, we will use PHP-FPM, the version is PHP7. Why use PHP7 instead of PHP5? Because PHP7 is updated, performance is better and memory management is better.
We can install PHP-FPM in the following ways:
$sudo apt-get install php7.0-fpm
After installing PHP-FPM, we need to run the following two commands to create two hyperlinks. When Lighttpd is running, it will read the two settings for PHP.
$sudo lighttpd-enable-mod fastcgi
$sudo lighttpd-enable-mod fastcgi-php
lighttpd runs PHP-CGI instead of PHP-FPM by default, we can run PHP-FPM by modifying the following configuration file:
$sudo vim /etc/lighttpd/conf-available/15-fastcgi-php.conf
Modify the above configuration file as follows:
#-*-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" ))
After everything is ready, we can restart lighthttpd.
$sudo service lighttpd force-reload
After restarting, we can write a PHP file to confirm whether our configuration takes effect.
$sudo vim /var/www/html/index.php
The contents of the file are as follows:
<? php phpinfo()?>
- Finally, we are accessing the Raspberry Pi in the same way as step 4. If you can see a PHP information page, it means that we have successfully built a Lighttpd Web server using PHP on the Raspberry Pi.
After reading all the true love, please like it and go? Your "three links" is the biggest motivation for Liang Xu's continuous creation!
- Follow Original public account "Liu Xu Linux" and get the latest Linux dry goods as soon as possible!
- The public account backstage reply [information][interview][resume]to obtain the interview, self-improvement, resume and other materials of selected top-tier manufacturers.
- Follow my blog: lxlinux.net