Quick Tutorial: Up and Running with the Fastest PHP Framework on PHP7

Some web developers may not be familiar with Phalcon PHP framework which is written in Zephir, a language mid-way between C and PHP that helps in developing PHP extensions without having to know C. Since Zephir compiles into C, which is what PHP extensions are made of, it’s lets PHP developers create highly optimized modules for their programming language environment without the overhead of learning a completely new language, because Zephir compiles into C, which is what PHP extensions are made of.

Phalcon is incredibly fast as it was an extension written in pure C. Moreover, Phalcon is also good in introducing massive overhead in fixing bugs or inspecting what’s going on under the hood when there are errors are detected. It also took ages to add new features, since developing in C is so much more difficult. Phalcon was rewritten in Zephir in version 2, but Zephir could not compile code to PHP 7 compatible extensions and was left behind in PHP 5 land as PHP 7 was looming on the horizon and announced a dramatic departure from the extension API of PHP 5+.

However, the cost of installing Phalcon was no longer worth it in any way since with our Homestead Improved box up and running and powering all our tutorials, and with PHP 7’s performance advances making up for any kind of speed gains Phalcon may have offered in PHP 5 time, the cost of installing Phalcon was no longer worth it in any way.

The biggest update by far is the fact that Zephir now supports PHP 7, and allows for not only the compilation of Phalcon, but also the compilation of any other Zephir code into PHP 7 as well. You can gain more benefits form compiling into PHP 7 in a jiffy, such as having unparalleled advantages in terms of speed and resource conservation.

Setting it Up

After understanding, what is PHP framework on PHP7, now you may be curious to use it. So, let’s learn on how to set up Phalcon 3 on a PHP 7. This instruction will be specific to an Ubuntu 16.04, but you can use any kind of environment that you like.

Installing Phalcon

sudo apt-get install software-properties-common

sudo apt-add-repository ppa:phalcon/stable

sudo apt-get update

sudo apt-get install php7.0-phalcon

sudo phpenmod -v 7.0 -s ALL phalcon

sudo service php7.0-fpm restart

The second to last command is a shortcut command to enable a PHP extension. The –v flag tells it which PHP version to activate it for (we want only 7.0 here) and which SAPI (command line, FPM, or both – we want both).

There’s one more step which isn’t described in the app’s repo – changing the baseUri in the configuration. You need to go into app/config/config.ini and change baseUri to /, otherwise assets (JS/CSS) will fail to load.