Login Try it Free

Symfony2

Last Updated: Sep 26, 2012 05:00PM MDT

Contributors: Miguel Perez, Sébastien Porati

If Symfony2 is your framework of choice, then this is the guide for you. After reading it, you should be familiar with:

  •  Preparing a Symfony2 app for deployment on Pagoda Box
  •  The Symfony2 default Boxfile
  •  Connecting your Symfony2 app to a database
 

Launch Your Symfony2 App

The Symphony2 Boxfile

Create a file named "Boxfile" in the base directory of your git repo and paste in the following code snippet. The Boxfile is your Pagoda Box config file. If you want the Boxfile explained in more detail, click here.

 YAMLSymfony2 Boxfile Example 

/Boxfile

If you want to know more about writing your own or customizing your Boxfile, check out Boxfile Guide. Any settings you define in your own Boxfile will override settings defined in the default Boxfile.

Connecting to Your Database

First things first—you need to create a database to connect to. Creating databases is really simple and is covered in our Creating a Database Guide.

Once your database is created, you have two options for connecting to it:

1. Using environment variables
2. Hard-coding your database credentials into your source

Using Environment Variables to Connect to Your Database

Using environment variables allows your app to connect to your database without exposing any databases credentials in your git repository.

Make the following changes to app/config/parameters.ini and app/config/config.yml.

 INIChanges to parameters.ini 

app/config/parameters.ini

 YAMLChanges to config.yml 

app/config/config.yml

Go to your application's Environment Vars tab in your Pagoda Box dashboard and add the following environment variables:

  Symfony2 Environment Variables  

For the key values, use the database credentials found in the Databases tab of your App Dashboard. Just click "Show Credentials" on the database you are trying to connect to.

   

Once the environment variables are setup, push and deploy your changes and your app will be connected to a database without exposing database credentials in your git repo.

Hard-Coding Database Credentials in Your Source

We admit that hard-coding database credentials in your source is the quick and dirty way to connect to your database and it's not our recommended method. Doing it this way exposes your database credentials to anybody who has access to your git repo. However, this doesn't matter if you are connecting to a database provided by Pagoda Box. Multiple layers of database authentication do not allow other apps or "non-collaborator" users to connect to your database, even if they have all of your database credentials. When it does become a problem is when you are connecting to a database hosted on another service. Others will be able to access those databases with credentials found in your source and viewable in your git repo.

When adding database credentials directly to your source, you need to make the following changes to app/config/parameters.ini and app/config/config.yml.

 INIChanges to parameters.ini 

app/config/parameters.ini

 YAMLChanges to config.yml 

app/config/config.yml

Your database credentials can be found in the Databases tab of your App Dashboard. Just click "Show Credentials" on the database you are trying to connect to.

After making these changes, push your application and deploy it on Pagoda Box and your Symfony2 app will be connected to its database.

Clearing Your Cache

If you have any suggestions or corrections for this guide, please submit a ticket.

Contact Us