FreeBSD Install Lighttpd Web Server

I’ve received couple of request about running Lighttpd web server under FreeBSD:

How do I install Lighttpd web server under FreeBSD along with MySQL 5 and PHP5?

lighttpd a secure, fast, compliant and very flexible web-server which has been optimized for high-performance environments. It has a very low memory footprint compared to other webservers and takes care of cpu-load. Its advanced feature-set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) make lighttpd the perfect webserver-software for every server that is suffering load problems. Installing lighttpd is quite simple under FreeBSD operating system using ports.

Lighttpd on FreeBSD

First update your port tree by typing following commands:
# portsnap fetch
# portsnap update

Install lighttpd web server under FreeBSD

Lighttpd port is located under /usr/ports/www/lighttpd:
# cd /usr/ports/www/lighttpd
Install lighttpd:
# make
# make install
# make clean

Install MySQL server

Install MySQL server:
# cd /usr/ports/databases/mysql50-server/
# make
# make install
# make clean

Also install mysql client support
# /usr/ports/databases/mysql50-client
# make
# make install
# make clean

Finally install mysql scripts:
# cd /usr/ports/databases/mysql50-scripts
# make
# make install
# make clean

Install php5 for lighttpd

Install PHP5 scripting:
# cd /usr/ports/lang/php5
# make
# make install
# make clean

Next you must install PHP5 extensions such as GB, mysql support and so on. At least select following extensions from menu:

  • ctype: The ctype shared extension for php
  • curl: The curl shared extension for php
  • dom: The dom shared extension for php
  • gd: The gd shared extension for php
  • imap: The imap shared extension for php
  • mbstring: The mbstring shared extension for php
  • mcrypt: The mcrypt shared extension for php
  • mysql: The mysql shared extension for php
  • mysqli: The mysqli shared extension for php
  • pcre: The pcre shared extension for php
  • posix: The posix shared extension for php
  • session: The session shared extension for php
  • simplexml: The simplexml shared extension for php
  • xml: The xml shared extension for php
  • xmlreader: The xmlreader shared extension for php
  • xmlwriter: The xmlwriter shared extension for php
  • zlib: The zlib shared extension for php

Type the following command:
# cd /usr/ports/lang/php5-extensions
# make
# make install
# make clean

Auto start lighttpd and mysql service

You need to enable both services. Open /etc/rc.conf:
# vi /etc/rc.conf
Append following two lines:

Start Mysql Server Under FreeBSD

To start MySQL server, enter:
# /usr/local/etc/rc.d/mysql-server start

Start Lighttpd Server Under FreeBSD

To start Lighttpd server, enter:
# /usr/local/etc/rc.d/lighttpd start

Verify that lighttpd is running:
# netstat -nat

FreeBSD Lighttpd configuration file location

  • Config file location: /usr/local/etc/lighttpd.conf
  • Default documentation root location : /usr/local/www/data/
  • Default username and groupname : www

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • CL Aug 11, 2008 @ 3:37

    Ok. Regarding PHP. Above there is no mention of which of the many options could or should be selected to make this work. CLI, CGI, FastCGI, etc… I’ve tried many combinations and read dozens of contradictory pages on this – without success – yet.

  • 🐧 nixCraft Aug 11, 2008 @ 6:19

    You need to use PHP FastCGI, There is a Link at the bottom of tutorial.

  • GW Sep 2, 2008 @ 16:28

    I made a temporary and partially buggy not-official port for lighttpd 1.5. More precisely it is called lighttpd-devel and contains version 1.5.0-svn2299. It can be found on:

    Before you install it you must uninstall all other lighttpd installations. For the port version download, extract and use the above procedure on lighttpd-devel.port.tar.bz2. The configuration window is the only buggy thing in it, so try to select only things that work (not every option works). If you miss-configured something use “make config” to reconfigure.

  • Karthik Oct 2, 2009 @ 18:19

    Hey Vivek,

    I installed lighttpd and mysql
    mysql works fine but i can see lighttpd when i run netstat
    and i’m also unable to connect!, what could be the reason?

  • Christofer Feb 13, 2010 @ 10:26

    Karthik -> read the httpd log…

  • Ty Apr 14, 2010 @ 6:23

    Also add /var/log/lighttpd.access.log mine wouldn’t start without the three log files: lighttpd.log, lighttpd.error.log and lighttpd.access.log.

    chown www:www

    And all is right in the world.

  • plaid May 17, 2010 @ 8:39

    Good article, thanks

  • Profesor Feb 8, 2011 @ 16:05

    thanks… useful for me… i will try to do.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum