Setting up a Symfony project on Media Temple’s Grid Service, Part 1

Media Temple’s Grid-Service is a great, low-cost solution for developing and deploying Symfony applications. This article will walk you through setting up a Grid-Server Subversion repository for use with a Symfony project. The main point here is being able to create and use a symfony project hosted on a Grid Server without having to have symfony pre-installed at all locally.

Setting Up Subversion

Symfony is designed to be used with version management software like Subversion. If you’ve never used versioning software, you should read about the benefits right from the Subversion book itself, but in general, it tends to make life easier for developing and maintaining large code bases as it tracks revisions between files and authors. Subversion is already installed in the Grid-Service environment, so all we have to do is set up a new repository. Media Temple has a knowledge base article describing the basic steps, but we’ll be tailoring things a bit to Symfony.

Be sure that you’ve enabled SSH access on your account. Personally, I like creating the repository using the serveradmin user, and then I’ll make commits using a local user on whichever domain I’ll be using. Let’s get started.

Once you’ve logged in via SSH as serveradmin, move into the data directory. This is where we’ll be creating the repository:

cd data

Then, create the base repository like so (substituting your own repository name for mirthlab):

svnadmin create --fs-type fsfs mirthlab

I tend to use separate repositories for each domain. This allows me to use a structure of the form:

mirthlab/
    project1/
        trunk/
        tags/
        branches/
    project2/
        trunk/
        tags/
        branches/
some_other_domain/
    project3/
        trunk/
        tags/
        branches/

… so I can effectively have as many projects related to each domain in version control as I need.

Now that we’ve created the repository, let’s create the base folder for the Symfony project. While still in the data directory, we’ll create a few new folders:

mkdir project1
mkdir project1/trunk
mkdir project1/tags
mkdir project1/branches

… where project1 is the name of your symfony project. This might all look familiar if you’re read through the Subversion documentation, but we’re going to add a couple of folders:

mkdir project1/trunk/lib
mkdir project1/trunk/lib/vendor

It’ll become clear in a moment why we’re doing this, but the short of it is that we’re going to link the Symfony libraries directly to the project itself using the lib/vendor folder. Once you’re done, commit the contents of your project folder to the repo like so:

svn import project1 file:///home/<site_number>/data/mirthlab/project1 --message "Creating initial repo."

Be sure to change <site_number>, mirthlab and project1 appropriately, so that they match your setup. Please note that this assumes you’re starting with a fresh Symfony project. If there’s an existing project you have that you want to import into the repository, these steps would vary slightly since you wouldn’t have to set up a lib folder.

The folder structure was imported into the repository, so you can safely delete the project folder skeleton we made from the data folder:

rm -rf project1

Set Up Additional SVN Users

This step is optional, but would be helpful if you’re going to allow multiple users to work on this repo. There’s also a Media Temple KB article for this if you’re curious. Log in to your Media Temple Account Center for your domain. Click on the “Email Users” button and add some local users.

Email Users Button

I created a user “mark” for my domain. Also, be sure to check the “Enable SSH access?” checkbox:

image here

Now, in order to allow other users to use the new repo, we have to give group access to the directory. From within the data directory run this command as serveradmin:

chmod -R g+w mirthlab

Again, being sure to substitute your own repository name for mirthlab.

Setting Up Symfony

Now that you have your base folder structure, it’s time to get the Symfony project initialized. Connect to your Subversion repository and download the trunk of our project by running the following commands locally. I’m on a Mac OS X box, so I’ll use the terminal to do a checkout of my project to the ~/Sites folder:

cd ~/Sites
svn checkout svn+ssh://your_user%your_domain.com@your_domain.com/home/<site_number>/data/mirthlab/project1/trunk project1

Note: svn checkout svn+ssh... should all be on one line. This creates a project1 folder in my Sites folder, which is just what I want. Now let’s get our Symfony project structure set up by linking the Symfony libraries to our lib/vendor folder with a subversion externals link.

cd project1
svn propedit svn:externals lib/vendor/

This should bring up your favorite text editor. Simply paste this line into the file, save and close it:

symfony http://svn.symfony-project.com/branches/1.0

This effectively links lib/vendor/symfony to the stable 1.0 branch of Symfony. Only security and bug fixes go into this branch, so there’s no need to worry about it breaking your app when running an svn up. Now, commit your changes back to the repository:

svn commit --message "Linking Symfony libraries to lib/vendor"

And when that’s done, update the local working copy to get the libraries:

svn up

Since we now have a local copy of symfony, we can use the symfony binary to execute pake tasks. Let’s flesh out our project by creating the initial structure using the init-project task.

lib/vendor/symfony/data/bin/symfony init-project project1

… where project1 is the name of our project. This doesn’t necessarily have to match the name of your repository project, but that’s usually what I use. This project name is used to set up defaults in files like propel.ini and properties.ini.

Also, be sure to change the path for the symfony libraries in config/config.php:

$sf_symfony_lib_dir  = dirname(__FILE__).'/../lib/vendor/symfony/lib';
$sf_symfony_data_dir = dirname(__FILE__).'/../lib/vendor/symfony/data';

… this just sets them up to use a relative path, instead of an absolute one (which we’ll need when we push this code to the production server).

We can now add the rest of the project to source control:

svn add *
svn commit --message "Added initial symfony project structure."

Subversion might complain that the lib folder is already under version control, but that’s ok.

Next Steps

Additional general info on Symfony and Subversion can be gleaned from Dave Dash’s excellent article: Tips for Symfony and Subversion. Read and follow the directions in that article to complete your setup by ignoring files in cache and log as well as other auto-generated files like the model files Propel generates.

Conclusion

With this setup, we now have a Symfony project under source control on a Media Temple Grid-Service account. We also now have symfony installed locally and which we can use by calling simply ./symfony from within our project directory. In the next article, we’ll take a look at getting our local development environment set up for editing on a Mac OS X box.



Find This Article Useful?

  • Share/Save This Entry



Related Articles


About this entry