Create a Symfony Development Environment
What are We Talking About?
Symfony, the hot new framework for PHP web application development, can drastically reduce development times on intricate applications. By utilizing a framework and the Rapid Application Development, Agile Development, XP, or whatever development cycle you might like best, elegant code is easier to produce and maintain. With proper design patterns already in use, one simply needs to fill in the appropriate logic at each level, and let the application grow into being. For more information on Symfony the following resources are available:
This is all great, but not nearly as useful if we can't develop and test locally. To get a nice development area installed what do we need to do? The following steps outline how to setup a machine so that you can have a projects directory that will automatically map to a nice set of URLs with minimal configuration.
What Do We Need?
We need the following installed (Gentoo use flags are in parentheses):
- apache
- mysql
- php (cli ctype reflection spl simplexml xml pcre session apache2 mysql pdo xsl)
- symfony
What's the Setup?
So how do we turn a directory full of projects into something we can get at by browsing to http://localhost/project? Well, we start by symlinking (or just changing) the docroot to the directory we want to use.
# rm -rf /var/www/localhost/htdocs
# ln -snf <path to projects> /var/www/localhost/htdocs
What we want to do now is change the vhost declaration for the default virtual host in apache. It's only an addition of a few simple lines (placed after the docroot declaration):
AliasMatch ^/((?!cgi-bin|icons).+)/sf/(.*) /usr/share/php5/data/symfony/web/sf/$2
AliasMatch ^/((?!sf|cgi-bin|icons).+?)/(.*) /var/www/localhost/htdocs/$1/web/$2
<Directory "/usr/share/php5/data/symfony/web/sf">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
The last thing that needs to be done is make sure the default redirect in your symfony project's .htaccess file redirects to /
Conclusions
That should be all there is to it, but as always your mileage may vary. If you notice significant problems or shortcomings with this how to, please, leave a comment denoting that. I will update this guide appropriately as quickly as possible.