Jonny Paylor

By Jonny

Web Development

How to install Phalcon PHP Framework with MAMP on OSX

Phalcon is a growing PHP framework, set to become one of the most significant for PHP developers in the next few years.

How to install Phalcon PHP Framework with MAMP on OSX

A recent survey by SitePoint revealed that Phalcon was regarded as one of the “most promising frameworks for 2014”.

Not only is Phalcon a brilliant framework overall, one of the biggest reasons for its recent rise in popularity is the huge performance gains it has achieved by implementing the framework as a compiled C extension to PHP. The downside to this approach is Phalcon must be compiled for each computer and server you’d like to use it on, and we found it a little tricky to configure on OSX at first, so we created this step-by-step installation guide based on our own experience.

Prerequisites

The Phalcon source code is hosted on github, so we recommend installing Git on your Mac in order for the “git clone” commands to work when following Phalcon’s installation instructions (though you can download it manually from their github page as an alternative). Git is easy to install for OSX by following the simple instructions at http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Mac

In order to compile source code on OSX you will need GCC compiler installed. If you’ve already compiled something before or if you’ve used Xcode, chances are you probably already have this, if not then the easiest way to get it installed is to use MacPorts or Homebrew. For a tutorial covering this see “Installing GCC on Mac”.

In addition you may also need autoconf, automake, libtool and libiconv. Again, the easiest way to install these is using MacPorts or Homebrew. Alternatively you can download the source code for each library directly from their respective websites, then run ./configure ; make ; sudo make install within their directory in terminal to install them.

1) Make sure MAMP is setup with the PHP version you intend to use

Phalcon will need to be compiled for each version of PHP you decide to use, so we recommend checking MAMP is already running a version you’re happy with.

You can download additional PHP versions on the MAMP website at http://www.mamp.info/en/downloads/index.html

2) Make sure your Mac is referencing MAMP’s php build

One of the main problems you’ll encounter when compiling Phalcon for use with MAMP is that OSX ships with its own version of PHP and this probably doesn’t match the version of PHP you’re running with MAMP.

This can be fixed by overriding OSX’s path to PHP with the version used by MAMP.

  1. Find the path to your MAMP php bin directory. This is usually located within the MAMP folder in Applications:e.g. /Applications/MAMP/bin/php/phpx.x.x/bin
  2. Open Terminal and run the following command: export PATH=/Applications/MAMP/bin/php/phpx.x.x/bin:$PATH
  3. Then run the following command: php -v

This should output the version of PHP that OSX is now referring to. This should match the version of PHP that you are using with MAMP. If this does not work, double-check the directory you used in the “export” command, including checking the casing as this is case-sensitive, and also try quitting and restarting Terminal.

3) Download PHP Source

Phalcon requires the “PHP development resources” which can be obtained by downloading the PHP source code from the PHP website at http://php.net/downloads.php

You will need to download the version of the PHP source that corresponds with the version you’re running with MAMP. Don’t worry if you can’t find the exact build, so long as it’s the same branch of PHP (i.e. PHP 5.5.x or PHP 5.4.x). For example, if you’re running PHP 5.5.3 then downloading php-5.5.9 would be fine.

It doesn’t matter where you download it to, just extract the archive and you should end up with a php-x.x.x directory.

4) Copy the PHP source into your MAMP directory

Copy the contents of the PHP directory you just unarchived into /include/php within your MAMP’s php directory:

      /Applications/MAMP/bin/php/phpx.x.x/include/php
    

(the /include/php directory probably doesn’t already exist, in which case just create it).

5) Configure the PHP source

Using terminal, go into your /include/php directory within your MAMP’s php directory

      cd /Applications/MAMP/bin/php/phpx.x.x/include/php
    

And then run the following:

      ./configure
    

It’ll take a minute or two to configure and should end with “Thank you for using PHP”. One this is done, Phalcon should be ready to compile.

6) Compile Phalcon

Following the instructions on the Phalcon website at http://phalconphp.com/en/download, clone and compile Phalcon

      git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build
sudo ./install
    

Don’t worry if you see a few warnings during this process and wait until you see the message “Thanks for compling Phalcon!”

If you see an error similar to “fatal error: ‘php.h’ file not found”, this is indicating that the PHP source that we configured in step 5 couldn’t be found, so OSX is still referring to the wrong version of PHP or you’ve not completed those steps correctly. Re-trace your steps and try again!

Upon successful completion of this, a phalcon.so extension file will be placed into MAMP’s php directory. All you need to do now is add the phalcon extension file to your php.ini file

TIP!

Not sure where your PHP.ini is located? Create a PHP script with <?php phpinfo() ?> in it, run that from your browser, and look for the value “Loaded Configuration File”. This tells you which php.ini file PHP is using in the context of the web server. (source: http://stackoverflow.com/a/11691791)

7) Restart MAMP and check phpinfo(), you should see “Phalcon” listed.

Now have fun using one of the most promising PHP frameworks of 2014!

Credits: Many thanks to Dan Schultzer for his post “Install phalcon with MAMP” as this got me started and covered most of the process.

Fancy a good ol' chat about the values of marketing to your business?

Drop Us a Line

Post by

Jonny

Jonny

Stay up to date

Insights & Industry News

If you want more expert viewpoints, industry insights and general marketing know-how from Team Extreme, get signed up.