r1pp3rj4ck's tech blog

Because software is like sex… it's better when it's free – and even better with a penguin.

Creating an environment for Symfony2 – Part 1

Hello, guys, I know I promised I would write one more post last year, but I underestimated the time I had to spend for work. I’m sorry about that. So, here it is, I’m ready to share my experience with Symfony2 and git. Starting a Symfony2 project is pretty easy and straight-forward. However, if you are just planning to create your first Symfony2 project, you should definitely read the Symfony book.

Let’s assume you’re familiar with Symfony2 now, you also created a little project with it (you should definitely do this before starting to develop a large project for production), and you are also familiar with the basics of Git distributed version control system (DVCS) and Linux (whatever distribution). You will need PHP, some HTTP server and a database server. Symfony2 is not a strict framework, you can choose between two database abstraction layers (DBAL) at this point as far as I know: Doctrine and Propel, which are capable of handling many database servers like MySQL, MongoDB, PostgreSQL.

So let’s begin with installing PHP, Apache and MySQL. I usually install PHP and Apache from source and go with the packaged version of MySQL. Actually, the Arch is a rolling-release distribution, so the packages are always bleeding edge, but it’s more convenient for me to just copy-paste my good old configure parameters and recompile it when a new version comes out.

When your server is up and running, configured everything, you will need an APC PHP accelerator (# pecl install apc, then add it as extension in php.ini), and xdebug (# pecl install xdebug, then load it too as an extension). This will ease the development (on production server you’ll need only APC, xdebug is unnecessary).

Next, you will need a good integrated development environment (IDE). I used NetBeans for a long time, and switched to PhpStorm a few days ago. NetBeans is free and pretty cool, but it lacks a good Twig plug-in. I’m a back-end developer so I didn’t miss it so much, but it was a pain in the ass to code even these little skeleton-templates or integrate the site-build into the actual project. Now that I started to use PhpStorm trial version, it’s all gone, it works like a charm. The Twig is integrated, the PHP editor is really intelligent, so I’m pretty sure that I will buy a licence. However, if you choose this, you’ll need Oracle JDK for it, it doesn’t really like OpenJDK.

So, where are we? We have a fully set web server on localhost, an IDE, what else do we need? Some optional stuff improving the quality of the code, sparing us some time and making work comfortable. If you’re working for a company, some coding standards are mandatory to use, am I right? Without coding standards, no matter how nice your code is, it will look like a mess, thanks to source control and the different coding conventions of the fellow developers. So, if you’re a boss or a project manager at your company, first thing is to standardize a coding convention used later by your team. If it’s done, your team should use PHP_CodeSniffer PEAR package (# pear install PHP_CodeSniffer) and create a sniff according to your coding standard.  Then, you should regularly check the whole code against it.

If the origin repository is on your own server or VPS, you should check it in pre-receive git hook, and nobody could push their “stinky” commits to the origin. We have our origin remote repository on Assembla, so we can’t do that at our company, but I have a pre-commit script validating the whole index. I didn’t actually write it, I found it on Google: http://pastebin.com/AZfzCTGH. It works fine, and I can’t commit until I fix every issue, including commenting methods, classes, removing trailing whitespaces, etc.

I still don’t really have time to write everything I wanted, so

to be continued…


Single Post Navigation

7 thoughts on “Creating an environment for Symfony2 – Part 1

  1. regarding the IDE integration: if you’re into eclipse, you might checkout my Symfony plugin (http://git.io/pUhN4w) and the phpsrc tools (http://www.phpsrc.org/) which provide an integration for codesniffer and other tools like PHPUnit.

  2. Unfortunately, I don’t really like Eclipse, but I guess I will try it sometime, but now I’m all about PhpStorm until my trial licence expires :D

  3. Michael on said:

    netbeans has twig plugin and I recommend it: http://plugins.netbeans.org/plugin/37069/php-twig

    • Yes, I know it does, I used it too, but my laptop is really slow, and the Twig plug-in it slowed it down even more. And the PhpStorm is smarter in Twig than the Twig plug-in.

  4. Pingback: A week of symfony #262 (2->8 January 2012) « We are php

  5. Pingback: Cgi script installation service

  6. codelobster on said:

    As for me, I like Codelobster PHP Edition with special Symfony plugin – http://codelobster.com/symfony.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: