CMPT 470, Fall 2012

Deploying Symfony

This information is provided to help you get (possibly several) Symfony applications running on your group's web server. The setup I have suggested is Apache 2 with mod_php, which is the standard PHP setup.

Installation and Setup

First of course, you need the relevant software installed. Since the Symfony package in Ubuntu is out of date, it's probably best to get Symfony as a PEAR package.

sudo apt-get install libapache2-mod-php5 php-pear php5-cli php5-xsl
sudo a2enmod rewrite
sudo pear channel-discover pear.symfony-project.com
sudo pear install symfony/symfony

You might want to do the Symfony PHP checks to make sure everything is okay. (You can ignore the warning about the PHP accelerator.)

GET http://sf-to.org/1.4/check.php > /tmp/check.php
php /tmp/check.php

If you haven't already, you will need to install the MySQL server as well: sudo apt-get install mysql-server

I'm going to assume a Symfony app already checked-out in the directory /home/userid/app/ and that you want to access that project at http://server/mysite/.

To alias this directory to the URL, edit /etc/apache2/sites-enabled/000-default and at the bottom of the <Virtualhost> section (right before the “</Virtualhost>”), add this:

Alias /mysite "/home/userid/app/web"
<Directory /home/userid/app/web>
  Options ExecCGI FollowSymLinks
  AllowOverride all
  Allow from all
  Order allow,deny
</Directory>

Restart the Apache server so it recognizes the config changes:

sudo /etc/init.d/apache2 restart

Settings

You will likely have to modify your config/databases.yml file so that your app uses a MySQL database that you create. See the MySQL database instructions for info on creating a database for your app. You can then use the Symfony command line to generate the tables and load your initial data if you wish:

php symfony doctrine:build --all --and-load

Since your site will be deployed in a directory (i.e. within /mysite/ instead of at the server root), edit the web/.htaccess file and uncomment RewriteBase line so it looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /mysite/
    …

Now, you should be able to see the front page of your site at http://server/mysite/.

Redirects and Links

Of course, any links within your system will have to take the new URL into account. For example, a link like this

<a href="/object/edit">

will have to become:

<a href="/mysite/object/edit">

Hopefully, you have used url_for, link_to, generateUrl, or similar functions wherever necessary in your app. If so, the changes should be automatic.

If you haven't, the easiest fix might be to go back to your code and use these functions wherever you need a URL.

Static Media

For all but the simplest sites, you will have some static files that accompany the dynamically-generated code (stylesheets, images, Javascript code, etc.).

With Symfony, you can simply place these files within the web directory. It would likely to be easiest to create a directory named something like web/static and put files in there. They can then be accessed at a URL like http://server/mysite/static/style.css .

Deployment in Practical Symfony.


Copyright © , based on content created by Greg Baker.