I finally decided to upgrade from symfony 1.4 to Symfony 2.
As I started migrating I figured that Symfony 2 is very different from symfony 1.4.
Since I’m probably not the only one migrating to Symfony 2, I’m going to share my migration experiences with you in this blogpost.
This is going to be a living post which means that I update it as soon as I think there is anything valueable to share.
Please feel free to post any feedback or suggestions in the comments.
A lot of stuff is already covered in the Symfony 2 book.
I suggest to read at least the first few chapters before starting to migrate.
I’m going to assume that you have an Apache webserver running and you are putting stuff in a directory called my_project in your webservers document root.
Installation
Everything (and even more) in this chapter is already covered in the Symfony 2 book. This is just the way I installed Symfony 2 which worked fine for me. Installing Symfony 2 is really easy (thanks to composer). Get the latest copy of composer and install the Symfony 2 framework standard edition:
1
| |
This will install Symfony 2.1.2 (which is the current stable version at the writing of this post) including all its dependencies. You don’t have to worry too much about the version as you can update this later easily. After the installation completed, setup write permissions for the webserver to the cache and log directories.
1 2 | |
That’s it, you can check your installation by visiting the two preconfigured application controllers in your browser:
1 2 | |
Oh wait, the last one should throw a 404-error. That’s okay, because this is the controller for the production environment and no routes have been setup for production yet.
As in symfony 1.4 there is a console application for easy access to useful commands.
In Symfony 2 it’s located at ./app/console.
You should make this executable so you can use it from the command line:
1
| |
Symfony 2 comes with a demo project (called Acme) pre installed. You can delete it to start off with a clean setup. Delete the following files and directories:
1 2 | |
Then unregister the Acme demo bundle from the application kernel (more on this later) by removing the line
1
| |
from app/AppKernel.php
Then remove the following routes from the development environment routing configuration in app/config/routing_dev.yml: _Welcome, _demo_secured, _demo.
Great, so if you now visit the development frontend controller
1
| |
Symfony should throw a 404 (NotFoundHttpException) because there are no configured routes. Now we have a clean setup and you can start migrating your project.
It’s time for your inital commit (assuming that you’re using git to version control this project).
1 2 3 | |
There is already a .gitignore file included so no further steps are necessary to exclude any directories.
A few words on Composer
You should make yourself familiar with Composer as it makes dependency management in your project a lot easier. I just want to mention a few tasks you are probably going to use more or less regularly.
The vendor directory of your project is used by composer to install all packages your project depends on.
Go check it out.
You will see that the Symfony framework itself is just a composer package.
Depedencies are defined in composer.json in the root directory of your project.
You can add packages from Packagist in this file and have composer install them by running
1
| |
from your project root.
Composer will then get the matching versions of each package and install them in the vendor directory.
This will also update all other packages defined in composer.json.
Composer will save the current package setup in composer.lock.
This is important for deployment.
Installed packages are not included in the git repository (but the composer.lock file is).
When deploying your project, you check out the repository on the production system and run
1
| |
to tell composer to install the packages defined in composer.lock.
You end up with the same package setup as the development system.
Great, this is exactly what we want.
Please note that this is just a minimal overview. You probably have more deployment stages between development and production and a more complex deployment process going on. However, you just need to customize the above to your needs.
Next up:
(Not necessarily in this order)
- Bundling
- Layout and Tempate organization
- Assets
- Translations
- Static partials
- Controller partials
- Using databases
- Using models
- Backend for CRUD-operations
- Fixtures
- Forms
- File uploads
- …