Installing Symfony 2 by creating a github fork

The Symfony 2 standard project suggests that you install it in one of two ways:

However, as I’m a developer, I’m used to using github, and I don’t need the code-base to be particularly stable at the moment - I chose a third option:

The danger of forking the actual repository is that it might not be stable. There could be unfixed bugs that aren’t in the official releases. The advantage is that it’s particularly easy to pull in new changes from the Symfony repository.

The environment

I’m doing all this on Ubuntu Raring Ringtail (13.04). This post will almost certainly work in a similar way for any modern debian-based OS, but it will be fairly useless for yum-based OSes, and completely useless for Windows.

Install packages

Before we start, you’ll need a github account, and you’ll need to install git, MySQL, php5-cli, php5-dev, php5-mysql, php5-intl and php-apc on your local computer:

# Install packages
$ sudo apt-get install git php5-cli php5-dev mysql-server php5-mysql php5-intl php-apc

Configuration tweaks

We must make sure that date.timezone is set to a valid timezone. Symfony recommends that we set short_open_tag to Off, so we might as well change that at the same time:

; /etc/php5/cli/php.ini

; around line 213
; change the value to "off"
short_open_tag = Off

; around line 876
; uncomment and change value
date.timezone = Europe/London

Symfony also recommends that we set XDebug to allow a high nesting level:

# Add to PHP configuration      
$ echo "xdebug.max_nesting_level=250" | sudo tee -a /etc/php5/mods-available/xdebug.ini

And that MySQL is set to UTF-8 by default:

; /etc/mysql/my.cnf

; around line 30
; add these new keys
collation-server = utf8_general_ci
character-set-server = utf8

Fork the repository

Forking a github repository is as easy as navigating to the repository page and clicking the “fork” button. Note down the URL for your repository and clone it and change to the directory, e.g.:

$ git clone [email protected]:<yourusername>/symfony-standard.git
$ cd symfony-standard

Install dependencies and configure

Now you’ll need composer to install dependencies:

$ curl -sS | php
$ php composer.phar install

When it prompts you for input, you’ll probably want to leave most things as default (blank), except the database password for root user if you set one:

Some parameters are missing. Please provide them.
database_driver (pdo_mysql):
database_host (
database_port (null):
database_name (symfony):
database_user (root):
database_password (null):<yourRootDbPassword>
mailer_transport (smtp):
mailer_host (
mailer_user (null):
mailer_password (null):
locale (en):en-gb
secret (ThisTokenIsNotSoSecretChangeIt):somesecretkeyorother

Now you can commit your composer.lock into your repository fork to make sure your dependency versions stay reliable:

$ git add composer.lock
$ git commit -m 'Add composer.lock: dependency versions'

Check everything works

Now hopefully if you run the check, you’ll see a long list of “OK”s:

$ php ./app/check.php
*                              *
*  Symfony requirements check  *
*                              *
 OK       PHP version must be at least 5.3.3 (5.4.9-4ubuntu2 installed)
 OK       PHP version must not be 5.3.16 as Symfony won't work properly with it
 OK       Vendor libraries must be installed
... etc

If you get errors you must fix them. If you get warnings feel free to ignore them.

Create the database

You can now, if you want, use Doctrine to create the database:

php app/console doctrine:database:create

Run the PHP server

If the PHP version listed in the output of check.php is at least 5.4 (see above, mine is 5.4.9-4ubuntu2) then you can run the PHP server. You can update to 5.4 if you don’t have it already.

$ php ./app/console server:run

And then browse to localhost:8000.

By @nottrobin