[How to] Install silex with lighttpd in centos 6.4


Here is starting point before you start this tutorial :

And, here is the step :

  1. Download silex

    cd /var/www/ && wget http://silex.sensiolabs.org/get/silex_fat.zip && unzip silex_fat.zip
  2. Try it with PHP builtin web server

    check php version

    php --version
    PHP 5.4.23 (cli) (built: Dec 11 2013 06:48:07)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend

    Edit index.php file

    vim /var/www/silex/web/index.php
    require_once __DIR__.'/../vendor/autoload.php';
    $filename = __DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
    if (php_sapi_name() === 'cli-server' && is_file($filename)) {
        return false;
    $app = new Silex\Application();
    $app->get('/hello', function() {
        return 'Hello!';
  3. Start the server

    php -S localhost:8080 -t web web/index.php

    If you try this with server, try to change the localhost with your server ip

  4. Check the browser if it works

    curl localhost:8080/hello

    You should see the hello message

  5. Lighttpd Configuration with virtual host

    Enable modules.conf

    vim /etc/lighttpd/lighttpd.conf

    # uncomment on line 78
    include "modules.conf"

    Enable modules at modules.conf

    vim /etc/lighttpd/modules.conf

    # just uncomment which is necessary for you
    # mine is like this
    server.modules = (
    #  "mod_auth",
    #  "mod_evasive",
    #  "mod_redirect",
    #  "mod_setenv",
    #  "mod_usertrack",

    Enable VHost Modules at modules.conf

    vim /etc/lighttpd/modules.conf

    # uncomment simple_vhost.conf
    # at line 161
    ## mod_simple_vhost
    include "conf.d/simple_vhost.conf"

    Virtual hosts conf at simple_vhost.conf

    vim /etc/lighttpd/conf.d/simple_vhost.conf

    # Add this into end of your file
    $SERVER["socket"] == "" {
    #point this domain to the symfony web directory
    server.document-root = "/var/www/silex/web/"
    accesslog.filename   = "/var/www/silex/silex-access.log"
    #rewrite rules for silex
    url.rewrite-once = (
    "^(/[^\?]*)(\?.*)?" => "/index.php$1$2"

    If you do not want to use IP instead server name or domain, change $SERVER["socket"] to something like this $HTTP ["host"] == "silex.local"

    Change file and folder permission to lighttpd

    sudo chown -R lighttpd /var/www/silex/

    Restart Lighttpd server

    /etc/init.d/lighttpd restart
  6. Test it in browser or curl


    Selamat, now You learn how to install silex in lighttpd

  7. References

    1. Lighttpd Documentation
    2. Silex Documentation
    3. Nerdpress
    4. VPSLink
  8. Advertisements

One thought on “[How to] Install silex with lighttpd in centos 6.4

  1. Reblogged this on dimensiweb.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s