Reducing the gap between Symfony and non-PHP frameworks

Something that always annoyed me is how tedious it is to install a Symfony project on a machine. Since I frequently need to intervene quickly on a project for work, and I was getting a brand-new machine, I really didn’t want to create an apache vhost (let alone install Apache: it’s painfully slow and its configuration is obscure and hard to debug), edit my /etc/hosts file, etc. for each project.

Moreover, developers are not system administrators and should not have to do complicated setups, especially when it turns out to be badly set up, and problems are “resolved” by “chmod 777” or “chmod 666” (which is indeed evil), a very sad but true practice promoted even by the developers of Symfony since there is a symfony fix-perms command that basically does that. It should have been named symfony break-perms or symfony please-make-things-insecure-i-want-to-go-back-to-windows or never been made.

On most non-PHP frameworks, there is a small embedded webserver that you can run on-demand. No configuration needed. Moreover, no special rights needed: a simple user can start it.

Since there was no such webserver written in PHP that was able to run Symfony properly, I chose to auto-configure lighttpd with a simple tool called symfttpd. The genconf tool was born.

However, I encountered another issue I didn’t think of before: for each project, I had to create symbolic links to the Symfony source code (another practice of the Symfony community, and there is no proper alternative in the PHP world). Hence, I created mksymlinks. For the developer, it is very simple to use: configure once on the machine, once per project, and that’s it.

genconf only generates a configuration, which is still very practical for a system administrator; moreover it is flexible and well-tested. But it still required the develop to configure something, and there still was the rights problem.

Hence I created spawn which handles starting and stopping the webserver, just like non-PHP frameworks do. As a nice addition, it keeps server and PHP logs in the log folder of the project.

symfttpd has even more uses; one I didn’t think of at first was that it can automate the installation of a project on a continuous integration platform, and can start a webserver for functional testing (both are used daily at work).

One of the most important aspects of symfttpd is that all tools are independent: you can use only mksymlinks or genconf (though spawn more or less requires the use of both, it isn’t set in stone). A system administrator will find use in mksymlinks and genconf, and a developer more in mksymlinks and spawn.

You’ll find extensive documentation on the project page; what will follow is a quick tutorial for developers.

Install the necessary packages:

# Debian/Ubuntu
aptitude install php5-cgi php5-cli lighttpd
 
# Gentoo
emerge php # with USE="cli cgi"
emerge lighttpd # with USE="fastcgi"
 
# Macports
port install php5 +fastcgi && port install lighttpd
 
# Windows
Nice try.

Get the symfttpd source code:

cd && git clone git://github.com/laurentb/symfttpd.git

There are also archives you can download here if you want to avoid git or bleeding-edge changes.

Basic configuration:

# notice the dot before symfttpd.conf.php
$EDITOR ~/.symfttpd.conf.php

Enter something like that:

< ?php
$options['sf_path']['1.0'] = '/home/myuser/symfony/1.0';
$options['sf_path']['1.4'] = '/home/myuser/symfony/1.4';

Of course, you have to have to adapt it to the Symfony versions you have installed and where you put them.

Configure the project:
If the project is using Symfony 1.4 in the lib/vendor/symfony, you don’t need to do anything. In case it is different, or to be on the safe side, create the file config/symfttpd.conf.php in your project. After, add the file to your project’s version control repository. If you’re lucky, someone already did it for you.

cd ~/myproject
# this time, no dot
$EDITOR config/symfttpd.conf.php
< ?php
$options['want'] = '1.3'; // The version of Symfony used by your project
$options['lib_symlink'] = 'lib/vendor/symfony'; // lib/vendor/symfony will lead to the "lib" directory of Symfony
~/symfttpd/mksymlinks

You’re done.
It will create symbolic links for plugins too, even if the version of Symfony (1.0 for instance) doesn’t handle them!

To start the server:

~/symfttpd/spawn

It will then tell you how to access it. It’s time to stop fighting with old, unpredictable software like Apache and start developing again!

What’s coming in future releases:

  • Colors
  • Interactive configuration
  • Server/PHP logs displayed in the terminal
  • Handling “sample” files
  • Custom configuration support on various places

Contributors are welcome.

This entry was posted in PHP, Symfony, Sysadmin and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Bitcoder
    Posted 2010-05-26 at 0611 | Permalink
    Firefox 3.5.5 Firefox 3.5.5 Windows XP Windows XP
    Was this project innitiated by you?
  2. Posted 2010-05-26 at 0649 | Permalink
    Firefox 3.6.3 Firefox 3.6.3 Gentoo x64 Gentoo x64
    Yes. I wrote it for my sole usage and it evolved to be much more.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*