Lighttpd Web server on CentOS /RHEL 7 / Ubuntu 15
lighttpd (pronounced "lighty") is an open-source web server optimized for speed-critical environments while remaining standards-compliant, secure and flexible.[citation needed] It was originally written by Jan Kneschke as a proof-of-concept of the c10k problem – how to handle 10,000 connections in parallel on one server, but has gained worldwide popularity
Installing Lighttpd
CentOS 7
As lighttpd is not available in the official repository of CentOS 7, we'll need to install epel additional repository to our system. and I have centos Instance so my tutorial is on centos
# yum install epel-release
Then, we'll gonna update our system and proceed towards the installation of lighttpd.
# yum update
# yum install lighttpd
Ubuntu 15.04
Lighttpd is available on the official repository of Ubuntu 15.04 so, we'll simply update our local repository index and then go for the installation of lighttpd using ubuntu command line.
# apt-get update
# apt-get install lighttpd
Installing from Source
If we wanna install lighttpd from the latest version of source code ie 1.4.39, we'll need to compile the source code and install it into our system. First of all, we'll need to install the dependencies required to compile it.
# cd /tmp/
# wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.39.tar.gz
After its downloaded, we'll need to extract it the tarball by running the following.
# tar -zxvf lighttpd-1.4.39.tar.gz
Then, we'll compile it by running the following commands.
# cd lighttpd-1.4.39
# ./configure
# make
Note: we are installing lighttpd with its standard configuration. If you wanna configure beyond the standard configuration and want to install more features like support for SSL, mod_rewrite, mod_redirect then you can configure.
Once, compiled completed, we'll install it in our system.
# make install
Configuring Lighttpd
If we need to configure our lighttpd web server further as our requirements, we can make changes to the default configuration file ie /etc/lighttpd/lighttpd.conf we'll need to run the following command for checking the conf file
# lighttpd -t -f /etc/lighttpd/lighttpd.conf
[root@hackthesec lighttpd]# lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK
[root@hackthesec lighttpd]#
On CentOS 7
we are running CentOS 7, we'll need to create a new directory for our webroot defined in our lighttpd's default configuration ie /src/www/htdocs/ .
# mkdir -p /srv/www/htdocs/
Then, we'll copy the default welcome page from /var/www/lighttpd/ directory to the above created directory.
# cp -r /var/www/lighttpd/* /srv/www/htdocs/
Starting and Enabling Services
Now, we'll gonna start our lighttpd server by executing the following systemctl command.
# systemctl start lighttpd
Now enable it to start automatically in every system boot.
# systemctl enable lighttpd
Allowing Firewall
To allow port 80 or http service, we'll need to run the following commands.
# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success
In my case i don't have any firewall on my centos server..Here is the screenshot bellow
Accessing Web Server
As we have allowed port 80 which is the default port of lighttpd, we should be able to access lighttpd's welcome page.Access the server through domain name or ip adress
example - http://lighttpd.hackthesec.co.in
example - http://lighttpd.hackthesec.co.in
Installing PHP5 Modules
Once our lighttpd is installed successfully, we'll need to install PHP and some PHP modules to run PHP5 scripts in our lighttpd web server.
On Ubuntu 15.04
# apt-get install php5 php5-cgi php5-fpm php5-mysql php5-curl php5-gd php5-intl php5-imagick php5-mcrypt php5-memcache php-pear
On CentOS 7
# yum install php php-cgi php-fpm php-mysql php-curl php-gd php-intl php-pecl-imagick php-mcrypt php-memcache php-pear lighttpd-fastcgi
Configuring Lighttpd with PHP
To make PHP work with lighttpd web server, we'll need to follow the following methods respect to the distribution we are running.
On CentOS 7
First of all, we'll need to edit our php configuration ie /etc/php.ini and uncomment a line cgi.fix_pathinfo=1 using a text editor.
# nano /etc/php.ini
After its done, we'll need to change the ownership of PHP-FPM process from apache to lightpd. To do so, we'll need to open the configuration file /etc/php-fpm.d/www.conf using a text editor.
# nano /etc/php-fpm.d/www.conf
Then, we'll append the file with the following configurations.
user = lighttpd
group = lighttpd
Once done, we'll need to save the file and exit the text editor. Then, we'll need to include fastcgi module from /etc/lighttpd/modules.conf configuration file.
# nano /etc/lighttpd/modules.conf
Then, we'll need to uncomment the following line by removing # from it.
include "conf.d/fastcgi.conf"
At last, we'll need to configure our fastcgi configuration file using our favorite text editor.
# nano /etc/lighttpd/conf.d/fastcgi.conf
Then, we'll need to add the following lines at the end of the file.
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)
After its done, we'll save the file and exit the text editor.
On Ubuntu 15.04
To enable fastcgi with lighttpd web server, we'll simply need to execute the following commands.
# lighttpd-enable-mod fastcgi
Enabling fastcgi: ok
Run /etc/init.d/lighttpd force-reload to enable changes
# lighttpd-enable-mod fastcgi-php
Enabling fastcgi-php: ok
Run /etc/init.d/lighttpd force-reload to enable changes
Then, we'll reload our lighttpd by running the following command.
# systemctl force-reload lighttpd
Testing if PHP is working
In order to see if PHP is working as expected or not, we'll need to create a new php file under the webroot of our lighttpd web server. Here, in this tutorial we have /var/www/html in Ubuntu and /srv/www/htdocs in CentOS as the default webroot so, we'll create a info.php file under it using a text editor.
On CentOS 7
# nano /var/www/info.php
On Ubuntu 15.04
# nano /srv/www/htdocs/info.php
Then, we'll simply add the following line into the file.
<?php phpinfo(); ?>
Once done, we'll simply save the file and exit from the text editor.
Now, we'll open our running lighttpd using its ip address or domain name with the info.php file path as http://lighttpd.hackthesec.co.in/info.php. after that you can see the phpinfo page
www.twitter.com/hackthesecurity
0 comments:
Post a Comment