[How to] Install silex with Apache in centos 6.4

Apache-Logo

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
    
    <?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!';
    });
    
    $app->run();
    
  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. Apache Configuration with virtual host

    Check httpd.conf

    Make sure httpd.conf accept all setting (uncomment) in /etc/httpd/conf.d.

    Create vhost file

    vim /etc/httpd/conf.d/vhost.conf

    Listen 8090
    <VirtualHost *:8090>
      DocumentRoot "/var/www/silex/web"
      #ServerName silex
      <Directory "/var/www/silex/web">
        AllowOverride All
      </Directory>
    </VirtualHost>
    

    Create .htaccess

    vim /var/www/silex/web/.htaccess

    <IfModule mod_rewrite.c>
        Options -MultiViews
    
        RewriteEngine On
        #RewriteBase /path/to/app
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]
    </IfModule>
    

    Restart Apache Server

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

    curl http://127.0.0.1:8090/hello
    

    Selamat, now You learn how to install silex in Apache

  7. References

    1. Silex Documentation
    2. mathiasnoback
Advertisements

2 thoughts on “[How to] Install silex with Apache in centos 6.4

  1. This tutorial doesn’t work at all in Centos 6.5

    Also.. this is pretty vague, and probably wrong.
    “Make sure httpd.conf accept all setting (uncomment) in /etc/httpd/conf.d.”

    I’m assuming you mean to uncomment the override order and set it to ” accept all ”
    On stock install this is in httpd.conf within /etc/httpd/conf/ folder.. not the conf.d folder

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