I have several php projects which contains several php version such as php 5.6, php 7.0 etc.
Recently, I have installed lighttpd server as a local server. Here is my lighttpd.conf
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_fastcgi",
"mod_redirect",
# "mod_rewrite",
)
server.document-root = "/home/andrew/www/"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
dir-listing.activate = "enable"
include "localhost.81.conf"
And localhost.81.conf
is :
$SERVER["socket"] == ":81" {
server.document-root = "/home/andrew/www7"
}
I have installed php5.6-cgi and php7.0-cgi and when fastcgi-php5.6 is enabled, then php 5.6 works and when fastcgi-php7.0 is enabled , then php 7.0 works.
mods fastcgi-php5.6:
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi5.6",
"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"
))
and mod fastcgi-php7.0:
## Start an FastCGI server for php (needs the php7-cgi package)
fastcgi.server += ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi7.0",
"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"
))
I can not enable two fastcgi-php at same time. But I want that port 80 will work with php 5.6 and port 81 will work with php7.0.
Is it possible in lighttpd server ? What are the configuration of running multiple php version at lighttpd ?
You can update at your fastcgi-php from conf-available folder.
$ cd /etc/lighttpd/conf-available/
Make a backup file:
$ sudo cp 15-fastcgi-php.conf 15-fastcgi-php.conf.save
Now open 15-fastcgi-php.conf
and update as like:
$ sudo vi 15-fastcgi-php.conf
and paste of given below code snippet:
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi5.6",
"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"
))
)
$SERVER["socket"] == ":81" {
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi7.0",
"socket" => "/var/run/lighttpd/php81.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
))
)
}
Now, save and close and enable the mod.
$ sudo lighty-enable-mod fastcgi-php
Reload and restart the server:
$ sudo systemctl force-reload lighttpd
$ sudo systemctl restart lighttpd
I hope it will work.