Nerds who love the symfony-project
10 Oct
So where we are currently working, we have a back catalogue of Symfony 1.0 applications, and are beginning to roll out a few Symfony 1.1 apps to production, as well as a few other things floating around on other versions. As helpful as the compatability plugin is, it can’t magically make any 1.0 app run under 1.1, and we made the decision that we just couldn’t afford the time to re-write… So what’s the best way of running multiple versions of Symfony apps together on the one environment?
The first thing we thought of was just using PEAR to install multiple version in different directoris, but unfortunately it cannot handle installing more than one version, so that’s out.
You could grab a Symfony sandbox for each application, and if you only had one or two 1.0 apps this is probabaly quite a valid option, but if you have a few more, your code-base would get very large, very quickly, and you miss out on the benefit of re-using components across your apps from one location.
So what did we actually do? In the end, we installed multiple versions of Symfony via SVN, allowing the environment to operate much as anyone who installed Symfony with PEAR would be familiar with, allowing each Symfony application to reference the global Symfony install and libraries etc. The example below document how this was set up in Ubuntu (our favoured development VM), but shouldn’t be too different form other Unix environments.
Step 1 - Un-install Symfony via PEAR
If you have Symfony installed via PEAR, get rid of it, it will only confuse you with what we are about to do.
express@express-dev:~$ sudo pear uninstall symfony/symfony
uninstall ok: channel://pear.symfony-project.com/symfony-1.1.0
Step 2 - Setup a structure for Symfony
In our case, I still want to install symfony in /usr/share/php/symfony, so lets set that up:
express@express-dev:~$ cd /usr/share/php
express@express-dev:/usr/share/php$ sudo mkdir symfony
Step 3 - Checkout each Symfony version you need
Now lets use SVN checkout to grab each Symfony version we are after, lets put these in a different folder under the base Symfony directory. Note: If you are behind a proxy, change your SVN settings first to go through your proxy. To change your proxy settings:
express@express-dev:/usr/share/php/symfony$ sudo nano /etc/subversion/servers
Now lets checkout each symfony version:
express@express-dev:/usr/share/php$ cd symfony/
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.0 symfony10
...
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.1 symfony11
...
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.2 symfony12
...
We now have created three installations of Symfony.
Step 4 - Create symbolic links for each version
The next step is for us to create symlinks for each version of Symfony. Lets place these in the standard bin directory:
sudo ln -s /usr/share/php/symfony/symfony10/data/bin/symfony /usr/bin/symfony10
sudo ln -s /usr/share/php/symfony/symfony11/data/bin/symfony /usr/bin/symfony11
sudo ln -s /usr/share/php/symfony/symfony12/data/bin/symfony /usr/bin/symfony12
Now lets test the sym links:
express@express-dev:~$ symfony10 -V
symfony version 1.0.19-PRE
express@express-dev:~$ symfony11 -V
symfony version 1.1.5-DEV (/usr/share/php/symfony/symfony11/lib)
express@express-dev:~$ symfony12 -V
symfony version 1.2.0-DEV (/usr/share/php/symfony/symfony12/lib)
What next? - Creating a new project
So to create a new project, you will need to use the relevant Symfony command. For example, to create a Symfony 1.0 project:
sudo symfony10 init-project test1
or to create a Symfony 1.1 or Symfony 1.2 Project:
sudo symfony11 generate:project test11
sudo symfony12 generate:project test12
Once you create a new project, check in the project Config to ensure its picked up the right version. For Symfony 1.0:
express@express-dev:/usr/local/express/projects/$ sudo symfony10 init-project test10
express@express-dev:/usr/local/express/projects/$ cat config/config.php
// symfony directories $sf_symfony_lib_dir = '/usr/share/php/symfony/symfony10/lib'; $sf_symfony_data_dir = '/usr/share/php/symfony/symfony10/data';
for Symfony 1.1:
express@express-dev:/usr/local/express/projects/test$ cat config/ProjectConfiguration.class.php
require_once '/usr/share/php/symfony/symfony11/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); class ProjectConfiguration extends sfProjectConfiguration { public function setup() { } }
and for Symfony 1.2, its the same, just make sure its including the right 1.2 files. Thats it! Hope this helps!
19 Responses for "Your complete guide to running multiple Symfony versions on the same environment"
[...] Your complete guide to running multiple Symfony versions on the same environment [...]
Very helpful - we’re in the same boat, and as a tiny agency, we don’t have the man-hours to re-write huge chunks of code.
Thanks for the tip
This is an interesting approach but I’ve found that it makes more sense to include the symfony libraries under lib/vendor as you would any external library. This has several benefits:
1. Your app is portable since it’s self-contained
2. Each project has their own specific version of symfony (good since even point releases can adversely affect different sites if they’re all upgraded at the same time by using one global symfony install for each symfony version)
3. You can simply use “./symfony” from within your app and it’ll use the right version of symfony (since you’ll set up your configuration files to use a relative path to ‘../lib/vendor/symfony’)
4. You can use “svn:externals” on lib/vendor/symfony to link the symfony libraries to a specific version and always stay up to date
There’s more info here: http://blog.mirthlab.com/2007/12/15/setting-up-a-symfony-project-on-media-temples-grid-service-part-1/
… under “setting up symfony”
And here: http://spindrop.us/2007/04/17/tips-for-symfony-and-subversion/
This is the same sort of approach that Fabien said he uses. Hope that helps.
Hi there!
I have a problem and maybe you guys could help me to resolve it…
if i have this function:
public function executeSleep()
{
sleep(10);
}
and if i run this function, i can’t run another function in the same project untill this 10 seconds finish…
Obviously, I don’t need a sleep(10) in my code, but I have some long process in one of my functions…
I Hope you can help me… thank you veeery much!
@Gustavo,
Your problem is PHP is not inertly multi-threaded. If you were using something like Java - you could make executeSleep() as part of one thread, and the rest of your code in another thread.
There are lots of hacks out there on the web to make your PHP (Just google PHP Threads - I’m sure you will find something out there).
Sherif
[...] http://symfonynerds.com/blog/?p=123 [...]
[...] been using this trick from symfonynerds to run multiple Symfony versions in the same environments. I can now work on projects built on Symfony 1.0, 1.1, and 1.2 simultaneously in the same [...]
There is so smazing for us! Thanks!
thanks man… this helped me a lot
GREAT! Thank you very much! That’s exactly what I was looking for!
Thanks, that was really helpful I was on the same boat here.
Is there any way of doing this but with the stable versions of symfony?
thanks, it was all i needed!
If developing on Windows, think this is a lil harder since Windows doesn’t do symlinks…
3rd party program Junction.exe can only do symlinks for folders.
i think I would put each version folder into a symfony folder outside of project folder (aka c:/dev/libs/symfony/symfony10, c:/dev/libs/symfony/symfony12), rename each symfony.bat to symfont10.bat, and put each version folder in the path. then use as you need with ’symfony10 generate:app project1′ and it probably? works out (still have to test and wondering if thats most efficient way to do it?).
Gonna try this setup now… currently i have just 1 project and i junction-symlinked c:/dev/symfony-sites/site1/lib/vendor/symfony/lib to C:\dev\php\PEAR\symfony, but that will stink once i get more projects going and different versions of symfony.
Just wanted to add, seemed like it worked:
I’ll add that in projectconfiguration.class.php, you must point for each project to absolute path of where autoload class now is …
aka require_once ‘C:\\dev\\libs\\symfony\\symfony12\\lib\\autoload\\sfCoreAutoload.class.php’;
or setup a junction symlink for each project, aka:
C:\> junction c:/dev/symfony-sites/site1/lib/vendor/symfony C:\dev\libs\symfony\symfony12
@Luis to select specific sub-versions (which you may run more than one of, especially on a DEV machine) you follow the same steps but select your release from http://svn.symfony-project.com/tags/ rather than http://svn.symfony-project.com/branches/
eg:
sudo svn co http://svn.symfony-project.com/tags/RELEASE_1_2_9/ symfony129[...] Se você quer resolver esse problema no Linux, siga esse tutorial [...]
[...] Fonte original: http://symfonynerds.com/blog/?p=123 [...]
multiple Symfony for thanx.
Leave a reply