How To Build Working CentOS Server with LightTPD and PHP5 (Part 1)
| |How to install LightTPD, PHP5 and MySQL on CentOS server. In this guide I will use newest release version, CentOS 6.4 running on my droplet hosted in DigitalOcean’s network. For your information, CentOS 6.4 has been released back in 2013-03-09. Lighttpd is a free asynchronous web server with fast and sleek performance. It is much more faster than Apache. Shortly, it is similar to Nginx and Lighttpd is also the best rival to Nginx.
About Lighttpd (shortly)
lighttpd (pronounced “lighty”)[ is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible. 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 (WikiPedia).
Most Web 2.0 websites are using Lighty to serve millions users a day, including WikiPedia and YouTube (before acquired by Google).
This tutorial is provided as it as. I write it purely for educational and learning purpose. I don’t recommend you to use Lighttpd on production server if you don’t know more about it. Again, my purpose writing this tutorial is to guide you how to install Lighttpd on CentOS so you can know it, learn it so you will be able to learn more about it (if you want).
Honestly, personally, I still prefer Nginx than Lighttpd. Anyway, read on..
Prerequisite
- A working CentOS server. In this guide I am using CentOS 6.4 x86.
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
- About 15 minutes of your time and a cup of coffee if you like.
How to install Lighttpd on CentOS
Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.
Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch login as root.
You may also need to type this command to go to the root directory:
cd ~
Step 2 – You have to firstly enable the Remi RPM repository plus the EPEL repository because Lighttpd and PHP-FPM are not available from the official CentOS repositories. In this case simply issue following commands:
rpm --import https://fedoraproject.org/static/0608B895.txt wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm
It will look like this:
There are other commands you have to issue:
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
It looks like this at my end:
Finally, execute this command syntax:
yum install yum-priorities
You it asks you to confirm, simply answer yes or type Y then hit Enter. You’ll get the “Complete!” message indicating the process to add new repo is success.
Step 3 – You have to also edit /etc/yum.repos.d/epel.repo file. Use Nano for that:
nano /etc/yum.repos.d/epel.repo
In the top part of the screen you’ll see the [epel] section. Add priority=10 line in it. See the screenshot below:
Once done, hit Control+O to save then Control+X to exit.
Step 4 – You have to also edit /etc/yum.repos.d/remi.repo file. Use Nano for that:
nano /etc/yum.repos.d/remi.repo
In the top part of the screen you’ll see the [remi] section. Add priority=10 line in it and change enabled to 1. See the screenshot below:
Hit Control+O to save it then Control+X to exit.
Step 5 – It’s time to install Lighttpd. The command syntax is simple:
yum install lighttpd
Hit Y if asked.
Step 6 – Optional but recommended: Add system startup links for Lighttpd service so it starts automatically whenever the system boots. Use this command:
chkconfig --levels 235 lighttpd on
Step 7 – In this point you can now start Lightpd service:
/etc/init.d/lighttpd start
or
service lighttpd start
Note: The service may start with following error:
(network.c260) warning: please use server. use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes.
or,..
(network.c.203) socket failed: Address family not supported by protocol
You can fix by by editing lighttpd.conf file:
nano /etc/lighttpd/lighttpd.conf
Find the Basic Configuration section and find server.use-ipv6, change its value to “disable”.
Save it and exit.
Note 2: You may also get following error:
(server.c.915) can't have more connections than fds/2: 1024 1024
You can fix it, again, by editing lighttpd.conf file:
nano /etc/lighttpd/lighttpd.conf
Find the line that says “#server.max-fds = 2048“. Found it? Now remove the # symbol (uncomment it):
Save it and exit. Now you should not see any error again:
Test it in your browser by typing your server’s IP and you should see this:
Next, installing PHP5-fpm and MySQL on your CentOS server with Lighttpd already installed and running on it. I’ll write about it ASAP as Part 2 of this tutorial.
Index of this guide: Part 1 – Part 2 – Part 3 – Part 4.
Lighttpd is as light as nginx on resource usage. very good server software!
Agree 😀
just trying to find another way to install lighthttpd .
sorry please ignore my last comment 😉
Hi mom
Centos 6 installation on my vps installs default with apache 2, i removed apache using
yum erase httpd httpd-tools apr apr-util
the i used the exact same method to install lighttpd but instead of serving pages lighttpd is giving me 404 error pages, i tried searching every where but couldnt find any solution, please help
thanks