Running Symfony
- 1. Wildan Maulana | wildan [at] tobethink.com #3 The Definitive Guide to symfony Running Symfony Doc. v. 0.1 - 14/04/09
- 2. Requirement Symfony requires at least PHP 5.2. Make sure you have it installed by opening a command line and typing this command: > php -v PHP 5.2.6-2ubuntu4 with Suhosin-Patch 0.9.6.2 (cli) (built: Oct 14 2008 20:06:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
- 5. Use Subversion (SVN) installation, it is meant to be used by advanced PHP developers, who want to take advantage of the latest patches, add features of their own, and/or contribute to the symfony project. Btw, I prefer using SVN installation method
- 6. Installing the Sandbox The sandbox is a simple archive of files. It contains an empty symfony project including all the required libraries (symfony, lime, Prototype with Scriptaculous, Doctrine and Propel with Phing), a default application, and basic configuration. It will work out of the box, without specific server configuration or any additional packages.
- 7. Download from : http://www.symfony-project.org/get/sf_sandbox_1_2.tgz Unpack it to the root web directory (I assume you to use sf_sandbox/ directory)
- 8. Test the installation : > php symfony -V You will see sandbox version number : symfony version 1.2.0 (/path/to/the/symfony/lib/dir/used/by/the/sandbox) Try to browse the sandbox by requesting this URL : http://localhost/sf_sandbox/web/frontend_dev.php/
- 11. Installing the symfony PEAR Package Add the symfony channel to PEAR > pear channel-discover pear.symfony-project.com
- 12. To see the libraries available in this channel, type the following: > pear remote-list -c symfony
- 13. Now you are ready to install the latest stable version of symfony. Issue this command: > pear install symfony/symfony
- 22. Installing the symfony PEAR Package The symfony libraries are now installed in directories as follows: $php_dir/symfony/ contains the main libraries.
- 25. $test_dir/symfony/ contains symfony core unit and functional tests. The _dir variables are part of your PEAR configuration. To see their values, type the following: > pear config-show
- 28. # > svn checkout http://svn.symfony-project.com/tags/RELEASE_1_2_0/
- 30. symfony version 1.2.0 (/path/to/the/svn/symfony/lib/dir) <?php require_once '/path/to/symfony/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); class ProjectConfiguration extends sfProjectConfiguration { // ... }
- 33. Creating Project For a PEAR installation, issue these commands: > mkdir ~/myproject > cd ~/myproject > symfony generate:project myproject For an SVN installation, create a project with these commands: > mkdir ~/myproject > cd ~/myproject > php /path/to/symfony/data/bin/symfony generate:project myproject apps/ cache/ config/ data/ doc/ lib/ log/ plugins/ test/ web/ Symfony will create a directory structure that looks like this:
- 36. This will create a frontend/ directory in the apps/ folder of the project root, with a default application configuration and a set of directories ready to host the file of your website: apps/ frontend/ config/ i18n/ lib/ modules/ templates/ web/ index.php frontend_dev.php index.php -> front controller in production environment frontend_dev.php -> front controller in development environment
- 40. Setting Up a Virtual Host <VirtualHost *:80> ServerName myapp.example.com DocumentRoot "/home/steve/myproject/web" DirectoryIndex index.php Alias /sf /$sf_symfony_data_dir/web/sf <Directory "/$sf_symfony_data_dir/web/sf"> AllowOverride All Allow from All </Directory> <Directory "/home/steve/myproject/web"> AllowOverride All Allow from All </Directory> </VirtualHost> Don't fortget to setup your DNS entry for your application address first
- 42. Configuring a Shared-Host Server This is a little trickier, since host usually has spesific directory layout that you can't change
- 43. .htaccess Options +FollowSymLinks +ExecCGI <IfModule mod_rewrite.c> RewriteEngine On # uncomment the following line, if you are having trouble # getting no_script_name to work #RewriteBase / # we skip all files with .something #RewriteCond %{REQUEST_URI} .+$ #RewriteCond %{REQUEST_URI} !html$ #RewriteRule .* - [L] # we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f # no, so we redirect to our front web controller RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>
- 49. The include path of your system must include the path to the php command, and the include path of your php.ini must contain a path to PEAR (if you use PEAR).
- 50. Sometimes, there is more than one php.ini on a server's file system (for instance, if you use the WAMP package). Call phpinfo() to know the exact location of the php.ini file used by your application.
- 52. The archives of the users mailing-list (http://groups.google.fr/group/symfony-users)
- 55. > svn mkdir -m "layout creation" file:///$SVNREP_DIR/myproject/trunk file:///$SVNREP_DIR/myproject/tags file:///$SVNREP_DIR/myproject/branches
- 59. svn import -m "initial import" . file:///$SVNREP_DIR/myproject/trunk
- 60. > svn ls file:///$SVNREP_DIR/myproject/trunk/
- 63. > svn co file:///$SVNREP_DIR/myproject/trunk myproject
- 77. Once your project is initiated, it is a good habit to start a version-control process.