FreeBSD Lighttpd fastcgi php configuration and installation

ww‮l.w‬autturi.com
FreeBSD Lighttpd fastcgi php configuration and installation

To configure and install Lighttpd with FastCGI support for PHP on FreeBSD, you will need to follow these steps:

  1. Install the Lighttpd web server:
sudo pkg install lighttpd
  1. Install the FastCGI module for Lighttpd:
sudo pkg install lighttpd-mod_fastcgi
  1. Install PHP:
sudo pkg install php74
  1. Enable the FastCGI module in Lighttpd by adding the following line to the server.modules section of the Lighttpd configuration file (/usr/local/etc/lighttpd/lighttpd.conf):
"mod_fastcgi",
  1. Configure the FastCGI module by adding the following block to the Lighttpd configuration file:
fastcgi.server = ( ".php" =>
  ((
    "bin-path" => "/usr/local/bin/php-cgi",
    "socket" => "/tmp/php.socket",
    "max-procs" => 1,
    "idle-timeout" => 20,
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "4",
      "PHP_FCGI_MAX_REQUESTS" => "10000"
    ),
    "bin-copy-environment" => (
      "PATH", "SHELL", "USER"
    ),
    "broken-scriptfilename" => "enable"
  ))
)
  1. Restart Lighttpd to apply the changes:
sudo service lighttpd restart

That's it! Lighttpd should now be configured to handle PHP scripts using FastCGI. To test it, you can create a file called test.php in the Lighttpd document root (usually /usr/local/www/lighttpd/) with the following contents:

<?php
phpinfo();
?>

Then, access http://localhost/test.php in your web browser. You should see a page displaying information about your PHP installation.

Created Time:2017-10-28 20:40:35  Author:lautturi