What is LLMP (Linux + Lighttpd + Mysql +Php)

3 11 2007

Nota untuk membina “webserver” LLMP

Langkah pertama;

# cd /usr/src/
# wget http://www.lighttpd.net/assets/2007/1/29/lighttpd-1.4.13.tar.gz
# tar -xvzf lighttpd-1.4.13.tar.gz
# cd lighttpd-1.4.13/
# ./configure –prefix=/usr/local/lighttpd –enable-fastcgi –with-openssl
# make
# make install
# mkdir /etc/lighttpd
# cp -fr doc/lighttpd.conf /etc/lighttpd/

dan….


# vi /etc/lighttpd/lighttpd.conf

Add the following configurations.
server.modules (
“mod_rewrite”,
“mod_auth”,
“mod_access”,
“mod_accesslog”
)

server.document-root = “/var/www/html/”
server.errorlog = “/var/log/lighttpd.error.log”
accesslog.filename = “/var/log/lighttpd.access.log”
server.port = 80
server.bind = “192.168.1.201”
server.pid-file = “/var/run/lighttpd.pid”
server.username = “lighttpd”
server.groupname = “lighttpd”

Here the ip “192.168.1.201” is my local ip ,so please change “server.bind” to your local ip and “server.port” to the port in which you wish to run lighty.
Now let us add a user to run lighty

# useradd lighthttpd
# groupadd lighthttpd

Now create the log files

# touch /var/log/lighttpd.error.log
# touch /var/log/lighttpd.access.log

Now change the ownerships

# chown lighthttpd.root /etc/lighttpd/lighttpd.conf
# chown -R lighttpd.lighttpd /var/www/html/
# chown lighttpd.lighttpd /var/log/lighttpd.error.log
# chown lighttpd.lighttpd /var/log/lighttpd.access.log

Now create our startup deamon script

# vi /etc/init.d/lighttpd

Add the following lines to this script

#!/bin/sh
# Source function library
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/lighttpd ]; then
. /etc/sysconfig/lighttpd
fi

if [ -z “$LIGHTTPD_CONF_PATH” ]; then
LIGHTTPD_CONF_PATH=”/etc/lighttpd/lighttpd.conf”
fi

prog=”lighttpd”
lighttpd=”/usr/local/lighttpd/sbin/lighttpd”
RETVAL=0
start() {
echo -n $”Starting $prog: ”
daemon $lighttpd -f $LIGHTTPD_CONF_PATH
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}

stop() {
echo -n $”Stopping $prog: ”
killproc $lighttpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}

reload() {
echo -n $”Reloading $prog: ”
killproc $lighttpd -HUP
RETVAL=$?
echo
return $RETVAL
}

case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $lighttpd
RETVAL=$?
;;
*)
echo $”Usage: $0 {start|stop|restart|condrestart|reload|status}”
RETVAL=1
esac

exit $RETVAL
###########################################

Now give execute permission to this daemon script

# chmod 755 /etc/init.d/lighttpd

Let us start our Lighty as follows,before that all webservers listening to the port(server.port) must be stopped

# /etc/init.d/lighttpd start

Our Lighty is started and let us check it is listening port 80( or port mentioned in server.port).

# netstat -pant |grep lighttpd

Now we can create a test html file in the document-root.

# vi /var/www/html/index.html

Add the following lines to index.html.

Lighttpd is running…… YAHOOOOOOOOOOOOOOOOO

Then call this file through the browser (with your Ip as configured in server.bind)as follows

http://192.168.1.201/

Note: If you use port other than 80 ,then you may need to mension that port in browser as http://192.168.1.201:port/
WOW lighty is working ..!!!
Let us add the following line to rc.local such that our server will be started during the boot time.

# echo “/etc/init.d/lighttpd start” >> /etc/rc.d/rc.local
The section ” 3.1 ” is for just a fun you can avoid this portion and continue with section ” 4 ”
The following steps ( in section 3.1 )will help you to install a self signed SSL certificate for your domain
3.1 Install open-ssl
Let us install an ssl for your domain as follows.

# mkdir /etc/lighttpd/ssl/yourdomain.com -p

# cd /etc/lighttpd/ssl/yourdomain.com

Now create SSl as follows. You need to provide information such as country name, your domain name etc.,

# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes

Let us give ownerships and permissions.

# chown lighttpd:lighttpd /etc/lighttpd/ssl -R

# chmod 0600 /etc/lighttpd/ssl/yourdomain.com

Now edit the lighty configuration to add ssl informations.

# pico /etc/lighttpd/lighttpd.conf

Add the following lines

$SERVER[“socket”] == “192.168.1.201:443” {

server.document-root = “/var/www/yourdomain.com”

ssl.engine = “enable”

ssl.pemfile = “/etc/lighttpd/ssl/yourdomain.com/server.pem”

}

Please test the configuration as follows

# /usr/local/lighttpd/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf

Now create a documet-dir and a test index.html file

#mkdir /var/www/yourdomain.com/

# cd /var/www/yourdomain.com/

# pico index.html

Add the follwing lines to this index.html file

Light is runing in ssl…

Now give the ownerships

# chown -R lighttpd:lighttpd /var/www/yourdomain.com/

Let us restart our lighty

# /etc/init.d/lighttpd restart

Let us check lighty is listening on ssl port as follows

# /etc/init.d/lighttpd restart

My server given the following out put

# netstat -pant |grep lighttpd

tcp 0 0 192.168.1.201:443 0.0.0.0:* LISTEN 27948/lighttpd
tcp 0 0 192.168.1.201:80 0.0.0.0:* LISTEN 27948/lighttpd

You can access your secure site as follows

Home

So we successfully completed our lighty installation ……
4. Install Mysql
Let us install mysql. We can install mysql in two ways ,
1. By using an rpm ,or
2.From the source tar ball
The preferable method is by using an rpm ,because the up-gradation procedures are simple. Guys,like me,(who love and like linux) will prefer source installations. Any way the following section will tell you both of the procedures.
4.1 Using RPM
The rpm installations are simple.You can do it through yum.

# yum install mysql-server

# yum install mysql

# yum install mysql-devel

# yum install mysql-bench

Now installation is completed let us start mysql sever as follows

# /etc/init.d/mysqld start

Let us get the mysql prompt as follows.

# mysql

So the mysql rpm installations are finished.
4.2 Using Source
You can install mysql from source as follows

# cd /usr/local/

# wget http://downloads.mysql.com/archives/mysql-4.1/mysql-debug-4.1.21-pc-linux-gnu-i686-glibc23.tar.gz

# groupadd mysql

# useradd -g mysql mysql

# tar -xvzf mysql-debug-4.1.21-pc-linux-gnu-i686-glibc23.tar.gz

# ln -s /usr/local/mysql-debug-4.1.21-pc-linux-gnu-i686-glibc23 /usr/local/mysql

# cd mysql

# scripts/mysql_install_db –user=mysql

# chown -R root .

# chown -R mysql data

# chgrp -R mysql .

Let us start mysql as follows,

# bin/mysqld_safe –user=mysql &

Now we can enter the mysql prompt as folows,

# mysql

Some time you may get an error as follws

Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

To resolve this issue we need to find the exact sock which is connected to mysql.

# netstat -ax |grep mysql

My server given the following result

unix 2 [ ACC ] STREAM LISTENING 3821 /tmp/mysql.sock

Here the sock file is ” /tmp/mysql.sock ” . But our mysqlserver is trying to connect through ” /var/lib/mysql/mysql.sock ” . To resolve this issue do the following operations.

# pkill -9 mysql

# rm -rf /var/lib/mysql/mysql.sock

# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

Now start mysql again and enter into mysql prompt as follows

# bin/mysqld_safe –user=mysql &

# mysql

So our Mysql installations are finished
5. Install Php
In this section we can install php as FastCGI.
First to download and untar the php source.

# wget http://us2.php.net/get/php-5.2.0.tar.gz/from/in.php.net/mirror

# tar -xvzf php-5.2.0.tar.gz

Let us install php as follows

# ./configure –prefix=/usr/local/php5/ –with-config-file-path=/usr/local/php5/etc \
–enable-force-cgi-redirect –enable-fastcgi \
–with-gd –with-jpeg-dir=/usr/local –with-zlib –with-openssl –with-mysql=/usr/include

# make
# make install
# cp php.ini-recommended /usr/local/php5/etc/php.ini

Now configure our lighty configuration as follows

# vi /etc/lighttpd/lighttpd.conf

Add the following lines to this conf file

fastcgi.server = ( “.php” =>

( “localhost” =>

( “socket” => “/tmp/php5-fcgi.socket”,

“bin-path” => “/usr/local/php5/bin/php”

)

)

)

server.modules = (
“mod_fastcgi”
)

Now create a phpinfo() file in the documet-root

# echo “” >>/var/www/html/phpinfo.php

Let us give ownership to this file.

# chown lighttpd.lighttpd /var/www/html/phpinfo.php

Let us restart our Lighty

# /etc/init.d/lighttpd restart

You can verify the php configurations from the browser as follws

http://192.168.1.201/phpinfo.php

Note: Sometimes the lighty will not start due to “/tmp/php5-fcgi.socket”. Because the ” /tmp” folder will not have proper permissions. So you can give the permissions as follows

# chmod 777 /tmp


Actions

Information

2 responses

7 04 2012
ubuntu web server

Someone essentially lend a hand to make critically articles I would state. That is the very first time I frequented your web page and thus far? I surprised with the research you made to make this actual put up incredible. Magnificent task!

30 06 2014
microsoft office 2013 crack

Thank you for sharing your info. I truly appreciate your efforts and I will be waiting for your further write ups thanks once again.

Leave a comment