Configuring lighttpd for use with Asterisk & FreePBX
I recently had a client that wanted to install Asterisk and FreePBX on a machine that was already running Apache so I though I’d have a go at getting it working with lighttpd instead.
It is pretty easy to setup and worked well. The instructions below are for CentOS 5.1.
Here’s how to set it up. You will probably need to alter this for your environment but it’ll be a good starting point.
Prerequisites
You need to have already installed Asterisk and FreePBX. When installing FreePBX you should choose a unique location for the install rather than the Apache default – /var/www/html. I chose /var/www/freepbx.
Installing lighttpd
I chose to install lighttpd from rpmforge but you could just as easy compile it from source.
See here for details on setting up rpmforge – http://dag.wieers.com/rpm/FAQ.php#B
yum install lighttpd lighttpd-fastcgi
Lighttpd configuration file changes
Change or add the following lines from the default lighttpd configuration file
server.document-root = "/var/www/freepbx"
server.port = 81
server.username = "asterisk"
server.groupname = "asterisk"
server.pid-file = "/var/run/lighttpd/lighttpd.pid"
server.modules = ( "mod_fastcgi", "mod_auth" )
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
)
)
)
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/lighttpd.pem"
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/.passwd"
auth.debug = 2
auth.require = ( "/" =>
(
"method" => "digest",
"realm" => "Authorized users only",
"require" => "valid-user"
)
)
Generate the SSL certificate
openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 365 -nodes
chown asterisk:asterisk lighttpd.pem
chmod 600 lighttpd.pem
Create the password file
Set some access rights
mkdir /var/run/lighttpd
chown -R asterisk:asterisk /var/run/lighttpd/
Start Lighttpd
service lighttpd start
And that’s it. You should now be able to connect to FreePBX on port 81 using HTTPS.
You should be asked for a username/password which, if you followed the instructions above, will be ‘bob’ and whatever password you chose.
Related posts:
- Namecheap SSL certificate for Sysadminman VPS
- Using callwithus with Asterisk, FreePBX and A2Billing
- iptables for Asterisk and FreePBX

Dominic:
Hello,
I follow up your nice tutorial but I got an error on line 129 (fastcgi.server) when I used the command service lighttpd start. Error: can’t start lighttpd line error 129 near to EOL, connection “FAILED”. could you please help me I’m running Centos5.6 with Asterisk+FreePbx runing, I’m trying to use lighttpd before I integrate A2billing. Thank you in advance for your help.
Regards,
Dominic
9 September 2011, 1:39 pmmatt:
Hi Dominic,
I think maybe you have a syntax error in your config file. Maybe a missing bracket or quote mark.
9 September 2011, 2:53 pmDominic:
Hi Matt thank for your quick response. I’m going to remove lighttpd and start from scratch. I hope this work for me.
9 September 2011, 6:36 pmDominic:
Hi Matt,
I did what I said on my last post and I’m getting the same respond from my server. I compared your configuration with yours and they look pretty much as the same. Please help.
[root@localhost lighttpd]# service lighttpd start
9 September 2011, 10:23 pmStarting lighttpd: Duplicate config variable in conditional 0 global: server.modules
2011-09-09 05:21:05: (configfile.c.912) source: /etc/lighttpd/lighttpd.conf line: 149 pos: 15 parser failed somehow near here: (EOL)
[FAILED]
matt:
If your lighttpd.conf file has no passwords in do you want to post it here? Sounds like an issue near line 149. Maybe just above.
9 September 2011, 10:44 pm