This will install Lighttpd and PHP 7.x on Ubuntu 18.04 or later and perform basic configurations needed to get it up and running. This is used to create isolated dev servers that use as little memory as possible.
You can also setup SSL on these using LetsEncrypt, but it is not covered here. This is to be used for dev or testing or used on local network with a Nginx proxy handling SSL.
Start by updating the server and installing lighttpd:
sudo apt update
sudo apt upgrade
sudo apt install lighttpdEnable lighttpd to run on boot and start it up now:
sudo systemctl start lighttpd.service
sudo systemctl enable lighttpd.serviceInstall PHP as well as “readline” perl module required for fastcgi
sudo apt-get install php-cgi php-cli php-mysql php-gd php-imagick php-mbstring php-recode php-tidy php-xmlrpc php-pdo php-sqlite3 php-curl php-xml libterm-readline-gnu-perlNow install and enable PHP mod for lighttpd
sudo lighttpd-enable-mod fastcgi
sudo lighttpd-enable-mod fastcgi-phpEdit the php.ini file:
sudo nano /etc/php/7.*/cgi/php.iniAnd append the following at the bottom of the file:
short_open_tag = On
display_errors = on
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
error_log = error_log
output_buffering = Off
date.timezone = "Asia/Singapore"
upload_max_filesize = 50M
post_max_size = 50M
memory_limit = 128MNow edit the lighttpd config file:
sudo nano /etc/lighttpd/lighttpd.confTake note of the following lines:
...
...
server.document-root = "/var/www/html"
...
...
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
...
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
...
...
This shows our server document root, the user lighttpd is running as and the fact that PHP has been added correctly.
Next check the php fastcgi server configuration file:
Ensure it looks similar to this:
sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf# -*- 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" =>
((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
))
)Restart lighttpd to load new configs and enable PHP
sudo systemctl restart lighttpd.serviceCreate a PHP test script to test your new configuration:
sudo echo '<?php phpinfo(); ?>' >> /var/www/html/info.phpRemember to set correct user for the folders and files under html:
sudo chown -hR www-data:www-data /var/www/html/