Symfony applications on CD-ROM
18. December 2007 in Symfony
The last week I coded a webbased application thats being used directly from CD-ROM. I used Server2Go as a CD-ROM Webserver that servers the application for browsing and searching on the CD-ROM.As you know my favorite Webframework is Symfony (www.symfony-project.com) so i developed this piece of software with the most current stable symfony version (1.0.9).
There are only some things that needs your attention if you want to make a symfony application runnable from CD-ROM:
1.) Freeze it: After developing you have to freeze your project with:symfony freeze app-name
2.) Now copy the entire (freezed) project folder to the htdocs folder of your Server2Go directory
3.) Clear the cache folder! You can do this by manually delete the content of this folder or by using “symfony cc” before copying the data to the htdocs folder
4.) Open the server/config_tpl/httpd.conf file and change the root directory of the server to the web folder in htdocs:
DocumentRoot “%CDPMS:DOCROOT%/web”
<Directory “%CDPMS:DOCROOT%/web”>
…
</Directory>
So far so good. Now the tricky part begins. Symfony is caching a lot of files and data in order to provide the best possible performance. Therefor views, configfiles and so on will be cached. Where’s the problem? The problem ist that the cache folder on CD-ROM isn’t writable and symfony is throwing exceptions if it can’t write the cache data…
My first thought: No problem, you have just to deactivate the caching in the settings.yml via
cache: off
Works great for view data, but not for the cached config data. Symfony always caches the config, there is no way to deactivate this (or i didn’t find one). So what to do? Was symfony the wrong choice for a cd-rom webapplication? No of course not
There possibility to customize the project structure (foldernames and hierarchie) via the constants.php file. You will find this in the htdocs/data/symfony/config folder. Open it and look for the line that starts with ‘sf_cache_dir’ and change it to:
‘sf_cache_dir’ => $sf_cache_dir = $_ENV['S2G_TEMP_FOLDER'].DIRECTORY_SEPARATOR. “cache”. DIRECTORY_SEPARATOR. $sf_environment,
Thats it! This line redirects the cache folder to a temorary folder on the users machine (is done by the S2G_TEMP_FOLDER environment variable that is set by Server2Go.
After that you can burn the Server2Go folder to a CD-ROM and everything works as expected
Gerald said on 19. December 2007
thanks for the tips, I never thought it would be possible, sounds really great, I’ll probably use it in the future.
You did not mention it but I guess it also support MySQL database?
Mike Nolan said on 19. December 2007
Interesting stuff. Did you use a database? Any trouble with that?
Timo Haberkern said on 19. December 2007
Hi,
the project doesn’t use MySQL but is is possible to use MySQL from CD-ROM with Server2Go. Should be nor problem to access with symfony
Timo
grayblur said on 20. December 2007
maybe we could use SQLite ,then run in memory mode..
is that possible?
Timo Haberkern said on 20. December 2007
Yes SQLite is alos supported by Server2Go
In this case you doesn’t need a MySQL-Server anymore.
Massimiliano said on 17. October 2008
You can use this trick with symfony 1.1: edit your config/ProJectConfiguration.class.php and add these lines in the setup method:
$this->setLogDir($_ENV['S2G_TEMP_FOLDER'] . ‘/log’);
$this->setCacheDir($_ENV['S2G_TEMP_FOLDER'] . ‘/cache’);
Lajuana said on 28. October 2008
Keep up the good work.
hammudi said on 10. November 2008
i’ve a plan to build an Inventory System using Symfony, is it possible to “secure” the code… so others can’t modify my application? and even copy it?
thx…
hendra1 said on 26. August 2009
hello your articel is very nice…
i just want to know where is the “constants.php ” file
if i’m using symfony 1.2 ?
thanks before…
Timo Haberkern said on 26. August 2009
Seems that I need to update the article
You are right. In Symfony 1.2 there is no constants.php any more. You will have to set the path via sfConfig::set(…) in the config/PojectConfiguration.class.php. I will write a post about this as soon as possible
Timo
hendra1 said on 28. September 2009
@thaberkern
hello thaberkern, i try to figure it out how to change the cache directory in symony 1.2, but it’s not as simple like in symfony 1.0
i try to following your advice to set via config in ‘config/PojectConfiguration.class.php’ but nothing happen. The cache is still in root directory, i’ll try to set config in action.class, the cache is move out to my cache directory.
But the problem is not all the cache file is move out..
have you find the solution..?
jojo said on 4. January 2011
just edit your server2go config..
it’s work