How to install lighthttpd with PHP and MySQL support
Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. I will explain how to install lighthttpd in a server. First we can start installing mysql in the server.
Please wait while we retrieve data from server .............
{codecitation}yum install mysql mysql-server{/codecitation}
Start the mysql server as follows.
{codecitation}/etc/init.d/mysqld start{/codecitation}
For better security, you can create a password for mysql access as follows.
{codecitation}mysqladmin -u root password yourrootsqlpassword{/codecitation}
Now you can check mysql is running or not using the following command.
{codecitation}ps aux | grep mysql
netstat -plan | grep mysql{/codecitation}
Also make sure that you allow port 3306 in your iptables to make sure that firewall is not blocking mysql port.
{codecitation}iptables -I INPUT 1 -i lo -p tcp --dport mysql -j ACCEPT
iptables -I INPUT 2 -i lo -p udp --dport mysql -j ACCEPT{/codecitation}
Now we can install lighthttpd in the server. For that we can install rpmforge repos in the server. To
install rpmforge follow steps in the link given below.
{codecitation} http://wiki.centos.org/AdditionalResources/Repositories/RPMForge
yum install lighttpd{/codecitation}
Now start lighthttpd service as follows.
{codecitation}/etc/init.d/lighttpd start{/codecitation}
Now check whether lighthttpd is installed properly by taking the link in the browser as follows.
{codecitation}http://<ip address>{/codecitation}
Lighttpd's default document root is /srv/www/lighttpd and configuration file is /etc/lighttpd/lighttpd.conf.
Now we can install PHP in the server.
{codecitation}yum install lighttpd-fastcgi php-cli php-common {/codecitation}
If the rpms are not available you can get it from http://rpm.pbone.net/
Now we need to configure lighthttp and php.
First we open /etc/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:
{codecitation}vi /etc/php.ini
[...]
cgi.fix_pathinfo = 1{/codecitation}
Then we open /etc/lighttpd/lighttpd.conf and uncomment "mod_fastcgi", in the server.modules stanza:
{codecitation}vi /etc/lighttpd/lighttpd.conf
[...]
server.modules = (
# "mod_rewrite",
# "mod_redirect",
# "mod_alias",
"mod_access",
# "mod_cml",
# "mod_trigger_b4_dl",
# "mod_auth",
# "mod_status",
# "mod_setenv",
"mod_fastcgi",
# "mod_proxy",
# "mod_simple_vhost",
# "mod_evhost",
# "mod_userdir",
# "mod_cgi",
# "mod_compress",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_secdownload",
# "mod_rrdtool",
"mod_accesslog" )
[...]{/codecitation}
and then, further down the file, there's a fastcgi.server stanza which we uncomment as well:
{codecitation}[...]
#### fastcgi module
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
)
)
)
[...]{/codecitation}
Then we restart Lighttpd:
The document root of the default web site is/srv/www/lighttpd/ . We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
{codecitation}vi /srv/www/lighttpd/info.php
<?php
phpinfo();
?>{/codecitation}
Now we call that file in a browser (e.g. http://<ip>/info.php)
Now we can add mysql support.
{codecitation}yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc{/codecitation}
Now restart Lighttpd:
{codecitation}/etc/init.d/lighttpd restart{/codecitation}
If you need a free control panel, you can go for webmin. Here is how you can install webmin in the server.
{codecitation} wget http://nchc.dl.sourceforge.net/sourceforge/webadmin/webmin-1.441.tar.gz
tar -xvzf webmin-1.441.tar.gz
cd webmin-1.441
./setup.sh
{/codecitation}