Phalcon needs PHP to run. Its loosely coupled design allows developers to install Phalcon and use its functionality without additional extensions. Certain components have dependencies to other extensions. For instance using database connectivity will require the php_pdo
extension. If your RDBMS is MySql/MariaDb or Aurora databases you will need the php_mysqlnd
extension also. Similarly, using a PostgreSql database with Phalcon requires the php_pgsql
extension.
Phalcon is designed to use as little resources as possible, while offering high performance. Although we have tested Phalcon in various low end environments, (such as 0.25GB RAM, 0.5 CPU), the hardware that you will choose will depend on the your application needs.
Our website and blog (as well as other sites) are hosted on an Amazon VM with 512MB RAM and 1 vCPU.
- PHP >= 5.5
You should always try and use the latest version of Phalcon and PHP as both address bugs, security enhancements as well as performance. PHP 5.5 will be deprecated in the near future, and Phalcon 4 will only support PHP 7.
Phalcon need the following extensions to run (minimal):
curl
gettext
gd2
(to use thePhalcon\Image\Adapter\Gd
class)libpcre3-dev
(Debian/Ubuntu),pcre-devel
(CentOS),pcre
(macOS)json
mbstring
pdo_*
fileinfo
openssl
- PDO Extension as well as the relevant RDBMS specific extension (i.e. MySQL, PostgreSql etc.)
- OpenSSL Extension
- Mbstring Extension
- Memcache, Memcached or other relevant cache adapters depending on your usage of cache
Since Phalcon is compiled as a PHP extension, its installation is somewhat different than any other traditional PHP framework. Phalcon needs to be installed and loaded as a module on your web server.
To install Phalcon on Linux, you will need to add our repository in your distribution and then install it.
Add the repository to your distribution:
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash
or
curl -s https://packagecloud.io/install/repositories/phalcon/nightly/script.deb.sh | sudo bash
This only needs to be done only once, unless your distribution changes or you want to switch from stable to nightly builds.
To install Phalcon you need to issue the following commands in your terminal:
sudo apt-get update
sudo apt-get install php5-phalcon
sudo apt-get update
sudo apt-get install php7.0-phalcon
If you do not wish to use our repository at packagecloud.io, you can always use the one offered by Ondřej Surý.
Installation of the repo:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
and Phalcon:
sudo apt-get install php-phalcon
Add the repository to your distribution:
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.rpm.sh | sudo bash
or
curl -s https://packagecloud.io/install/repositories/phalcon/nightly/script.rpm.sh | sudo bash
This only needs to be done only once, unless your distribution changes or you want to switch from stable to nightly builds.
To install Phalcon you need to issue the following commands in your terminal:
sudo yum update
sudo yum install php56u-phalcon
sudo yum update
sudo yum install php70u-phalcon
Remi Collet maintains an excellent repository for RPM based installations. You can find instructions on how to enable it for your distribution here.
Installing Phalcon after that is as easy as:
yum install php56-php-phalcon3
Additional versions are available both architecture specific (x86/x64) as well as PHP specific (5.5, 5.6, 7.x)
A port is available for FreeBSD. To install it you will need to issue the following commands:
pkg_add -r phalcon
export CFLAGS="-O2 --fvisibility=hidden"
cd /usr/ports/www/phalcon
make install clean
An overlay for installing Phalcon can be found here https://github.com/smoke/phalcon-gentoo-overlay
On a macOS system you can compile and install the extension with brew
, macports
or the source code:
- PHP 5.5.x/5.6.x/7.0.x/7.1.x development resources
- XCode
brew tap homebrew/homebrew-php
brew install php55-phalcon
brew install php56-phalcon
brew install php70-phalcon
brew install php71-phalcon
sudo port install php55-phalcon
sudo port install php56-phalcon
Edit your php.ini file and then append at the end:
extension=php_phalcon.so
Restart your webserver.
To use Phalcon on Windows, you will need to install the phalcon.dll. We have compiled several DLLs depending on the target platform. The DLLs can be found in our download page.
Identify your PHP installation as well as architecture. If you download the wrong DLL, Phalcon will not work. phpinfo()
contains this information. In the example below, we will need the NTS version of the DLL:
The available DLLs are:
Architecture | Version | Type |
---|---|---|
x64 | 7.x | Thread safe |
x64 | 7.x | Non Thread safe (NTS) |
x86 | 7.x | Thread safe |
x86 | 7.x | Non Thread safe (NTS) |
x64 | 5.6 | Thread safe |
x64 | 5.6 | Non Thread safe (NTS) |
x86 | 5.6 | Thread safe |
x86 | 5.6 | Non Thread safe (NTS) |
x64 | 5.5 | Thread safe |
x64 | 5.5 | Non Thread safe (NTS) |
x86 | 5.5 | Thread safe |
x86 | 5.5 | Non Thread safe (NTS) |
Edit your php.ini file and then append at the end:
extension=php_phalcon.dll
Restart your webserver.
Compiling from source is similar to most environments (Linux/macOS).
- PHP 5.5.x/5.6.x/7.0.x/7.1.x development resources
- GCC compiler (Linux/Solaris/FreeBSD) or Xcode (macOS)
- re2c >= 0.13
- libpcre-dev
You can install these packages in your system with the relevant package manager. Instructions for popular linux distributions are below:
sudo apt-get install php5-dev libpcre3-dev gcc make
sudo zypper install php5-devel gcc make
sudo yum install php-devel pcre-devel gcc make
We first need to clone Phalcon from the Github repository
git clone https://github.com/phalcon/cphalcon
and now build the extension
cd cphalcon/build
sudo ./install
You will now need to add extension=phalcon.so
to your PHP ini and restart your web server, so as to load the extension.
# Suse: Add a file called phalcon.ini in /etc/php5/conf.d/ with this content:
extension=phalcon.so
# CentOS/RedHat/Fedora: Add a file called phalcon.ini in /etc/php.d/ with this content:
extension=phalcon.so
# Ubuntu/Debian with apache2: Add a file called 30-phalcon.ini in /etc/php5/apache2/conf.d/ with this content:
extension=phalcon.so
# Ubuntu/Debian with php5-fpm: Add a file called 30-phalcon.ini in /etc/php5/fpm/conf.d/ with this content:
extension=phalcon.so
# Ubuntu/Debian with php5-cli: Add a file called 30-phalcon.ini in /etc/php5/cli/conf.d/ with this content:
extension=phalcon.so
Phalcon automatically detects your architecture, however, you can force the compilation for a specific architecture:
cd cphalcon/build
# One of the following:
sudo ./install --arch 32bits
sudo ./install --arch 64bits
sudo ./install --arch safe
If the automatic installer fails you can build the extension manually:
git clone https://github.com/phalcon/cphalcon
# cd cphalcon/build/php5/32bits
cd cphalcon/build/php5/64bits
# NOTE: for PHP 7 you have to use
# cd cphalcon/build/php7/32bits
# or
# cd cphalcon/build/php7/64bits
make clean
phpize --clean
export CFLAGS="-O2 --fvisibility=hidden"
./configure --enable-phalcon
make
make install
If you have specific php versions running:
git clone https://github.com/phalcon/cphalcon
# cd cphalcon/build/php5/32bits
cd cphalcon/build/php5/64bits
# NOTE: for PHP 7 you have to use
# cd cphalcon/build/php7/32bits
# or
# cd cphalcon/build/php7/64bits
make clean
/opt/php-5.6.15/bin/phpize --clean
export CFLAGS="-O2 --fvisibility=hidden"
./configure --with-php-config=/opt/php-5.6.15/bin/php-config --enable-phalcon
make
make install
You will now need to add extension=phalcon.so
to your PHP ini and restart your web server, so as to load the extension.
You can create a small script in your web server root that has the following in it:
<?php
phpinfo();
and load it on your web browser. There should be a section for Phalcon. If there is not, make sure that your extension has been compiled properly, that you made the necessary changes to your php.ini
and also that you have restarted your web server.
You can also check your installation from the command line:
php -r 'print_r(get_loaded_extensions());'
This will output something similar to this:
Array
(
[0] => Core
[1] => libxml
[2] => filter
[3] => SPL
[4] => standard
[5] => phalcon
[6] => pdo_mysql
)
You can also see the modules installed using the CLI:
php -m
Note that in some Linux based systems, you might need to change two php.ini
files, one for your web server (Apache/Nginx), and one for the CLI. If Phalcon is loaded only for say the web server, you will need to locate the CLI php.ini
and make the necessary additions for the module to be loaded.