Installing symfony via PEAR on Leopard

This documentatoin is still pre-alpha. If you find any error on this tutorial, please email me. Visit projects.


Installing PEAR and symfony

This article assumes you read my “Install PHP and MySQL via MacPorts on Mac OS X 10.5 Leopard”. This article tries to make a web server for a symfony project locally.

We install symfony via PEAR and make it work with the Ajax tutorial on symfony website.

What is PEAR?

Just read the manual.

Installing PEAR

Leopard, unlike its predecessors, doesn’t have PEAR pre-installed. You need to install it manually. We don’t use MacPorts here. PEAR also has an excellent documentatoin. Visit PEAR manual.

curl http://pear.php.net/go-pear > go-pear.php

This step downloads a file need to install pear. The file will be located under your home folder, and the file name is “go-pear.php”. (Note: We don’t use go-pear.org because go-pear.org is not longer available.)

sudo php -q go-pear.php

Follow the instruction. Default setting doesn’t cause any problem. Just your personal preference. (But, I installed the tool under /usr/local/bin. Concerning why, read the Dan Benjamin’s article.)

Now your have pear command tool installed.

How to See Your Configuration

Everytime you come across a setting problem, it’s always useful to check your currnt configuration. You can check your pear configuration by running

pear config-show

As I would like to install beta packages as well as stable ones, I set preferred package state to be beta.

You can do so by running

sudo pear config-set preferred_state beta

Here’s what I have:

Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          /usr/local/bin
PEAR documentation directory   doc_dir          /usr/local/share/pear/docs
PHP extension directory        ext_dir          ./
PEAR directory                 php_dir          /usr/local/share/pear
PEAR Installer cache directory cache_dir        /var/folders/qo/qoHKwm05H3eGEek47+j0Hk+++TI/-Tmp-//pear/cache
PEAR data directory            data_dir         /usr/local/share/pear/data
PEAR Installer download        download_dir     /usr/local/temp/download
directory
PHP CLI/CGI binary             php_bin          /usr/bin/php
php.ini location               php_ini          <not set>
PEAR Installer temp directory  temp_dir         /usr/local/temp
PEAR test directory            test_dir         /usr/local/share/pear/tests
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  beta
Unix file mask                 umask            22
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          /usr/local/bin/gpg
Signature Key Directory        sig_keydir       /private/etc/pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         /Users/takaaki/.pearrc
System Configuration File      Filename         /private/etc/pear.conf

Modifying php.ini to Recoginize PEAR installation

Now to make pear work with PHP, you need to add the pear path in your PHP include path by editing php.ini file. The path you need to include is php_dir, in my case /usr/local/share/pear.

mate /opt/local/etc/php.ini

First of all, though not mandatory, but it is highly recommended that you not use magic quotes in PHP. To turn it off, look for “magic_quotes_gpc = On”, which is around line 440. And change it to

magic_quotes_gpc = Off

Next, add th PEAR directory path to include path. Find “include_path”, which is around line 470. Add your PEAR directory, which you can find by running pear config-show and remove the semicolumn (;) at the beginning of the line.

My one looks like this:

include_path = ".:/usr/local/share/pear"

Check if PEAR is recongized with your PHP script

Edit test.php file to check if PHP can work with PEAR.

Open test.php.

mate /opt/local/apache2/htdocs/

Write the following and save it.

<?php

if (require 'PEAR.php') {
    echo "You can now use PEAR with PHP!";
} else {
    echo "PEAR is not recoginzed with your PHP.";
}

?>

Visit localhost/test.php. If you get an error, include_path may very well be wrong.

Installing symfony

Follow the symfony official guide. Find the “PEAR installation”

After installation, let’s check if symfony is properly installed or not. Type the following to get the version number of symfony.

symfony -V

(Note: this is capital/large V. symfony -v won’t work.)

If you see the version number of symfony, symfony is installed successfuly.

Set up a Web Server for symfony

There are three ways to install symfony: a) The sandbox, b) Source Download and c) PEAR instllation. We are using PEAR installation approach. We are going to have a web server for a symfony project running. For other instllation, visit symfony’s documentation.

Our aim is to set up a webserver on a Mac for the Easy Ajax Tutorial on symfony documentaion.

Let’s make several settigs clear. Always keep what you try to do in mind:

  • We make a project called “sfdemo” in the folder named “sfdemo” under your user’s Sites folder.
  • Therefore, your path to the project is /Users/[yourusername]/Sites/sfdemo.
  • Symfony projects require a setting where /web under the project directory is set to web root path. (So, browsers only access to /web directory.)
  • That is, Apache needs to access /Users/[yourusername]/Sites/sfdemo/web when your broweser points http://localhost. (Note: Don’t add .com in the URL.)

Before creating a symfony project, we change Apache configuration file (httpd.conf) so that our project works under localhost.

Open Apache configuration file (httpd.conf).

    mate /opt/local/apache2/conf/httpd.conf

Add the following at the beginning. Replace [yourusername] with a real one. Also replace “/usr/local/share/pear/data” with your PEAR data directory path. You can find your by running pear config-show.

    <VirtualHost localhost:80>
    ServerName localhost
    DocumentRoot "/Users/[yourusername]/Sites/sfdemo/web"
    DirectoryIndex index.php
    Alias /sf /usr/local/share/pear/data/symfony/web/sf
    <Directory "/usr/local/share/pear/data/symfony/web/sf">
    AllowOverride All
    Allow from All
    </Directory>
    <Directory "/Users/[yourusername]/Sites/sfdemo/web">
    AllowOverride All
    Allow from All
    </Directory>
    </VirtualHost>

Save the file and restart Apache web server.

    sudo apachectl restart

You will see a warning as the following.

[warn] VirtualHost localhost:80 overlaps with VirtualHost localhost:80, the first has precedence, perhaps you need a NameVirtualHost directive

This means that you already have a setting for localhost:80 in your Apache configuration file. As this is a warning, not an error, let’s ingnore it for a second. You can tweak the configuration anytime when you learned more about Apache.

Let’s make a symfony project.

First, open Terminal and move to the Sites folder.

cd ~/Sites

And create a directory called “sfdemo” and move to the folder.

mkdir sfdemo
cd sfdemo

Create a project called “sfdemo” and make an application called “app” and a module called “cart”. What each command does is not explained here. Visit the tutorial.

symfony init-project sfdemo
symfony init-app app
symfony init-module app cart

Visit localhost/cart. If everything works fine, you will see a symfony page, saying “Module " cart" created”.

References

Comments

Great post. Congratulations.

Great post. Congratulations. And thank you :)

This was extremely helpful.

This was extremely helpful. Thanks so much!

Post new comment

The content of this field is kept private and will not be shown publicly.