The Passioned Mobile Developer Interested Backend Developer Excited Graphic Designer

Installing Phalcon on Mac OS X El Capitan without package manager

Phalcon is a full-stack PHP framework delivered as a C-extension. It's a really performant framework and I started to work with it while I was a student.

If you are using any package manager like Homebrew or Macport, it's pretty easy to install, you will `tap` or `brew` the right command (following the installation tips in their documentation).

But if for any reason you do not want to use package managers, you will have to install it from the sources. The installation require many developer tools running on your machine, and this tutorial gives you the different steps for a ready-to-go installation.

I. The classic web environment: MAMP

If you are installing Phalcon, you are probably going to make some web development right? So you should make a proper install of the classic tools: apache and php.

Fortunately, El Capitan comes with integrated php and apache versions (php 5.5.30 and apache 2.4.16 while writing) which are enough for phalcon installation. You can find your php and apache versions by running these commands:

$ php -v
PHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

$ httpd -v
Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26

If you want to upgrade them, there is tons of tutorials, but here we will use their integrated installation.

Ensure that apache is running with the following command:

$ sudo apachectl start

II. xCode and its command line tool

xCode is Apple's IDE providing a suit development tools for iOS and OSX development. It contain many tools (gcc, make, ...) you need as a developer and you can download it for free, but it's quite heavy and could be a real challenge for your nerves.

If you can't install it, get its command line tool by running the following command in your terminal:

$ xcode-select --install

You can check that you successfully installed it with the command:

$ xcode-select -p

III. Autoconf

Autoconf is an extension of macros for helping your shell configuring some installation, Phalcon needs it and you have to install it. It can be done really easily by running the following commands:

#step1: download and extract the package
$ curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
$ tar xzf autoconf-latest.tar.gz

#step2: go to your extracted folder and launch your configuration
$ cd autoconf-*
$ ./configure --prefix=/usr/local

#step3: install autoconf
$ make
$ sudo make install

IV. Pcre

Perl Compatible Regular Expressions (or pcre) is a Perl library (also) required for installing Phalcon, it's not really hard to install as soon as you get all the steps:

  • First, download the latest version on Source Forge
  • Extract it with the terminal command:

$ tar -xzvf pcre-*.**.tar.gz

(notice that \*.** should be replaced by the downloaded version)

$ cd pcre-*.**
$ ./configure --prefix=/usr/local/pcre-*-**
$ make
$ sudo make install

  • And finally, you will have to create a symbolic link of your pcre.h file located in your pcre directory. El Capitan comes with its new System Integrity Protection (SIP) which prevent you from altering the /usr/local directory. So in order to perform our symbolic link, we will have to disarm the SIP
System Integrity Protection (SIP, sometimes referred to as >rootless) is a security feature of OS X El Capitan, if you decide to disarm it, be aware of it

To disarm the SIP, follow these steps:

  1. Reboot your apple computer in recovery mode by holding Command + R
  2. Open the terminal (Utilities > terminal)
  3. Enter the following command : `csrutil disable`
  4. Restart your computer

After you disabled it, you will be able to create your symbolic link by running the following command:

$ sudo ln -s /usr/local/pcre-*-**/include/pcre.h /usr/include/pcre.h

V. Phalcon installation

You are now ready to install Phalcon!

  • First, download the package with the following commands:

$ git clone --depth=1 git://github.com/phalcon/cphalcon.git

  • Go to the building directory and install it:

$ cd cphalcon/build
$ sudo ./install

$ git clone --depth=1 git://github.com/phalcon/cphalcon.git

  • Once the installation is finished, add the phalcon extension to your php.ini (create it from php.ini.default if necessary):

$ cd /etc/
#copy php.ini.default if there is no php.ini file
$ cp php.ini.default php.ini
$ sudo nano php.ini

  • go around the line 886 and add the phalcon.so extension

extension=phalcon.so #phalcon php extension

  • Save and ensure that phalcon.so exists by searching it in your php extension directory (by default: /usr/lib/php/extensions/no-debug-non-zts-20121212/):

  • The last step is to ensure you have some useful (and necessary) modules activated in your php.ini (locate them and uncomment them if they are commented out):

$ LoadModule authz_core_module libexec/apache2/mod_authz_core.so

$ LoadModule authz_host_module libexec/apache2/mod_authz_host.so

$ LoadModule include_module libexec/apache2/mod_include.so

$ LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Congratulation! Your Phalcon installation has been done, and you can now enjoy this powerful framework!

I also highly recommend to install the Phalcon Developer Tools which are really useful for deploying your projects.