A popular forum question from symfony beginners is how to install the software on a server that hosts a number of symfony projects. The original core team advice, dating back to before the 1.0 version, was to install via PEAR. However, anyone who has fought with PEAR in a Microsoft corporate network environment knows that proxying out to the internet can be a royal pain; in any case, as far as I know, using PEAR also limits the machine to one concurrent version of symfony. For new symfony users, and especially for PHP beginners, I recommend a simple, alternative approach.
Let us presume that your hosting folder is /var/www, and that each Apache virtual host points to a folder in the form /var/www/projectname (these are, of course, *nix pathnames, but this approach can be easily followed by Windows users). Create a root folder for symfony, and then create a subfolder for each version of symfony you use, thus:
mkdir /var/www/symfony mkdir /var/www/symfony-1.0.21 mkdir /var/www/symfony-1.4.5
OK, great. Now unpack the tarball/zipfile of each version into each folder; these are available on the symfony website. In my example, one or more projects are to use version 1.4.5, which is current at the time of writing, and one or more projects are to use 1.0.21, which is now out of support (though incidentally, I still do active development with it). So, each folder will contain the data, doc, lib (etc) folders for each installation.
Lovely. Now let’s demonstrate how to create a new project using a version of our choosing. Let’s first create a project folder, then use PHP to access the relevant symfony command:
mkdir /var/www/thenextfacebook php /var/www/symfony/symfony-1.4.5/bin/symfony generate:project thenextfacebook
From that point on, whilst inside that folder, we can use:
# For users of any OS platform php symfony php symfony <command> # For *nix environments symfony symfony <command>
This is because, during project creation, a “symfony” file is copied to the project root.
Now, this approach makes upgrading between update releases very easy. If a project is running on 1.4.5, and 1.4.6 is released, it is just a question of installing the new version according to the above guidelines, and then modifying the pathname in the relevant configuration file (for this version, it’s /config/ProjectConfiguration.class.php). Then, just clear the symfony cache and you’re good to go:
php symfony cc
It is worth quickly mentioning an alternative approach, favoured by the core team, which is to use Subversion to pull a copy of symfony onto the server. Rather than creating a folder for each revision version, one is simply created for each non-compatible release:
mkdir /var/www/symfony mkdir /var/www/symfony-1.0 mkdir /var/www/symfony-1.4
In each folder, a checkout of the latest version is made. Then, when a new minor release is made, svn switch can be used to upgrade all projects using that version. However, this can be risky to do manually; if there are several projects using it, until each has its individual cache cleared, it may not operate correctly. Thus, if a server is running several projects, either a script should be written that clears each cache in turn, or the previous approach should be used.
One other item of note: the official tutorials show that symfony can be installed inside a project folder, in /lib/vendor. This is fine, especially on a dedicated server running just one project – symfony can then become an svn:external in source control. But if the server is to run several symfony projects, there is no need for each to have its own identical copy; in my view, it is tidier for there to be a central ‘symfony repository’, which any symfony projects may use.