Development

InstallingSymfonyWithoutPear

You must first sign up to be able to contribute.

Overview

25 October 2005

This page describes the process of installing symfony without using "pear install" on Windows XP.

I am not associated with the symfony project itself so this is an outside observers view point of the process. This is very much a work in progress. I have reached the point of being able to view the Project Congratulations page in a web browser.

Why

You should of course be asking yourself why not use "pear install" since it seems to simple. Well, there are a few cases where you don't have shell access to your web server so you need to do stuff via ftp. But more to the point, "pear install" and I have never gotten along well. No doubt it's my fault but everytime I try it I run into problems. Even on a fresh machine "pear upgrade PEAR" complained about Archive_Tar and stopped working. Another reason that one might wish to avoid using "pear install" is a desire to understand exactly which files need to end up where for the system to work. And if I am going to use a frame work then I want to know how it works.

In most cases installing a pear module manually is easy. You just unpack the .tgz file and copy the .php stuff to your pear directory. However, symfony is more complex. It has files that need to be copied to different pear directories. And furthermore it has params such as @php_dir@ which automatically get replaced by real paths by the pear installer. It's not hard to install symfony manually but does take a bit of care.

The Environment

I'm currently running under Windows XP though most of this should be directly applicable to linux and other operating systems. I'm using PHP 5.0.3 (Dec 2004), it's a bit dated but have not run into any problems yet. I'm using xampp which in one of the many LAMP installation tools for Windows. Make sure you have magic_quotes_gpc = Off and register_globals = Off in your php.ini file as symfony will throw an exception (after generating some errors) if they are set. Also, I recommend setting include_path="." just to remove any possibility of accessing the pre-installed pear code. I use Eclipse with the PHPEclipse plugin for an IDE. I generally use the FireFox browser for testing. This is also my first time using TracWiki so we will just see how the formatting goes.

Setting Up PEAR Directories

Even though symfony is not really a pear module I still install it under the pear heirachy. In my Eclipse osso workspace I created a project called pearx to manage things. I often find myself needing to browse the pear code while developing so having a pearx project under Eclipse is useful. I used pearx just to distingush it from any other pear stuff floating around. Plus, all cool names need to have a x in them somewhere. From a file system perspective we end up with:

C:\cerad\osso\pearx

Create lib,bin,data,cache,docs,test and ext folders under pearx. Add pearx\bin to your PATH with MyComputer/Properties/Advanced/Enviroment

Installing Pake

Pake is used by the command line symfony tool for generating assorted skeleton code. Start by getting the latest pake.tgz file from http://www.pake-project.org/download.html. I usually save these files to a tgz directory outside of my Eclipse workspace and then unpack them resulting in a pake-1.0.69 folder.

Copy the pake-1.0.69/lib/pake folder to pearx/lib resulting in a pearx/lib/pake/<assorted files> folder. Copy pake-1.0.69/bin/pake.php to pearx/lib resulting in pearx/lib/pake.php.

The pake-1.0.69/bin/pake.bat file allows you to run pake from the command line. It has assorted env variable and what not to make it general. I just create a new pearx/bin/pake.bat file with these lines:

@echo off
c:\xampp\php\php -d html_errors=off -qC c:\cerad\osso\pearx\lib\pake.php %1 %2 %3 %4 %5 %6 %7 %8 %9

This makes it easy to see exactly what is being kicked off. Test your installation with from a console window with "pake -V". This ensures your PATH is setup correctly and that pake.php can be found.

Installing Symfony

Grab the symfony.tgz file from http://www.symfony-project.com/content/download.html and unpack it resulting in symfony-0.4.1. Now this is a bit tricky so read carefully.

Copy the symfony-0.4.1/data/symfony directory to the pearx/data directory resulting in pearx/data/symfony/lots of files.

Now create a new directory pearx/lib/symfony and then copy all of the directories under symfony-0.4.1/lib/ (six of them) to pearx/lib/symfony. \

Copy symfony-0.4.1/bin/symfony.php to pearx/lib.

Finally, create pearx/bin/symfony.bat with these lines:

@echo off
c:\xampp\php\php -d html_errors=off -qC c:\cerad\osso\pearx\lib\symfony.php %1 %2 %3 %4 %5 %6 %7 %8 %9

You should end up with something like this:

pearx/lib/pake.php
pearx/lib/symfony.php
pearx/lib/pake/assorted_files
pearx/lib/symfony
pearx/lib/symfony/symfony/assorted_files
pearx/lib/symfony/propel/assorted_file
pearx/lib/symfony/some_more_directories
pearx/data/symfony/assorted_files
pearx/bin/pake.bat
pearx/bin/symfony.bat

Now edit symfony.php and replace the pear variables with:

define('PAKEFILE_LIB_DIR',  'c:/cerad/osso/pearx/lib');
define('PAKEFILE_DATA_DIR', 'c:/cerad/osso/pearx/data');
define('PAKEFILE_SYMLINK',  false);
define('SYMFONY_VERSION',   '0.4.1');

From a console window run "symfony -V" and "symfony -T" to verify correct installation.

Creating a Project

Under eclipse create a new php project called ProjectOne. From a console window

cd c:\cerad\osso\ProjectOne
symfony init-project ProjectOne

Lot's of files are created including:

>> file+     C:\cerad\osso\ProjectOne\\config\config.php
>> file+     C:\cerad\osso\ProjectOne\\config\doc_footer.html
>> file+     C:\cerad\osso\ProjectOne\\config\doc_header.html
>> file+     C:\cerad\osso\ProjectOne\\config\doxygen.cfg
>> file+     C:\cerad\osso\ProjectOne\\config\propel.ini
>> file+     C:\cerad\osso\ProjectOne\\config\properties.ini
>> file+     C:\cerad\osso\ProjectOne\\web\css\main.css
>> file+     C:\cerad\osso\ProjectOne\\web\error.php

The project config.php is just an empty file so there is nothing to edit for now.

Creating An Application

cd c:\cerad\osso\ProjectOne
symfony init-app AppOne

Agin we get lots of new files:

>> file+     C:\cerad\osso\ProjectOne/AppOne\\config\app.yml and other yml files
>> file+     C:\cerad\osso\ProjectOne/AppOne\\config\config.php
>> file+     C:\cerad\osso\ProjectOne/AppOne\\lib\myAction.class.php and other php files
>> file+     C:\cerad\osso\ProjectOne/AppOne\\templates\layout.php,error.php,error.txt
>> file+     C:\cerad\osso\ProjectOne/web/index.php
>> file+     C:\cerad\osso\ProjectOne/web/AppOne_dev.php

Edit the AppOne?/config/config.php file and you will see:

// symfony directories
if (is_readable(SF_ROOT_DIR.'/lib/symfony'))
{
  // symlink exists
  define('SF_SYMFONY_LIB_DIR',  SF_ROOT_DIR.'/lib/symfony');
  define('SF_SYMFONY_DATA_DIR', SF_ROOT_DIR.'/data/symfony');
}
else
{
  // PEAR config
  if ((include 'symfony/symfony/pear.php') != 'OK')
  {
    throw new Exception('Unable to find symfony librairies');
  }
}

By default symfony looks to see if you have symbolically linked the main symfony php and data files to your project directory. If not then it calls a special pear.php script for setting the directory paths. Just comment out the above lines and add:

define('SF_SYMFONY_LIB_DIR',  'c:/cerad/osso/pearx/lib/symfony');
define('SF_SYMFONY_DATA_DIR', 'c:/cerad/osso/pearx/data');

Note that you could also edit pearx/data/symfony/skeleton/app/app/config/config.php before generating your app code.

Web Setup

I'm not a big fan of setting up virtual hosts nor do I care to have my development code directly exposed under a web home directory. Assuming that htdocs is your web server directory then create a directory called htdocs/ProjectOne and copy ProjectOne?/web/index.php to it. Edit index.php as follows:

ini_set('include_path',  'C:/cerad/osso/pearx/lib;.');
define('SF_ROOT_DIR',    'C:/cerad/osso/ProjectOne');

I like to always explicity set the include directories upon startup. Notice that even though symfony ends up defining all sorts of paths and such you still need to make sure the system points to pearx/lib. Browse to ProjectOne?/index.php and (with luck) you will see the congratulations page.

You should also copy the ProjectOne?/web/css/main.css file to htdocs/ProjectOne/css/main.css then edit ProjecyOne/AppOne?/config/view.yml and

change
  stylesheets:    [main]
to
  stylesheets:    [./css/main.css]

This change results in a relative path for loading in the style sheet. Note that after adjusting the view.yml file you will need to do a

symfony clear-cache

for the change to take effect.

Propel and Phing Setup

Following along with the my first project tutorial, the next step is to add some schema information to config/schema.xml and run:

symfony build-model
symfony build-sql

For the above to work you need to install the Phing package. Grap http://phing.info/pear/phing-current.tgz and unpack it. Phing installs like the other packages except it takes a bit more copying.

pearx/data/phing
	etc/*.xsl
	listener/defaults.properties
	tasks/defaults.properties
	types/defaults.properties
	VERSION.TXT
	
pearx/lib/phing
    *.php
    listener/*.php
    tasks/*.php
    types/*.php
    filters             
    system
    input
    lib          
    util
    mappers
    parser

pearx/lib
    bin/phing.php

A real pain but if you came this far then you may as well finish. There is an alternate way to install Phing but this seems to work ok.

Add to phing.php

ini_set('include_path',  'C:/cerad/osso/pearx/lib;.');

Then you need to make one hack to pearx/lib/Phng.php. Phing searches the include directories for property files which means it won't find stuff under pearx/data/phing. Look in lib/Phing.php and

replace
$data_dir = '@DATA-DIR@';
with
$data_dir = '/cerad/osso/pearx/data';

This is something that probably should be cleaned up later.

Up to this point you may have noticed that we have not needed any of the actual pear classes. In particular PEAR.php has never been included. Sadly, somewhere deep in the bowels of Phing, some sort of Pear Zip class is being requested. I didn't spend time tracking down why. I suspect it could be commented out for our purposes. But in any event you now need to install a few of the Pear classses. Get PEAR.tgz and Console_Getopt.tgz from pear.php.net, expand them, then copy:

pearx/lib/PEAR.php
pearx/lib/System.php
pearx/lib/Console/Getopt.php

I ran into one strange thing. Under the directory pearx/lib/symfony/propel-generator\classes\propel\engine\builder\om\php5\ some of the files had an extension of .ph instead of .php. Must be some sort of limit in the tar/zip program somewhere. Renaming the files with the correct .php extension was required.

At this point, you should be able to run

symfony build-model
symfony build-sql

Which results in Propel classes as well as a schema.sql. Follow the tutorial and create your database.

Creating a Module

This is as far as I have gotten so far. Modules come next.

Feedback

Probably should use the forum topic for feedback.