Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Installing and configuring Lighttpd with PHP + FastCGI

Leer en espanol
Installing and configuring Lighttpd with PHP + FastCGI

Table of contents

It is optimized for environments where speed is very important, and that is why it co ===

Light logo

lighttpd (pronounced lighty) is a web server designed to be fast, secure, flexible, and faithful to standards.

It is optimized for environments where speed is very important, and therefore consumes less CPU and RAM memory than other servers. For everything it offers, lighttpd It is appropriate for any server that has loading problems.

lighttpd is free software and is distributed under the BSD license. Works in GNU/Linux andUNIX officially. For Microsoft Windows there is currently a distribution known as Lighttpd For Windows maintained by Kevin Worthington.

We download the code:

We decompress

CODE
Bash
tar -xzvf lighttpd-1.4.30.tar.gz

We access the folder

CODE
text
cd lighttpd-1.4.30

We create the folder where we are going to install it.

BASH
Bash
 mkdir /usr/local/lighttpd

The configuration will be default, we will install it in /usr/local/lighttpd  and disable ipv6, zlib and bzip2

CODE
text
./configure --prefix=/usr/local/lighttpd --without-zlib --without-bzip2 --disable-ipv6

If you get the following error when compiling:

configure: error: pcre-config not found, install the pcre-devel package or build with –without-pcre

It is because you are missing the libpcre libraries, we install them.

apt-get install libpcre3 libpcre3-dev

At the end we will see a summary of the configuration, activated and deactivated plugins.

Plugins:

CODE
text
enabled:
mod_access
mod_accesslog
mod_alias
mod_auth
mod_cgi
mod_compress
mod_dirlisting
mod_evhost
mod_expire
mod_extforward
mod_fastcgi
mod_flv_streaming
mod_indexfile
mod_proxy
mod_redirect
mod_rewrite
mod_rrdtool
mod_scgi
mod_secdownload
mod_setenv
mod_simple_vhost
mod_ssi
mod_staticfile
mod_status
mod_trigger_b4_dl
mod_userdir
mod_usertrack
mod_webdav
disabled:
mod_cml
mod_magnet
mod_mysql_vhost

Features:

text
enabled:

auth-crypt

large-files

regex-conditionals

disabled:

auth-ldap

compress-bzip2

compress-deflate

compress-gzip

network-ipv6

network-openssl

stat-cache-fam

storage-gdbm

storage-memcache

webdav-locks

webdav-properties

If everything went well...we compile and install

CODE
text
 make && make install

We create a user and group without a shell for the execution of the service.

CODE
text
# useradd -G lighttpd -s /sbin/nologin -d /var/www/html lighttp
# groupadd lighttpd

We create the log structure:

BASH
Bash
mkdir /var/log/lighttpd

We changed the owner and the group.

BASH
Bash
 chown lighttpd:lighttpd /var/log/lighttpd

We create the folder where the configuration file will be hosted.

BASH
Bash
mkdir /etc/lighttpd

We copy the configuration files

CODE
Bash
 cp ./doc/config/lighthttpd.conf /etc/lighthttpd/
cp -rp doc/config/conf.d/ /etc/lighttpd/
cp ./doc/config/modules.conf /etc/lighttpd/
cp -rp ./doc/config/vhosts.d/ /etc/lighthttpd/

We fit the owner

Bash
chown lighttpd:root /etc/lighttpd/lighttpd.conf

We copy the script to start/stop the service in init.d

CODE
Bash
cp ./doc/initscripts/rc.lighttpd /etc/init.d/lighttpd

We give execution permissions.

BASH
Bash
chmod u+x /etc/init.d/lighttpd

We check if we can access the web server with the IP address of the machine, in my case: http://192.168.1.185


Finally we are going to compile PHP and configure FastCGI

We download PHP

BASH
Bash
wget http://es2.php.net/get/php-5.3.10.tar.gz

We decompress

CODE
Bash
tar xvf php-5.3.10.tar.gz

We access

text
cd cd php-5.3.10/

We install the necessary libraries.

CODE
Bash
apt-get install libmysqlclient15-dev libxml2-dev

We configure

CODE
text
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/bin/mysql --with-mysql --enable-ftp --disable-pdo --disable-ctype

We compile and install

CODE
text
make && make install

Finally, we add the following configuration to the file: lighttpd.conf

CODE
text
fastcgi.server = ( ".php" =>
                   ("localhost" =>
                     ("socket" => "/tmp/fcgi.socket",
                       "bin-path" => "/usr/local/php/bin/php-cgi"
                     )
                   )
                 )

We restart Lighttpd and we should now be able to view php pages from the web server:

CODE
text
# /etc/init.d/lighttpd restart

Installation completed!

Greetings, rokitoh!

Comments