Standard way for local configuration file in Zend Framework

I’ve read people have talked about local configuration files in Zend Framework.

As of Zend Framework 1.10, multiple configuration files is supported by Zend_Application. Here is the right (standardized) approach:

$application = new Zend_Application(
    APPLICATION_ENV,
    array(
        'config' => array(
            APPLICATION_PATH . '/configs/application.ini',
            APPLICATION_PATH . '/configs/local.ini'
        )
    )
);

I hope this small tip becomes spread instead of alternative approaches, that most of the times overload your Zend application.

Posted in php, Uncategorized | Leave a comment

Fixing Mysql sock issue when using PHP on Snow Leopard

If you followed my tutorial pages about installing Apache + PHP + missing extensions and installing PEAR previously, maybe you are interested to look at this fix.

Installing MySQL is easy. Just go to MySQL Download page and grab the x86_64 DMG file.
Follow the installation instructions and do not forget to also install StartupItem.

As soon as you attempt to connect to MySQL, this error would popup for you:

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file  or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...

To fix that, the only necessary change is actually to create a symbolic link to the same location PHP is looking at (I would recommend to update php.ini config to point to the right file).

$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Restart your Apache and live happy!

Posted in Uncategorized | 1 Comment

Installing PEAR on built-in PHP of Snow Leopard

If you followed my last blog post, now you have your PHP environment with missing extensions compiled and loaded. But we still lack of PEAR support.

This post has the intention to explain how to install PEAR on your default Snow Leopard PHP binary.

First open your Terminal and type these commands:

$ cd /usr/local
$ curl http://pear.php.net/go-pear.phar > go-pear.phar
$ php go-pear.phar

It will open a configuration panel. Type each number and define the correct directory. Here is my final configuration:

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)                   : /usr/local/pear
2. Temporary directory for processing            : /tmp/pear/install
3. Temporary directory for downloads             : /tmp/pear/install
4. Binaries directory                            : /usr/local/bin
5. PHP code directory ($php_dir)                 : /usr/local/pear/share/pear
6. Documentation directory                       : /usr/local/pear/docs
7. Data directory                                : /usr/local/pear/data
8. User-modifiable configuration files directory : /usr/local/pear/cfg
9. Public Web Files directory                    : /usr/local/pear/www
10. Tests directory                               : /usr/local/pear/tests
11. Name of configuration file                    : /Users/gblanco/.pearrc

Install PEAR and it would likely trigger that it could not update the php.ini file. We will fix that manually now.

Open /private/etc/php.ini and locate the include_path line. If it is not commented, update it, otherwise, expose this variable through this line:

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

That’s it! Now you have PEAR configured with your built-in PHP. You’re now able to install PEAR packages without any troubles.

Posted in pear, php | 1 Comment

Getting Snow Leopard built-in MAMP to work smoothly

Considering you are here, I can assume you are a desperate folk looking for a possible solution to make built-in MAMP work perfectly using the default packages that comes with clean Snow Leopard installation. Trust me, I was feeling like you are now a few hours before I start this post.

Here you’ll see how to enable Apache2, turn PHP 5.3 available on server and also install missing PECL extensions of PHP, such as Imagick (ImageMagick), Xdebug, APC and Memcache.

Before we start I would assume you have Xcode and Homebrew installed.
Xcode 4 is paid, but you can install 3rd version by using the DVD that came with your Mac. It’s free! =)

Enabling Web Sharing (Web Server)

This is the first step to be done, which is turn Apache2 ON to make your machine responds to HTTP requests. To do that, open your System Preferences > Sharing. Then, turn on Web Sharing:

That’s it. You already have Apache2 running on your system. Now let’s enable PHP.

Enabling PHP on Web Server

To enable PHP in Apache, you have to open /private/etc/apache2/httpd.conf file with root privileges. Locate the line:

#LoadModule php5_module        libexec/apache2/libphp5.so

Remove the #.
Now, locate the line:

DirectoryIndex index.html

Edit it to be:

DirectoryIndex index.php index.html

Now, save and exit.
Go to System Preferences > Sharing again and turn Web Sharing OFF then ON.

Testing Apache2 + PHP integration

You can use Terminal for this one. We are going to create a phpinfo file, which displays all PHP configuration that is exposed to user land. In Terminal:

$ cd ~/Sites
$ vim info.php

Now press I (enable Insert mode in VIm) and type:

<?php phpinfo(); ?>

Now press Esc, then :wq <Enter>
Esc leaves Insert mode of VIm and enter in File manipulation mode. W means write and Q means quit.

Access your page, it should be something similar to http://localhost/~<username>/info.php
You should see a page similar to this one:

If you scroll down, you will see at Date extension a big warning telling you haven’t chosen a locale of your server. We are going to fix this now. On Terminal, type this:

$ sudo cp /private/etc/php.ini.default /private/etc/php.ini

Now open this file for edit. Locate this line:

;date.timezone=

Remove the ; and place whatever timezone you are at. Here is the list of available timezones. In my case, I’m in America/Sao_Paulo.

Save the file and reload the server (go to System Preferences > Sharing, then disable and enable Web Sharing. Next time I’ll now explain again. =P). Now refresh the info page and the warning disappeared.

It is now time to install missing extensions on PHP.

Compiling APC on PHP

If you are familiar with PHP from other environments, you may think it is simply do a pecl install. The problem is that Snow Leopard doesn’t come with pecl or pear available by default. While pear is possible to be installed manually, pecl isn’t. So we need to make the everything the hard way.

Download the latest stable APC package available at: http://pecl.php.net/package/APC
Decompress the folder.

Install required packages for APC. That’s where Homebrew comes to rescue us.
Go to your Terminal and type:

$ sudo brew install pcre

It should install PCRE dependency. As soon as it finishes, we are allowed to continue to the next step.

Go inside of decompressed folder and on Terminal run these commands:

$ phpize
$ CFLAGS='-arch x86_64' ./configure
$ make
$ sudo make install

Please remember these 4 commands. We will use them to compile other extensions.

Now we need to enable the APC on PHP. Open /private/etc/php.ini in edit mode.
Locate a similar line and add this:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so

Save file and reload your server. Info should not display that APC is correctly configured!

Compiling Memcache on PHP

We are going to make the same process that we did with APC.
First download the latest stable package available at: http://pecl.php.net/package/memcache
Here are the steps I’ve done on my personal machine:

$ mv ~/Downloads/memcache-* ~/src
$ cd ~/src
$ tar xvf memcache-*
$ cd memcache-*
$ phpize
$ CFLAGS='-arch x86_64' ./configure
$ make
$ sudo make install

Now I opened again the /private/etc/php.ini file, located the apc.so line and added on the next line:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/memcache.so

Restarting the web server, my info now displays the Memcache extension loaded on PHP!

Compiling Xdebug on PHP

I followed the same steps that I did with Memcache, grabbing the latest stable package available at: http://pecl.php.net/package/xdebug

Enabling it is a bit different. I opened the /private/etc/php.ini file and added at the end of it:

[xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.file_link_format="txmt://open?url=file://%f&amp;line=%1"
xdebug.remote_enable = On
;xdebug.remote_handler = 'dbgp'
;xdebug.remote_handler = 'gdb'
;xdebug.remote_mode = jit
xdebug.remote_autostart = 1

Reloaded my server and voilà! It worked!

Compiling Imagick on PHP

Imagick relies on ImageMagick in order to work. Again we ask help for Homebrew to save our lives.

$ sudo brew install imagemagick

I will install a couple of dependencies, but at the end we’ll have ImageMagick working. Now we can get back to our tedious work of phpize, configure, make, make install…
Grab the latest stable package available at: http://pecl.php.net/package/imagick
Now, execute the commands:

$ mv ~/Downloads/imagick-* ~/src
$ cd ~/src
$ tar xvf imagick-*
$ cd imagick-*
$ phpize
$ CFLAGS='-arch x86_64' ./configure
$ make
$ sudo make install

Finally, open the /private/etc/php.ini file, located the memcache.so line and added on the next line:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so

Reload your server and have fun! =)

Posted in apache, apc, development, imagemagick, memcache, php, snow leopard, xdebug | Tagged , , , , , , , | 4 Comments

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Posted in Uncategorized | 1 Comment