• Installing lighttpd 1.4.22 as static file server running by proxy with Apache 2.2.3

    Posted on March 21st, 2009 admin No comments

    In this tutorial i will show how i have installed my lighttpd to run side by side with my Apache installation.

    First of all let me introduce both, Apache i suppose that everyone nows, its one of the most stable, secure and used web server on the market. Lighttpd is growing, lighttpd is getting famous by the his speed, if look for benchmarks in google you will see that . What a lot of webmasters are doing now is let Apache run the script part, the complicated part, and configuring lighttpd as a static file server, a server for .js, .gif, .jpg, .css this type of files, www.gwebtools.com is running this way the website speed had increased a lot.

    I am running on CentOS

    Installing and configuring lighttpd

    1. wget http://www.lighttpd.net/download/lighttpd-1.4.22.tar.gz
    2. gunzip lighttpd-1.4.22.tar.gz
    3. tar -xvf lighttpd-1.4.22.tar
    4. Inside the lighttpd folder run ./configure maybe you get some dependencies errors so you will need to download it with yum install “dependencie-lib”
    5. make all && make install
    6. if you get no errors still here, type the command lighttpd and you will get some message like this 2009-03-21 09:33:34: (server.c.552) No configuration available. Try using -f option.
    7. Now its time to create your lighttpd.conf file, type mkdir /etc/lighttpd, after that inside your lighttpd folder type cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
    8. Ok, now you have a default conf file, you just need to change the default port of the lighttpd web server.
    9. Set server.port = 81, this is necessary because apache already runs on port 80, see the log path to see if they are right for your *nix distribution
    10. Set server.document-root = “Your www folder”, in my case /var/www/vhosts/gwebtools.com/httpdocs
    11. Now start the lighttpd server running lighttpd -f /etc/lighttpd/lighttpd.conf

    Configuring apache to run on proxy mod

    1. Enable mod proxy on httpd.conf,
      LoadModule proxy_module modules/mod_proxy.so
      LoadModule proxy_http_module modules/mod_proxy_http.so
      LoadModule proxy_connect_module modules/mod_proxy_connect.so
    2. In your virtual host config you need to edit conforming your needs, for this blog.gwebtools.com that is running with wordpress i do the following
      ProxyRequests Off
      ProxyPreserveHost On
      ProxyPass /wp-content
      ProxyPass /wp-includes
      ProxyPassReverse /
    3. Now every request to static files, js, images from my blog, lighttpd will be the server how will attend to the request.
    4. Now everything is running fine and faster.

    Creating a script file to manage lighttpd process

    # Author: Nathaniel Brown
    # Date: December 16, 2005
    # URL: http://nshb.net/lighttpd-restart-script.html
    # Version: 1.0
    # License: MIT
    #Binary Paths
    # Modifiy this line for each install
    if [ -e $PIDFILE ]; then
        PID=`$CAT $PIDFILE`
        if [ "x" == "x$PID" ]; then
    case "$1" in
            if [ 0 -ne $PID ]; then
                running=`$PS --pid $PID | grep $PID`
                if [ $running ]; then
                    echo "lighttpd is already running"
                    exit 1
                rm $PIDFILE
            $HTTPD -f $LIGHTTPD_CONF
            if [ 0 -eq $PID ]; then
                echo "lighttpd was not running"
                exit 1
            kill $PID
            while [ -e $PIDFILE ]; do
                if [ "x$tries" == "x.........." ]; then
                sleep 2
            if [ -e $PIDFILE ]; then
                echo "lighttpd did not go gentle into that good night, murdering"
                kill -9 $PID
                rm $PIDFILE
            $0 stop
            $0 start
            if [ 0 -eq $PID ]; then
                echo "lighttpd was not running"
            kill -HUP $PID
           if [ 0 -eq $PID ]; then
                echo "lighttpd is not running"
           if [ 0 -ne $PID ]; then
                echo "lighttpd (pid $PID) is running..."
            echo "Usage: "`basename $0`" (start|stop|restart|reload|status)"
            exit 1

  • Installing PHP XCache in 11 Steps

    Posted on March 5th, 2009 admin No comments

    XCache is a a cache system for php scripts, it will increase a lot your php pages load speed. (Official Web Site)

    In this post i will not discuss about how it works and what it does, i just tell you guys how to install it in few steps.

    1º – download the last stable version http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
    2º – tar -xvf xcache-1.2.2.tar.gz
    3º – cd xcache-1.2.2
    4º – phpize
    5º – ./configure –enable-xcache
    6º – make
    7º – make install
    8º – cp xcache.ini /etc/php.d
    9º – vim /etc/php.d/xcache.ini
    10º – uncomment and set xcache.size = 64M
    11º – restart apache and its done!

    Obs.: Sometimes you will need to install php-devel packages if they are not currently installed on your system. (yum install php-devel)

  • Apache .htaccess – Subdomain redirect rules

    Posted on February 26th, 2009 admin No comments

    In the begin of my website i have had a lot of problems to find a good working .htaccess configuration file. I need some redirect rules from specific folders from a subdomain to redirect to specific folder in other subdomain, passing parameters.

    I need this type of redirect because my website is multilangue, so i dont want folders on portuguese associated with the english subdomain by example.

    This code was really hard to get working, but here it is for you guys, hope it be useful.

    — part of the .htacces file of gwebtools.com —

    <IfModule mod_rewrite.c>
    RewriteEngine On

    #redirect gwebtools.com to www.gwebtools.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www..*
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
    RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]

    #if subdomain pt or whois and folder port-scanner redirect to pt.gwebtools.com/scanner-porta, with parameters
    RewriteCond %{HTTP_HOST} ^(pt|whois)\.gwebtools\.com
    RewriteRule ^port-scanner/* http://pt.gwebtools.com/scanner-porta$1 [R=301,L]


    The above code is running on this site www.gwebtools.com!