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

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install lighttpd lighttpd-fastcgi

Lighttpd configuration file changes

Change or add the following lines from the default lighttpd configuration file

vi /etc/lighttpd/lighttpd.conf

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

cd /etc/lighttpd/
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

htdigest -c /etc/lighttpd/.passwd 'Authorized users only' bob

Set some access rights

chown -R asterisk:asterisk /var/log/lighttpd/
mkdir /var/run/lighttpd
chown -R asterisk:asterisk /var/run/lighttpd/

Start Lighttpd

chkconfig lighttpd on
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.

Last updated by .




Related posts:
  1. Namecheap SSL certificate for Sysadminman VPS
  2. Using callwithus with Asterisk, FreePBX and A2Billing
  3. iptables for Asterisk and FreePBX



SysAdminMan provides virtual PBX hosting based on Asterisk and Freeswitch.
Avaialble systems include FreePBX, PBX-in-a-Flash, Elastix, A2Billing and FusionPBX.
More details and prices can be found at sysadminman.net


6 Comments

  1. 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

  2. matt:

    Hi Dominic,

    I think maybe you have a syntax error in your config file. Maybe a missing bracket or quote mark.

  3. Dominic:

    Hi Matt thank for your quick response. I’m going to remove lighttpd and start from scratch. I hope this work for me.

  4. Dominic:

    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
    Starting 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]

  5. 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.

  6. Gulshan:

    You need to enable all modules related to cgi in modules.conf.

Leave a comment