android bsd linux unix & open-source world


FreeBSD: How To Install Lighttpd with PHP5-FastCGI and MySQL Support in FreeBSD 8

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed or subscribe via E-mail for updates on this topic.

In this article I'll show you how to install and configure Lighttpd web server on FreeBSD 8.1 with PHP5 support (through FastCGI) and MySQL support.

1. FreeBSD port tree update

Update FreeBSD ports using the following command:

portsnap fetch update

Once is done, we can proceed with the next step.

2. Install MySQL Server and Client

To install MySQL Server (this will install MySQL Client as well), enter:

cd /usr/ports/databases/mysql51-server/
make install clean

By default, MySQL has no password. To create a password for the MySQL user root , enter:

mysqladmin -u root password yourpassword

You should set a MySQL password for your hostname too, because otherwise anybody can access your database:

mysqladmin -h -u root password yourpassword

3. Install PHP5 and PHP5-extensions

To install PHP5, enter:

cd /usr/ports/lang/php5
make install clean

To install PHP5-extensions, enter:

cd /usr/ports/lang/php5-extensions
make config

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

and install them with this command:

make install clean

4. Install lighttpd and enable PHP support through FastCGI

To configure options for lighttpd, enter:

cd /usr/ports/www/lighttpd
make config

lighttpd freebsd options

To install lighttpd under FreeBSD 8, enter:

cd /usr/ports/www/lighttpd
make install clean

To enable FastCGI support, edit lighttpd.conf ( usually located in /usr/local/etc/lighttpd.conf )

vi /usr/local/etc/lighttpd.conf

and make sure mod_fastcgi is enabled:

server.modules += ( "mod_fastcgi" )

and append ( or uncomment ) the following code:

fastcgi.server = ( ".php" =>
( "localhost" =>
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi"

Save and close lighttpd.conf.

Create and set the access rights to the log files (check the lighttpd.conf to locate the logs):

touch /var/log/lighttpd.access.log
touch /var/log/lighttpd.error.log
chown www /var/log/lighttpd.*

Create /var/run/lighttpd directory according to your lighttpd.conf

mkdir /var/run/lighttpd/
chown -R www /var/run/lighttpd/

5. Enable services to start on boot

To enable the services, edit /etc/rc.conf file and make sure the following lines are enabled:


Start the services:

/usr/local/etc/rc.d/mysql-server start
/usr/local/etc/rc.d/lighttpd start

6. Testing lighttpd

The document root of the default web site is /usr/local/www/data. We'll create a PHP file in that directory and call it in a browser (you should create the directory if it doesn't exist).

The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /usr/local/www/data/info.php

<?php phpinfo();?>

Now open info.php in your browser. If everything it's ok, you should see something like this:


That's all.

Print This Post Print This Post
Comments (2) Trackbacks (1)
  1. Thanks for the article! Really useful to a Linux user trying BSD.

  2. When I open info.php in browser it shows nothing, so I do “view source” and it shows:

Leave a comment