Posts Tagged PHP

Dynamic Web Service using ckWebServicePlugin

To implement Web Service in symfony, ckWebServicePlugin can offer integration of symfony module as web service. The instruction detail can be found at http://www.symfony-project.org/plugins/ckWebServicePlugin/3_0_0?tab=plugin_readme.

But, to make the plugin installation work, you need additional files:

Then follow the instruction to configure the plugin. But, the readme is rather outdated. For example:

<?php

// apps/frontend/modules/math/actions/actions.class.php
class mathActions extends sfActions
{
  /**
   * An action multiplying two numbers.
   *
   * @ws-enable
   * @ws-method SimpleMultiply
   *
   * @param double $a Factor A
   * @param double $b Factor B
   *
   * @return double The result
   */
  public function executeMultiply($request)
  {
    // nothing changed here...
  }
}

But, it should be:

<?php

// apps/frontend/modules/math/actions/actions.class.php
class mathActions extends sfActions
{
  /**
   * An action multiplying two numbers.
   *
   * @WSMethod(name='SimpleMultiply', webservice='MathApi')
   *
   * @param float $a Factor A
   * @param float $b Factor B
   *
   * @return float The result
   */
  public function executeMultiply($request)
  {
    // nothing changed here...
  }
}

Notice the comment doc tag, it should @WSMethod(name=’SimpleMultiply’, webservice=’MathApi’) instead @ws-method and @ws-enable is removed. You can view the complete module at [project]/plugins/ckWebServicePlugin/test/fixtures/project/apps/tutorial/modules/math/actions/actions.class.php.

By default, the generated WSDL will be located under SF_WEB_DIR, so the wsdl location is at http://localhost/MathApi.wsdl, and the front controller will be http://localhost/MathApi.php. Notice that the front controller defined in the MathApi.wsdl using static address. So if you move your Web Service to production server, you need to alter the front controller manually.

Now the part to make the wsdl front controller dynamically changed. Generate a module named wsdl:

php symfony generate:module frontend wsdl

And change the content of index action to:

<?php

// apps/frontend/modules/wsdl/actions/actions.class.php
class wsdlActions extends sfActions
{
  /**
   * Executes index action
   *
   * @param sfRequest $request A request object
   */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward404Unless($service = $request->getParameter('service'));
    $wsdl = sprintf('%s/wsdl/%s.wsdl', sfConfig::get('sf_data_dir'), $service);
    if (!file_exists($wsdl))
    {
      $this->forward404('WSDL "'.$wsdl.'" is not found.');
    }

    // generate the wsdl controller based on current request
    $wsdlController = $request->getUriPrefix().$request->getRelativeUrlRoot().'/'.$service.'.php';

    $dom = new DOMDocument();
    if ($dom->load($wsdl))
    {
      // query the soap:address node to change location
      $xpath = new DOMXPath($dom);
      $nodes = $xpath->query('/wsdl:definitions/wsdl:service/wsdl:port/soap:address');
      foreach ($nodes as $node)
      {
        if ($node->hasAttribute('location'))
        {
          $node->setAttribute('location', $wsdlController);
        }
      }

      // output
      $this->response->setContentType($request->getMimeType('xml'));

      return $this->renderText($dom->saveXML());
    }

    throw new sfException('"'.$wsdl.'" is not a valid xml document.');
  }
}

Add a route to your [project]/apps/frontend/config/routing.yml:

wsdl:
  url:   /:service.wsdl
  param: { module: wsdl, action: index }

Move your wsdl from [project]/web/MathApi.wsdl to [project]/data/wsdl/MathApi.wsdl, and last modify your [project]/frontend/config/app.yml, from:

soap:
  ck_web_service_plugin:
    wsdl:                  %SF_WEB_DIR%/MathApi.wsdl

to:

soap:
  ck_web_service_plugin:
    wsdl:                  %SF_DATA_DIR%/wsdl/MathApi.wsdl

If you want to enabled debugging on wsdl front controller, edit your [project]/web/MathApi.php to:

<?php

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'soap', true);
sfContext::createInstance($configuration)->dispatch();

, ,

3 Comments

Adding Access Logging to Symfony Application

sfAccessLoggerPlugin introduces a way of logging your site visits. To accomplish this logging, the others plugin is needed:

  1. sfGuardPlugin for User management.
  2. sfPropelUuidBehaviorPlugin for generating Universally Unique Identifier (UUID).
  3. sfRemoteIPPlugin, an extract of function found in sfPropelAuditPlugin by Sacha Telgenhof Oude Koehorst to detect the remote IP Address.
  4. sfBrowscapPlugin, a simple symfony wrapper for phpbrowscap to determine the client browser capability.
  5. The sfAccessLoggerPlugin itself.

Configuration:

  1. Instal all plugins and enable them.
  2. Do propel build model, forms, filters, and SQL, then insert generated SQL to your database.
  3. In your backend application, enable bundled module sfAccessLogViewer to provide admin style generated module to view the access log.

, , , , ,

Leave a comment

Using Multiple Primary Keys in Admin Generator

Sometimes, the table we’re using force us to use multiple primary keys as shown in the schema below (config/schema.yml):

connection:            propel
defaultIdMethod:       native
package:               lib.model

classes:
  State:
    tableName:         state
    columns:
      id:              { type: varchar, size: 2, primaryKey: true }
      country_id:      { type: varchar, size: 2, primaryKey: true }
      name:            { type: varchar, size: 50, index: true }
      created_at:

By default, the symfony Admin Generator will only support single primary key. Since symfony 1.2, which adds sfRoute class, using multiple primary keys is possible by a configuration modifications and adds a few lines of code.

So now, generate the admin module by issuing:

symfony propel:generate-admin frontend State

Look at the generated route in apps/frontend/config/routing.yml:

state:
  class: sfPropelRouteCollection
  options:
    model:                State
    module:               state
    prefix_path:          state
    column:               id
    with_wildcard_routes: true

Only a single primary key was generated, so the idea is concatenate the primary keys as a single column, separated by a dash (-) for example.

Modify the route:

state:
  class: sfPropelRouteCollection
  options:
    model:                State
    module:               state
    prefix_path:          state
    column:               countryandstate
    with_wildcard_routes: true
    model_methods:
      object:             doSelectForRoute
  requirements:           { countryandstate: '[a-zA-Z0-9\.\_\-\:]+' }

As seen in the modified route, we change the column name to countryandstate, add a model-methods for object configuration and change the countryandstate column requirements.

When an object converted as a route, the sfRoute class will check for toParams() method, so we can provide the value of countryandstate column by adding this code:

// lib/model/State.php
<?php

class State extends BaseState
{
  public function toParams()
  {
    return array('countryandstate' => implode('-', array($this->getCountryId(), $this->getId())));
  }
}

A model-methods for object configuration in the routing above, changes the method used by the sfRoute class to retrieve an object which match a route.

// lib/model/StatePeer.php
<?php

class StatePeer extends BaseStatePeer
{
  /**
   * Retrieve State object for routing.
   *
   * @param array $parameters  The route parameters
   * @return State
   */
  public static function doSelectForRoute($parameters)
  {
    if (!isset($parameters['countryandstate']))
    {
      return null;
    }

    $c = new Criteria();
    list($country, $state) = explode('-', $parameters['countryandstate']);
    $c->add(StatePeer::COUNTRY_ID, $country)
      ->add(StatePeer::ID, $state);

    return StatePeer::doSelectOne($c);
  }
}

The rest is, to customize the generated module and adjusting the form as you need.

, , ,

13 Comments

Hacking Symfony Application in A Shared Hosting

In a shared hosting environment, you may not have a full access to the server. Everything has already been installed. But a least they provide a secure shell (SSH).

I have successfully deploy a syfmony 1.2 application in a shared hosting, surely with a hacking.

PDO Hack

Symfony 1.2 at least need PHP 5.2.4 and above. So if your PHP version is 5.2.0 and you’re using MySQL database, make sure to activate PDO::MYSQL_ATTR_USE_BUFFERED_QUERY for buffered MYSQL Api.

Edit your databases.yml:

dev:
  propel:
    param:
      classname:  DebugPDO

all:
  propel:
    class:        sfPropelDatabase
    param:
      dsn:        mysql:dbname=your_db;host=localhost
      username:   root
      password:   your_password
      encoding:   utf8
      persistent: true
      pooling:    true
      classname:  PropelPDO
      options:
        MYSQL_ATTR_USE_BUFFERED_QUERY:  {value: on}

Symfony CLI Hack

Usually, we can customize the php.ini file for web server, but not for the PHP CLI. Unfortunately, the PDO extension for PHP CLI is not enabled by default. As in shared hosting environment, there are no write access to system configuration.

Try this:

$ php -i | grep PDO

If you got an output telling about PDO extensions has been enabled then, you don’t need this hack.

First, we can create our own php.ini file to be passed to the PHP CLI, and put in a writable directory, for example in the home directory:

# ~/php.ini
extension=pdo.so
extension=pdo_mysql.so
memory_limit=64M

Wrap the symfony command to make sure PHP CLI is using our custom php.ini, create the script and name it symfony.sh. Put in home directory for ease the access:

# ~/symfony.sh
cd /path/to/myproject
php -c ~/php.ini -f symfony -- $*

Make sure the script is executable:

$ chmod u+x ~/symfony.sh

Now you can launch the symfony CLI from within your home directory by issuing:

$ ./symfony.sh [command]

, , , , ,

6 Comments

Panduan Pemula Symfony

Catatan: Tutorial ini menggunakan Sistem Operasi Windows.

Instalasi Webserver, PHP, dan MySQL

Webserver: Apache HTTPD

Sebagai webserver, coba Apache HTTPD (http://httpd.apache.org), download versi terakhir (2.2.x) kemudian install. Setelah instalasi selesai, buka browser:

http://localhost

Dan hasilnya “It works!”, ini menandakan instalasi apache telah selesai, selanjutnya kita akan mengkonfigurasi httpd agar bisa menyajikan aplikasi symfony.

Database: MySQL

Database MySQL dapat diambil di sini (http://dev.mysql.com/downloads/). Untuk klien anda dapat menggunakan MySQL GUI Tools yang juga dapat diambil dari lokasi yang sama. Atau, untuk klien web based gunakan PHPMyAdmin (http://www.phpmyadmin.net/home_page/downloads.php).

PHP

Download PHP di http://www.php.net/downloads.php. Umumnya, paket binari PHP untuk Windows berbentuk arsip atau paket installer. Download paket arsip untuk versi 5.2.x dan ekstrak ke C:\PHP.

Sekarang waktunya menyiapkan php.ini, konfigurasi PHP contoh sudah disertakan dalam arsip–php.ini-dist danphp.ini-recommended–untuk saat ini, kita gunakan file php.ini-dist, cukup copy file tersebut dan ubah menjadi php.ini.

Beberapa konfigurasi PHP perlu dimodifikasi, jadi gunakan teks editor favoritmu–semisal Notepad++–untuk mengedit php.ini:

Jika perlu, atur include path, cari baris berikut (baris 476):

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Ubah menjadi:

; Windows: "\path1;\path2"
include_path = ".;C:\PHP\PEAR"

Atur direktori extension, cari baris ini (baris 491):

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

Ubah menjadi:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\PHP\ext\"

Aktifkan ekstensi-ekstensi yang diperlukan, cari baris ini (baris 604):

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

Anda bisa mengaktifkan ekstensi mbstring, mysql, pdo, pdo_mysql dan ekstensi lain yang mungkin diperlukan oleh proyek anda semisal gd2 dengan menghapus komentar (;–titik-koma) diawal tiap baris.
Juga, anda dapat menambahkan ekstensi xdebug (http://www.xdebug.org/download.php) dan letakkan di C:\PHP\ext\php_xdebug.dll kemudian tambahkan baris-baris berikut setelah konfigurasi di atas:

zend_extension_ts=C:\PHP\ext\php_xdebug.dll

Untuk membuat ekstensi mysql berjalan baik di PHP, copy libmysql.dll yang disediakan dariC:\PHP\libmysql.dll ke C:\WINDOWS\system32\.

Buka Command Prompt dan ketik perintah berikut untuk menginstall paket PEAR yang di-bundle:
cd C:\PHP
go-pear.bat

Gunakan nilai baku pada waktu menginstall PEAR, cukup tekan saja ENTER untuk menerima.
Berikut contoh output:

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : C:\PHP
 2. Temporary directory for processing            : C:\PHP\tmp
 3. Temporary directory for downloads             : C:\PHP\tmp
 4. Binaries directory                            : C:\PHP
 5. PHP code directory ($php_dir)                 : C:\PHP\pear
 6. Documentation directory                       : C:\PHP\docs
 7. Data directory                                : C:\PHP\data
 8. User-modifiable configuration files directory : C:\PHP\cfg
 9. Public Web Files directory                    : C:\PHP\www
10. Tests directory                               : C:\PHP\tests
11. Name of configuration file                    : C:\WINDOWS\pear.ini
12. Path to CLI php.exe                           : C:\PHP\.

1-12, 'all' or Enter to continue:
Beginning install...
Configuration written to C:\WINDOWS\pear.ini...
Initialized registry...
Preparing to install...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar...

installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar.
..
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.2
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

** WARNING! Old version found at C:\PHP, please remove it or be sure to use the
new c:\php\pear.bat command

The 'pear' command is now at your service at c:\php\pear.bat

** The 'pear' command is not currently in your PATH, so you need to
** use 'c:\php\pear.bat' until you have added
** 'C:\PHP' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

http://pear.php.net/faq.php
http://pear.php.net/manual/

Thanks for using go-pear!

* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under C:\PHP\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

Press any key to continue . . .

Setup Sebuah Proyek

Untuk setup proyek symfony lihat Mengintegrasikan Symfony dengan Eclipse PDT.

Menjalankan Symfony

Saatnya menyiapkan Apache agar bisa melayani aplikasi symfony. Konfigurasi apache terletak di C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf. Pada tahap ini dan selanjutnya, Saya mengasumsikan proyek anda terletak di C:\Project\myproject dan librari symfony terletak di C:\Project\symfony.

Konfigurasi Apache HTTPD agar Mengenali Skrip PHP

Cari konfigurasi Dynamic Shared Object (DSO) Support, kemudian tambahkan konfigurasi berikut (tambahkan hanya dalam komentar BEGIN s/d END):

#LoadModule version_module modules/mod_version.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so

### BEGIN ADD ###

# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"

### END ADD ###
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

Tambahkan index.php sebagai DirectoryIndex, cari:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

Ubah menjadi:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
Konfigurasi Modul Apache

Saat ini module apache yang dibutuhkan baru mod_rewrite, cari:

#LoadModule rewrite_module modules/mod_rewrite.so

Dan hapus komentar dari baris tersebut menjadi:

LoadModule rewrite_module modules/mod_rewrite.so

Jika anda membutuhkan modul yang lain, aktifkan modul yang diinginkan sesuai yang diperlukan.

Setup Virtual Host

Untuk mendukung virtual host, tambahkan baris berikut ke akhir konfiurasi apache:

### all vhost configurations
Include conf/myconf/*.conf

Konfigurasi Apache selesai. Sekarang saatnya membuat konfigurasi virtual host untuk aplikasi symfony–myproject. Buat file myproject.conf dan letakkan di C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\:

# C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\myproject.conf
<VirtualHost *:80>
    ServerAdmin admin@myproject.localhost
    #ServerName myproject.localhost
    #ServerAlias www.myproject.localhost
    ErrorLog "logs/myproject.localhost-error.log"
    CustomLog "logs/myproject.localhost-access.log" common
    DocumentRoot "C:/Project/myproject/web"
<Directory "C:/Project/myproject/web">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>
<Directory "C:/Project/symfony/data/web/sf">
        AllowOverride All
        Allow from all
</Directory>
    Alias /sf "C:/Project/symfony/data/web/sf"
</VirtualHost>

Tambahkan konfigurasi lain, semisal untuk PHPMyAdmin. File-file PHPMyAdmin dapat diletakkan di C:\Project\phpmyadmin:

# C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\phpmyadmin.conf
<Directory "C:/Project/phpmyadmin">
    AllowOverride All
    Allow from all
</Directory>

Alias /phpmyadmin "C:/Project/phpmyadmin"
Jelajah Aplikasi Anda

Restart web server Apache httpd, buka Command Prompt, ketik:
net stop Apache2.2
net start Apache2.2

Sekarang buka browser anda dan pergi ke:
http://localhost/frontend_dev.php

, , ,

4 Comments

A Newbie Guide for Symfony

Note: This tutorial using Windows Operating System.

Webserver, PHP, and MySQL Instalation

Webserver: Apache HTTPD

For a webserver, try Apache HTTPD (http://httpd.apache.org), download the latest version (2.2.x) and install. After the instalation is finished, browse to:

http://localhost

And it say “It works!”, then the apache installation is done, next we will configure the httpd configuration to be able to browse the symfony application.

Database: MySQL

MySQL database can be found here (http://dev.mysql.com/downloads/). For the client you can use MySQL GUI Tools which can be downloaded at the same location. Or, use the web based client such as PHPMyAdmin (http://www.phpmyadmin.net/home_page/downloads.php).

PHP

Download PHP at http://www.php.net/downloads.php. Usually, the PHP Windows binary package come in an archived or an installer packaging. Download the archived package for version 5.2.x and extract to C:\PHP for example.

Now the time to prepare the php.ini, the sample configuration for PHP already included in the archive–php.ini-dist and php.ini-recommended–for this time, I assumed we are using php.ini-dist, just copy this file and rename to php.ini.

We need to adjust several php configuration, so now use your favorite text editor–such as Notepad++–to edit the php.ini:

If necessary, adjust the include path, locate this line (line 476):

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Change to:

; Windows: "\path1;\path2"
include_path = ".;C:\PHP\PEAR"

Adjust the extension directory, locate this line (line 491):

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

Change to:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\PHP\ext\"

Enable needed extensions, locate this line (line 604):

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

You can enable mbstring, mysql, pdo, pdo_mysql and another extensions may be needed for your project such as gd2 by removing the comment (;–semicolon) preceding each line.
Also, you can add the xdebug (http://www.xdebug.org/download.php) extension and place in C:\PHP\ext\php_xdebug.dll and add the following line after previous configuration:

zend_extension_ts=C:\PHP\ext\php_xdebug.dll

To make mysql extension working in PHP, copy the supplied libmysql.dll from C:\PHP\libmysql.dll to C:\WINDOWS\system32\.

Open a Command Prompt and type the following command to install the bundled PEAR package:
cd C:\PHP
go-pear.bat

Accept the default value while installing PEAR, simply press ENTER to accept.
Here are the sample output:

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : C:\PHP
 2. Temporary directory for processing            : C:\PHP\tmp
 3. Temporary directory for downloads             : C:\PHP\tmp
 4. Binaries directory                            : C:\PHP
 5. PHP code directory ($php_dir)                 : C:\PHP\pear
 6. Documentation directory                       : C:\PHP\docs
 7. Data directory                                : C:\PHP\data
 8. User-modifiable configuration files directory : C:\PHP\cfg
 9. Public Web Files directory                    : C:\PHP\www
10. Tests directory                               : C:\PHP\tests
11. Name of configuration file                    : C:\WINDOWS\pear.ini
12. Path to CLI php.exe                           : C:\PHP\.

1-12, 'all' or Enter to continue:
Beginning install...
Configuration written to C:\WINDOWS\pear.ini...
Initialized registry...
Preparing to install...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar...

installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar.
..
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.2
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

** WARNING! Old version found at C:\PHP, please remove it or be sure to use the
new c:\php\pear.bat command

The 'pear' command is now at your service at c:\php\pear.bat

** The 'pear' command is not currently in your PATH, so you need to
** use 'c:\php\pear.bat' until you have added
** 'C:\PHP' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

http://pear.php.net/faq.php
http://pear.php.net/manual/

Thanks for using go-pear!

* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under C:\PHP\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

Press any key to continue . . .

Setup a Project

For a symfony project setup see Integrating Symfony into Eclipse PDT.

Running Symfony

Now its time to prepare Apache to be able to browse symfony application. The configuration file for Apache is located at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf. In this point forward, I assumed your project is located at C:\Project\myproject and the symfony library is located at C:\Project\symfony.

Make Apache HTTPD Understands PHP scripts

Locate the Dynamic Shared Object (DSO) Support configuration, and add the following configuration (add only in comment block):

#LoadModule version_module modules/mod_version.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so

### BEGIN ADD ###

# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"

### END ADD ###
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

Add index.php as DirectoryIndex, locate:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

Change to:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
Configuring Apache Modules

At this time the only needed apache module is mod_rewrite, locate:

#LoadModule rewrite_module modules/mod_rewrite.so

And remove the comment from the line:

LoadModule rewrite_module modules/mod_rewrite.so

If you need another module, enable the corresponding module as you need.

Setup a Virtual Host

To support a virtual host, add the following lines to the end of the configuration file:

### all vhost configurations
Include conf/myconf/*.conf

You’re done with your httpd configuration. Now we can create the virtual host configuration for symfony application–myproject. So create myproject.conf and place it in C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\:

# C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\myproject.conf
<VirtualHost *:80>
    ServerAdmin admin@myproject.localhost
    #ServerName myproject.localhost
    #ServerAlias www.myproject.localhost
    ErrorLog "logs/myproject.localhost-error.log"
    CustomLog "logs/myproject.localhost-access.log" common
    DocumentRoot "C:/Project/myproject/web"
<Directory "C:/Project/myproject/web">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>
<Directory "C:/Project/symfony/data/web/sf">
        AllowOverride All
        Allow from all
</Directory>
    Alias /sf "C:/Project/symfony/data/web/sf"
</VirtualHost>

Add another configuration, for instance PHPMyAdmin. PHPMyAdmin files can be placed in C:\Project\phpmyadmin:

# C:\Program Files\Apache Software Foundation\Apache2.2\conf\myconf\phpmyadmin.conf
<Directory "C:/Project/phpmyadmin">
    AllowOverride All
    Allow from all
</Directory>

Alias /phpmyadmin "C:/Project/phpmyadmin"
Browse your application

Restart the httpd web server, open Command Prompt, type:
net stop Apache2.2
net start Apache2.2

Now open your browser and goto:
http://localhost/frontend_dev.php

, , , ,

Leave a comment

Symfony 1.2: sfDbConfigPlugin, a sfConfig Counterpart

Symfony has a file based configuration, and with sfDbConfigPlugin, it can handle a database based configuration.

sfDbConfigPlugin provide the following feature:

sfDbConfig class

sfDbConfig class provide a counterpart methods of sfConfig class:

sfDbConfig::set('MYSETTING::TEST', 'test value'); // set the value
sfDbConfig::get('MYSETTING::TEST', 'default');    // get the value, return 'default' if not defined
$exist = sfDbConfig::has('MYSETTING::TEST');      // check if a configuration exist
sfDbConfig::remove('MYSETTING::TEST');            // remove a configuration
Override a YAML configuration

We can easily override a YAML configuration, for example we have a configuration:

// app.yml
all:
  my_setting:
    setting1:                        test

To override the above configuration, we can define a sfDbConfig configuration named OVERRIDE::app_my_setting_setting1 and provide the overidden value.

Also we can define which environment will be overridden by specifying the environment before the configuration name, so it becomes OVERRIDE::prod:app_my_setting_setting1.

sfDbConfig configuration can be altered any time with the included admin interface.

db-config-edit

Instalation and Configuration
  1. Download the plugin here, currently only available for symfony 1.2.
  2. Install and enable the plugin.
  3. Rename project/plugins/sfDbConfigPlugin/config/schema.yml.sample to schema.yml.
  4. Rebuild model, form, filter, and sql, then insert generated sql to database.
  5. Enable sfDbConfigAdmin module in settings.yml so we can define and alter a configuration.
  6. Enable sfDbConfig module so we can clear the configuration override cache by navigating to an url /reload-config-override.

, ,

Leave a comment