Inheritance with symfony and Doctrine ORM: Project Setup

This post goes along with another post, Inheritance with symfony and Doctrine ORM. If you’ve found yourself here, you might want to start there.

First, set up the symfony project:

$ mkdir inheritance
$ cd inheritance/
$ mkdir -p lib/vendor
$ cd lib/vendor/
$ wget http://www.symfony-project.org/get/symfony-1.4.1.zip
$ mv symfony-1.4.1 symfony
$ rm symfony
$ rm symfony-1.4.1.zip
$ cd ../../
$ php lib/vendor/symfony/data/bin/symfony -V
symfony version 1.4.1 (/var/www/inheritance/lib/vendor/symfony/lib)

$ php lib/vendor/symfony/data/bin/symfony generate:project INHERITANCE

Then create the database:

mysql> create database inheritance;
Query OK, 1 row affected (0.06 sec)

Following the principle of least privilege, create a user that only has access to the inheritance database and nothing else:

mysql> create user 'inheritance'@'localhost' identified by 'pass123';
Query OK, 0 rows affected (0.24 sec)

mysql> grant all on inheritance.* to 'inheritance'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Now tell symfony about the database:

$ php symfony configure:database "mysql:host=localhost;dbname=inheritance" inheritance pass123

And create the frontend app:

$ symfony generate:app frontend
$ chmod 777 cache/ log/

In order for your stylesheets to work, you’ll have to add a directive to your Apache config file similar to the following. My project lives in /var/www/inheritance; yours might be different. (Don’t forget to restart Apache after you add this.)

Alias /inheritance/web/sf /var/www/inheritance/lib/vendor/symfony/data/web/sf

Lastly, you might need to modify web/frontend_dev.php. My dev server is not the same machine that I use to look at what I’m developing, so I can’t restrict access to 127.0.0.1. For this temporary little project, it’s safe enough for me just to allow access from anywhere.

// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
/*
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
sfContext::createInstance($configuration)->dispatch();

That’s all.

Leave a Reply