Installing Symfony 2.0 Framework in Ubuntu

Symfony is PHP MVC framework used to create websites and web application.
There are certain things you need to do first because you can run a Symfony website
This guide provides a step by step instructions on setting up Symfony in your localhost.


1. Prepare the requirements. Follow the link of the ff softwares and packages to download:

Symfony 2.0 with vendors ( preferrably v2.0.17 since this guide was based on that. )
Propel ORM
Phing
Propel Bundle

2. Extract each packages in its rightful location

Symfony       -> your web root
Propel ORM    -> Symfony/vendor
Phing         -> Symfony/vendor
Propel Bundle -> Symfony/vendor/bundles/Propel 

3. Register the Propel Bundle in app/AppKernel.php and app/autoload.php

# add this code in app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Propel\PropelBundle\PropelBundle(),
    );
    // ...
}

# add this code in app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'Propel' => __DIR__.'/../vendor/bundles',
));

# add this code in app/autoload.php
$loader->registerPrefixes(array(
    // ...
    'Phing' => __DIR__.'/../vendor/phing/classes/phing',
));

4. Set the path for Propel and Ping in app/config/config.yml

propel:
  path:        "%kernel.root_dir%/../vendor/propel"
  phing_path:  "%kernel.root_dir%/../vendor/phing"

5. If you're gonna use a database. Set the connection details in app/config/config*.yml

propel:
  dbal:
    driver:     mysql
    user:       root
    password:   null
    dsn:        mysql:host=localhost;dbname=test;charset=UTF8
    options:    {}
    attributes: {}

6. Remove the default bundle Acme

// remove this line in app/AppKernel.php
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();

Go to app/config/routing_dev.yml and remove all entries related to Acme Bundle
Finally, delete the src/Acme directory

CONFIGURE SYMFONY 2

Go to http://localhost/Symfony/web/config.php

1. Install and enable the following php modules

SQlite 
PDO_SQlite, 
PHP Accelerator
intl Extension

By running these commands in the terminal:

sudo apt-get install php5-sqlite
sudo apt-get install php-apc
sudo apt-get install php5-intl
sudo service apache2 reload

2. Set short_open_tag to off and date.timezone to your timezone in /etc/php5/apache2/php.ini.

3. Change the permissions of the app/cache/ and app/logs/ to rewritable

sudo chmod -R 777 app/cache app/logs

STARTING YOUR SYMFONY 2 PROJECT

1. Create a bundle on your terminal, make sure you’re in the Symfony directory

php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml

2. Erase everything at app/config/routing.yml and replace with:

BloggerBlogBundle:
  resource: "@BloggerBlogBundle/Resources/config/routing.yml"
  prefix: /

3. Create your database in PHPMyAdmin of whichever MySQL client you used, then generate your schema on terminal by typing the ff command:

php app/console propel:reverse

reverse means everything in your database will be converted to xml.


4. Copy the scheme to src/Blogger/BlogBundle/Resources/config/schema.xml

Open your schema.xml then on the <database> tag type your namespace:

<database name="default" namespace="Blogger\BlogBundle\Model" defaultIdMethod="native">

Then on terminal run the command:

php app/console propel:build-model

This command will generate a model for each of the tables in your database.

Comments

  1. Hi Hana.
    I try to configurate Propel with Symfony, but I have this trouble

    InvalidConfigurationException: Unrecognized options "dbal" under "propel"

    This issue is about the moment of Processor.php try to load the configuration
    of app/config/.config.yml
    propel:
    dbal:
    driver: mysql
    user: root
    password: root
    dsn: mysql:host=localhost;dbname=mydb;charset=UTF8

    Some idea about this trouble?
    Thanks

    ReplyDelete
  2. Hi Hana
    Finally works!
    Issues with versions!

    ReplyDelete

Post a Comment