Lighttpd, PHP with PHP-FPM, and MySQL Under Ubuntu Maverick

It is time for Lighttpd the “Fly Light” webserver installation include PHP and MySQL under Ubuntu 10.10 Maverick, let’s go!

First, update repository list, install dependencies, and remove unneeded modules

apt-get update -y
apt-get install -y build-essential make automake patch cadaver bc netcat libgeoip1 libgeoip-dev fontconfig libfontconfig-dev libpam0g-dev libpam-devperm ldap-utils libldap-2.4-2 libldap2-dev libdb4.6 libxpm-dev libtool libaio-dev libltdl3-dev mcrypt libmcrypt-dev libmhash-dev unixodbc unixodbc-dev zip unzip nano perl openssl libssl-dev libdevel-repl-perl libperl-dev libpcre3 libpcre3-dev libjpeg62 libjpeg62-dev libpng-dev libtiff4 libtiff-dev libfreetype6 libfreetype6-dev libgmp3-dev aspell libaspell-dev libpspell-dev libiconv-ruby mlocate libc-client2007e libc-client2007e-dev uw-imapd tidy libtidy-dev libbz2-dev gamin libgamin-dev sqlite3 libsqlite3-dev libreadline6 libreadline6-dev e2fsprogs uuid-dev memcached libmemcache-dev
apt-get remove -y apache2 apache2-doc apache2-utils apache2.2-common bind9 php5 mysql-server curl libcurl3 libcurl-dev libidn11 libidn11-dev libxslt-dev

pkill apache2
pkill named
pkill sendmail-mta

Install additional modules

wget http://pkgs.serversreview.net/files/gd-2.0.33.tar.gz
tar -zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr --libdir=/usr/lib --with-png=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib --with-jpeg=/usr/lib --with-xpm=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/libev-4.04.tar.gz
tar -zxvf libev-4.04.tar.gz
cd libev-4.04
./configure --prefix=/usr --libdir=/usr/lib --with-pic 
make
make install

wget http://pkgs.serversreview.net/files/gnupg-1.4.11.tar.gz
tar -zxvf gnupg-1.4.11.tar.gz
cd gnupg-1.4.11
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget libidn-1.9.tar.gz http://pkgs.serversreview.net/files/libidn-1.9.tar.gz
tar -zxvf libidn-1.9.tar.gz
cd libidn-1.9
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/curl-7.21.6.tar.gz
tar -zxvf curl-7.21.6.tar.gz
cd curl-7.21.6
./configure --prefix=/usr --libdir=/usr/lib --with-openssl --with-libidn  --enable-ipv6
make
make install

wget http://pkgs.serversreview.net/files/libxml2-2.7.8.tar.gz
tar -zxvf libxml2-2.7.8.tar.gz
cd libxml2-2.7.8
rm -rf /usr/lib/libxml2*
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/libxslt-1.1.26.tar.gz
tar -zxvf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
rm -rf /usr/lib/libxslt* /usr/lib/libexslt*
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/lua-5.1.4.tar.gz
tar -zxvf lua-5.1.4.tar.gz
cd lua-5.1.4
sed -i 's/\/usr\/local/\/usr/g' Makefile
#if x86_64 then
#edit src/Makefile
#change CFLAGS= -O2 -Wall $(MYCFLAGS)
#with CFLAGS= -O2 -Wall -fPIC $(MYCFLAGS)
make linux install

wget http://pkgs.serversreview.net/files/valgrind-3.6.1.tar.bz2
tar -jxvf valgrind-3.6.1.tar.bz2
cd valgrind-3.6.1
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/libevent-2.0.11-stable.tar.gz
tar -zxvf libevent-2.0.11-stable.tar.gz
cd libevent-2.0.11-stable
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/gdbm-1.8.3.tar.gz
tar -zxvf gdbm-1.8.3.tar.gz
cd gdbm-1.8.3
./configure --prefix=/usr --libdir=/usr/lib
make
make install


Install MySQL 5.5

groupadd mysql
useradd -r -g mysql mysql
wget http://pkgs.serversreview.net/files/mysql-5.5.12-linux2.6-`uname -m`.tar.gz
tar -C /usr/local -zxvf mysql-5.5.12-linux2.6-`uname -m`.tar.gz
mv /usr/local/mysql-5.5.12-linux2.6-`uname -m` /usr/local/mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
/usr/local/mysql/scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data

copy one of the following MySQL configuration to /etc

/usr/local/mysql/support-files/my-huge.cnf
/usr/local/mysql/support-files/my-innodb-heavy-4G.cnf
/usr/local/mysql/support-files/my-large.cnf
/usr/local/mysql/support-files/my-medium.cnf
/usr/local/mysql/support-files/my-small.cnf

cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf

copy MySQL init script, make it executable and autorun after booting

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
echo "/etc/init.d/mysql start" >> /etc/init.d/rc.local
/etc/init.d/mysql start

securing mysql

/usr/local/mysql/bin/mysql_secure_installation

Install Lighttpd

wget http://pkgs.serversreview.net/files/lighttpd-1.4.28.tar.gz
tar -zxvf lighttpd-1.4.28.tar.gz
cd lighttpd-1.4.28
export LUA_CFLAGS="-I/usr/include" 
export LUA_LIBS="-L/usr/lib -llua"
./configure --prefix=/usr --libdir=/usr/lib --with-libev=/usr/lib --with-mysql=/usr/local/mysql/bin/mysql_config --with-ldap --with-attr --with-valgrind --with-openssl=/usr/bin --with-openssl-includes=/usr/include/openssl --with-openssl-libs=/usr/lib/openssl --with-zlib --with-bzip2 --with-fam --with-webdav-props --with-webdav-locks --with-gdbm --with-memcache --with-lua

All plugins will be enabled if the configuration’s correct

Configuration Complete

make
make install

Install PHP 5.3

wget http://pkgs.serversreview.net/files/autoconf-2.13.tar.gz
tar -zxvf autoconf-2.13.tar.gz
cd autoconf-2.13
./configure
make && make install

wget http://pkgs.serversreview.net/files/php-5.3.6.tar.gz
tar -zxvf php-5.3.6.tar.gz
cd php-5.3.6
./buildconf --force
./configure --prefix=/usr --libdir=/usr/lib  --with-libdir=lib --enable-force-cgi-redirect --enable-fpm --enable-cli --with-mcrypt --enable-mbstring --with-openssl --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-zlib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-png --with-jpeg --with-gmp --with-sqlite --enable-pdo --with-xpm-dir=/usr/lib --with-freetype-dir=/usr/include/freetype2 --with-ttf=/usr/include/freetype2 --enable-gd-native-ttf --enable-fileinfo --disable-debug --with-pic --with-bz2 --with-curl --with-curlwrappers --without-gdbm --with-gettext --with-iconv --with-pspell --with-pcre-regex --with-imap --with-imap-ssl=/usr/lib --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --disable-sysvsem --disable-sysvshm --disable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-memory-limit --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic --with-system-tzdata --with-odbc --enable-gd-jis-conv --enable-dom --disable-dba --enable-xmlreader --enable-xmlwriter --with-tidy  --with-xml --with-xmlrpc --with-xsl --enable-bcmath --enable-soap --enable-zip --enable-inline-optimization --with-mhash --enable-mbregex
make
make install
cp php.ini-production /usr/lib/php.ini

Create Lighttpd Configuration

useradd www
passwd www
mkdir -p /usr/html
mkdir -p /etc/lighttpd
nano /etc/lighttpd/lighttpd.conf

This is basic Lighttpd configuration with PHP-FPM

##===============================================================================##
## Lighttpd Configuration File ##

# Default Document Root
# This is the site that the server will revert to incase of an unknown Virtual Host
server.document-root = "/usr/html" 

# Listening Port
server.port = 80

# Lighttpd User and Group
server.username = "www"
server.groupname = "www"

# Acceptable Mime types
mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)

server.modules += ("mod_fastcgi")
fastcgi.server = ( ".php" =>
  ( "localhost" =>
    (
      "host" => "127.0.0.1",
      "port" => "9000"
    )
  )
)

static-file.exclude-extensions = (".fcgi", ".php", ".rb", "~", ".inc")
index-file.names = ("index.html", "index.php")
##===============================================================================##

Create Lighttpd Init Script

nano /etc/init.d/lighttpd

The scrit will call lighttpd binary and configuration, it would be like this

case "$1" in
	start)
		/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
		echo "Lighttpd started successfully"
		exit 1
	;;

	stop)
		pkill lighttpd
		echo "Lighttpd stopped"
		exit 1
	;;
	restart)
		echo "Stopping Lighttpd"
		pkill lighttpd
		sleep 1
		echo "Starting Lighttpd"
		/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
		sleep 1
		echo "Lighttpd restarted successfully"
		exit 1
	;;
	*)
		echo "Usage: start - stop - restart"
		exit 1
	;;
esac

PHP-FPM configuration

cp /usr/etc/php-fpm.conf.default /etc/php-fpm.conf
nano /etc/php-fpm.conf

change user and group from “nobody” to “www”

user = www
group = www

delete semicolon (;) from the following lines

pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
pm.max_requests

Create PHP-FPM Init Script

nano /etc/init.d/php-fpm

same as Lighttpd, basically calling php-fpm binary file and configuration

case "$1" in
	start)
		/usr/sbin/php-fpm --fpm-config /etc/php-fpm.conf
		echo "PHP-FPM started successfully"
		exit 1
	;;

	stop)
		pkill php-fpm
		echo "PHP-FPM stopped"
		exit 1
	;;
	restart)
		echo "Stopping php-fpm"
		pkill php-fpm
		sleep 1
		echo "Starting php-fpm"
		/usr/sbin/php-fpm --fpm-config /etc/php-fpm.conf
		sleep 1
		echo "PHP-FPM restarted successfully"
		exit 1
	;;
	*)
		echo "Usage: start - stop - restart"
		exit 1
	;;
esac

PHP.INI

nano /usr/lib/php.ini

delete semicolon (;) from the following lines and edit the values

date.timezone = America/New_York
cgi.fix_pathinfo = 0

Make Lighttpd and PHP-FPM init scripts executable and autostart after reboot

chmod +x /etc/init.d/lighttpd /etc/init.d/php-fpm
echo "/etc/init.d/lighttpd start" >> /etc/init.d/rc.local
echo "/etc/init.d/php-fpm start" >> /etc/init.d/rc.local

Create phpinfo in /usr/html directory

nano /usr/html/phpinfo.php

<?php phpinfo(); ?>

Now Start Lighttpd, PHP, and MySQL

/etc/init.d/lighttpd start
/etc/init.d/php-fpm start
/etc/init.d/mysql start

Voila!!!

Lighttpd - PHP - MySQL with PHP-FPM under Ubuntu Maverick

Domain / Virtual Host Configuration

Create domain configuration separated from main configuration

mkdir -p /etc/lighttpd/domain
nano /etc/lighttpd/domain/serversreview.net.conf

The basic configuration is like the following

$HTTP[“host”] == “serversreview.net” {
server.document-root = “/home/www/serversreview.net/public_html”
accesslog.filename = “/home/www/serversreview.net/logs”
}

and then add the following line to /etc/lighttpd/lighttpd.conf

include “domain/serversreview.net.conf”

I’ll put all domains under www user, public directory is public_html and log directory is logs, and then restart Lighttpd.

mkdir -p /home/www/serversreview.net/public_html /home/www/serversreview.net/logs
/etc/init.d/lighttpd restart

Now you can upload your files to your domain directory and access it via browser.

{ 0 comments }

5 thoughts on “Lighttpd, PHP with PHP-FPM, and MySQL Under Ubuntu Maverick

  1. # /etc/init.d/lighttpd restart
    Stopping Lighttpd
    Starting Lighttpd
    2012-06-10 16:25:02: (configfile.c.884) source: /etc/lighttpd/lighttpd.conf line: 37 pos: 9 invalid character in variable name
    2012-06-10 16:25:02: (configfile.c.940) configfile parser failed at: include
    Lighttpd restarted successfully

    Help me

Leave a Reply

Your email address will not be published. Required fields are marked *