Install multiple version Phalcon

flag Questions

In this particular post, we intend to offer a solution to install multiple versions of Phalcon, PHP and run them on a single web server. The PHP 5.5.x and 5.6.x will be used in here, but you can replace it with other versions. Any servers that support PHP-FPM should be enough but we recommend using the Nginx for the web server. The environment using in this tutorial is Fedora OS - a Linux system.

Preliminary Note

This tutorial will cover the installation of PHP 5.5.x correspoding Phalcon 1.3.x and PHP 5.6.x correspoding Phalcon 2.0.0. We also configuration some Nginx

Installing Nginx

Nginx is an available package in Fedora OS which we can install as follow:

  sudo yum install nginx

Then we create the system startup links for Nginx and start it

  sudo chkconfig nginx on
  sudo service nginx start

Building PHP

Before starting with PHP, we need to install the prerequisites for building PHP5:

  • gcc or some other compiler suite.
  • libc-dev, provides the C standard library, including headers.
  • make, which is the build-management tool PHP uses.
  • autoconf (2.59 or higher) for generating the configure script.
  • automake (1.4 or higher), generates Makefile.in files.
  • libtool, helps us manage shared libraries.
  • bison (2.4 or higher), for generating the PHP parser.
  • (optional) re2c, which is used to generate the PHP lexer. As the git repository already contains a generated lexer you will only need re2c if you wish to make changes to it.

Also you can references to full information here

On Centos/Fedora you can install all these with the following command:

  sudo yum install gcc libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel bison gcc make

Then we need to get its source code. There are two ways to do this: You can either download an archive from PHP’s download page or clone the git repository from Github.

We recommend to checkout out the source code from git, because it provides you an easy way to keep your installation up-to-date and to try your code with different versions. A git checkout is also required if you want to submit patches or pull requests for PHP.

To clone the repository, run the following commands in your terminal:

  sudo mkdir /opt/source && cd /opt/source
  git clone git@github.com:php/php-src.git && cd php-src

By default you will be on the master branch, so if you want to move on a development version, you need to check out the stable branch. For example.

  PHP 5.3:  git checkout PHP-5.3
  PHP 5.4:  git checkout PHP-5.4
  PHP 5.6:  git checkout PHP-5.6
  PHP HEAD: git checkout master 

Before going to the individual build steps do, we must execute some "little" commands for a “default” PHP build. This is only necessary for who builds from git

sudo ./buildconf

The "./buildconf" generates the configuration script. This may take several minutes.

We need to make a directory. In my opinion, I think storing the whole web server in a single directory is the best, so I use /opt here. Open the terminal and type the following command.

  sudo mkdir -p /opt/php-5.6
  sudo mkdir -p /opt/php-5.5

Once the ./configure script is generated you can use it to customize your PHP build. You can list all supported options using --help:

  ./configure --help

The command line above will help list various generic options, which are supported by all autoconf-based configuration scripts. In our example below we'll do a simple configure with PHP-FPM, --prefix is /opt/php-5.6, etc.

Here are some useful settings:

  [...]

  Usage: ./configure [OPTION]... [VAR=VALUE]...

  To assign environment variables (e.g., CC, CFLAGS...), specify them as
  VAR=VALUE.  See below for descriptions of some of the useful variables.

  Defaults for the options are specified in brackets.

  Configuration:
    -h, --help              display this help and exit
        --help=short        display options specific to this package
        --help=recursive    display the short help of all the included packages
    -V, --version           display version information and exit
    -q, --quiet, --silent   do not print `checking ...' messages
        --cache-file=FILE   cache test results in FILE [disabled]
    -C, --config-cache      alias for `--cache-file=config.cache'
    -n, --no-create         do not create output files
        --srcdir=DIR        find the sources in DIR [configure dir or `..']

  Installation directories:
    --prefix=PREFIX         install architecture-independent files in PREFIX
                            [/usr/local]
    --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                            [PREFIX]

  By default, `make install' will install all the files in
  `/usr/local/bin', `/usr/local/lib' etc.  You can specify
  an installation prefix other than `/usr/local' using `--prefix',
  for instance `--prefix=$HOME'.

  For better control, use the options below.

  Fine tuning of the installation directories:
    --bindir=DIR            user executables [EPREFIX/bin]
    --sbindir=DIR           system admin executables [EPREFIX/sbin]
    --libexecdir=DIR        program executables [EPREFIX/libexec]
    --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
    --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
    --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
    --libdir=DIR            object code libraries [EPREFIX/lib]
    --includedir=DIR        C header files [PREFIX/include]
    --oldincludedir=DIR     C header files for non-gcc [/usr/include]
    --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
    --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
    --infodir=DIR           info documentation [DATAROOTDIR/info]
    --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
    --mandir=DIR            man documentation [DATAROOTDIR/man]
    --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
    --htmldir=DIR           html documentation [DOCDIR]
    --dvidir=DIR            dvi documentation [DOCDIR]
    --pdfdir=DIR            pdf documentation [DOCDIR]
    --psdir=DIR             ps documentation [DOCDIR]

  [...]

After finishing the preparation we install the PHP version 5.6, run the following commands in your shell


./configure \
--prefix=/opt/php-5.6 \
--with-pdo-pgsql \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-mcrypt \
--with-zlib \
--with-gd \
--with-pgsql \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysql \
--with-pdo-mysql \
--with-mysqli \
--with-png-dir=/usr \
--enable-gd-native-ttf \
--with-openssl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-libdir=lib64 \
--enable-ftp \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-gettext \
--with-gd \
--with-jpeg-dir=/usr/lib/ \
--enable-fpm

The last switch (--enable-fpm) makes this PHP version work with PHP-FPM. If you want to use this PHP-FPM version with Apache, please use --with-fpm-user=apache and --with-fpm-group=apache. On the other hand, if you want to use this PHP-FPM version with nginx, please use --with-fpm-user=nginx and --with-fpm-group=nginx.

If everything goes fine. The successful message will be outputted in the terminal like

[...]

creating libtool
appending configuration tag "CXX" to libtool

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

Now, you can use make to perform the actual compilation:

  make

The main result of this operation will be PHP binaries for the enabled SAPIs (by default sapi/cli/php and sapi/cgi/php-cgi), as well as shared extensions in the modules/ directory.

Now you can run "make install" to install PHP into /usr/local (default) or another directories by using the --prefix configuration. In this case is /opt/php-5.6

  sudo make install

Please note that the "make install" will not create an ini file.

/opt/php-5.6/bin/php --ini
Configuration File (php.ini) Path: /opt/php-5.6/lib
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Copy php.ini and php-fpm.conf to the correct directory:

sudo cp /opt/source/php-src/php-fpm.conf.default /opt/php-5.6/etc/php-fpm.conf
sudo cp /opt/source/php-src/php.ini-production /opt/php-5.6/lib/php.ini

We verify and checking the php version one more time.

  /opt/php-5.6/bin/php --ini
  Configuration File (php.ini) Path: /opt/php-5.6/lib
  Loaded Configuration File:         /opt/php-5.6/lib/php.ini
  Scan for additional .ini files in: (none)
  Additional .ini files parsed:      (none)

  ### Checking php
  /opt/php-5.6/bin/php --version
  PHP 5.6.2-dev (cli) (built: Oct  2 2014 17:20:23) 
  Copyright (c) 1997-2014 The PHP Group
  Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

Open /opt/php-5.6/etc/php-fpm.conf and adjust the settings in the listen line. You must change to an unused port (e.g. 9001; the port 9000 might be in use by Fedora)

  vi /opt/php-5.6/etc/php-fpm.conf
  [...]
  pid = run/php-fpm.pid
  [...]
  user = nginx
  group = nginx
  [...]
  listen = 127.0.0.1:9001
  [...]
  #include=/opt/php-5.6/etc/pool.d/*.conf

Init script setup

You will probably want to create an init script for your new php-fpm. Luckily, the PHP 5.3+ already provides it for you, simply copy the init script to your directory and change permissions:

  sudo cp /opt/source/php-src/sapi/fpm/init.d.php-fpm /etc/init.d/php5.6-fpm
  sudo chmod 755 /etc/init.d/php5.6-fpm

Your init script is ready. Now, you are able to start, stop and reload php-fpm:

  sudo /etc/init.d/php5.6-fpm start
  sudo /etc/init.d/php5.6-fpm stop
  sudo /etc/init.d/php5.6-fpm reload

Building the second PHP (5.5.x)

We open up the terminal and type the following command.

git checkout PHP-5.5
sudo ./buildconf 
./configure \
--prefix=/opt/php-5.5 \
--with-pdo-pgsql \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-mcrypt \
--with-zlib \
--with-gd \
--with-pgsql \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysql \
--with-pdo-mysql \
--with-mysqli \
--with-png-dir=/usr \
--enable-gd-native-ttf \
--with-openssl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-libdir=lib64 \
--enable-ftp \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-gettext \
--with-gd \
--with-jpeg-dir=/usr/lib/ \
--enable-fpm

make && sudo make install

Building PHP Phalcon extensions

To install multiple versions of Phalcon include Phalcon 2.0, we need to install Zephir

  git clone https://github.com/json-c/json-c.git
  cd json-c
  sh autogen.sh
  ./configure
  make && sudo make install

  git clone https://github.com/phalcon/zephir
  cd zephir
  sudo ./install -c

There are many ways to install PHP extensions. We will use phpize build it, so what is phpize ?

phpize plays a similar role as the ./buildconf script used for PHP builds: First it will import the PHP build system into your extension by copying files from $PREFIX/lib/php/build. Among these files are acinclude.m4 (PHP’s M4 macros), phpize.m4 (which will be renamed to configure.in in your extension and contains the main build instructions) and run-tests.php.

Then phpize will invoke autoconf to generate a ./configure file, which can be used to customize the extension build. Note that it is not necessary to pass --enable-apcu to it, as this is implicitly assumed. Instead you should use --with-php-config to specify the path to your php-config script:

Remember!!!. You must specify the --with-php-config option when build the extensions (unless you have only a single, global installation of PHP). Otherwise the ./configure will not be able to determine correctly the PHP version and flags. Moreover, the php-config script also ensures that "make install" command will move the generated .so file (which can be found in the modules/ directory) to the right extension directory.

Building the first PHP Phalcon (2.0)

  git clone http://github.com/phalcon/cphalcon
  cd cphalcon && git checkout 2.0.0
  zephir compile
  cd ext && /opt/php-5.6/bin/phpize
  ./configure --with-php-config=/opt/php-5.6/bin/php-config
  make && sudo make install
  Installing shared extensions:     /opt/php-5.6/lib/php/extensions/no-debug-non-zts-20131226/

Please check whether or not it is successful

  ls /opt/php-5.6/lib/php/extensions/no-debug-non-zts-20131226/

After the extension is installed. You still need to activate it by including it in php.ini file.

  sudo su
  echo "extension=phalcon.so" >> /opt/php-5.6/lib/php.ini
  exit

Building the second PHP Phalcon (1.3.x)

  git clone http://github.com/phalcon/cphalcon
  cd cphalcon && git checkout master
  cd ext && /opt/php-5.5/bin/phpize
  ./configure --with-php-config=/opt/php-5.5/bin/php-config
  make && sudo make install
  Installing shared extensions:     /opt/php-5.5/lib/php/extensions/no-debug-non-zts-20121212/

We check again to make sure the installation is successful

  ls /opt/php-5.6/lib/php/extensions/no-debug-non-zts-20131226/
  sudo su
  echo "extension=phalcon.so" >> /opt/php-5.5/lib/php.ini
  exit

Configuring Nginx

  sudo vi /etc/nginx/nginx.conf

The following configuration will create two servers: the phalcon-prd.localhost runs on PHP 5.5.x and phalcon-dev.localhost works with PHP 5.6.x. This is a example, you can customize anything you want, see Nginx documentation

[...]
http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  #gzip  on;
  include /etc/nginx/conf.d/*.conf;

  index index.php index.html index.htm;

  #Prodution environment Phalcon
  server {
    listen       80;
    server_name  phalcon-prd.localhost;

    root   /usr/share/nginx/html/phalcon-prd;

    location / {
      index  index.php;
    }

    location ~ \.php$ {
      fastcgi_pass   127.0.0.1:9001;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
  }
  #Development environment Phalcon
  server {
    listen       80;
    server_name  phalcon-dev.localhost;

    root   /usr/share/nginx/html/phalcon-prd;

    location / {
      index  index.php;
    }

    location ~ \.php$ {
      fastcgi_pass   127.0.0.1:9002;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
  }
}
[...]

Set Up Local Hosts File

If you are using a Linux system, you can edit the host file:

  sudo vi /etc/hosts

The new host file will look like.

[...]
127.0.0 localhost phalcon-dev.localhost phalcon-prd.localhost
::1   localhost6.localdomain6 localhost6
[...]

This one intercepts all requests for phalcon-dev.localhost and phalcon-prd.localhost then send them to your server.

Testing it

For testing, we create a new file called test.php and put it into folder corresponding to the above configuration of Nginx. In each files, we add the following command.

  <?php phpinfo(); ?>

Now running the test.php file in each server, we see a Phalcon 1.3.x phpinfo() at http://phancon-prd.localhost/test.php while at http://phancon-dev.localhost/test.php should be phpinfo() of Phalcon 2.0.x

In conclusion

So we’ve been taken to have a overview about install multiple versions of Phalcon and PHP. With this way you are able to run as many as versions of Phalcon as well as PHP.

Leave your feedback in the comments below and, as always, please share this article if you liked it!

solved
Jan 1/70 at 12:00 15 Answers 3637 Views 0

About the Author

Answers ( 6 )

    0
    Jun 16/15 at 02:31

    After (re)combination (I never understand why the "re" is used) and the formation of the CMB, the universe was transparent and the only light in it was from the rapidly cooling CMB. The baryonic universe was composed almost entirely of neutral hydrogen and helium.

  1. Nhi
    0
    Jun 14/15 at 09:01

    This process is not entirely understood in terms of when it happened, how quickly it happened and what objects were primarily responsible. The thing is that it was probably the first stars (thought to be much more massive, hot and luminous than stars today) in relatively small dwarf galaxies, but it is not possible to see these directly. Conversely, high redshifts qusars may have played some role, either in direct reionisation or more likely in regulation star formation.

    owned: function(){
        this.url = this.options.url.owned;
        this.parse = function(users){
            return users.map(function(user){
                return user;
            });
        };
        this.fetch({
            data: {
                screen_name : login
            }
        });
    }

    0
    Jun 14/15 at 04:12

    This process is not entirely understood in terms of when it happened, how quickly it happened and what objects were primarily responsible. The thing is that it was probably the first stars (thought to be much more massive, hot and luminous than stars today) in relatively small dwarf galaxies, but it is not possible to see these directly. Conversely, high redshifts qusars may have played some role, either in direct reionisation or more likely in regulation star formation.

    0
    Jun 14/15 at 04:12

    In summary I would say the significance of reionisation is twofold. First it offers an opportunity to probe and test our ideas about the formation of stars and galaxies in the otherwise very hard to observe early universe. Second, the end of the "dark ages", marks the point where baryonic matter takes a very active role in shaping the formation of stars and galaxies. The radiation from the first stars exerts a strong negative feedback the collapsing ionised gas around it and can drive galactic winds and outflows. Prior to this, dark matter was the dominant influence, but reionisation couples the radiation and baryonic matter together again on galaxy-sized scales.

    0
    Jun 14/15 at 04:09

    After (re)combination (I never understand why the "re" is used) and the formation of the CMB, the universe was transparent and the only light in it was from the rapidly cooling CMB. The baryonic universe was composed almost entirely of neutral hydrogen and helium.

    After perhaps 100 million years, the first galaxies and stars (assisted by dark matter) were able to form and then over the next few hundred millions of years most of the hydrogen was reionised by the radiation emitted by these objects. You can imagine bubbles of ionised gas forming around regions of intense star formation.

    This process is not entirely understood in terms of when it happened, how quickly it happened and what objects were primarily responsible. The thing is that it was probably the first stars (thought to be much more massive, hot and luminous than stars today) in relatively small dwarf galaxies, but it is not possible to see these directly. Conversely, high redshifts qusars may have played some role, either in direct reionisation or more likely in regulation star formation.

    0
    Apr 4/15 at 12:50

    Chrome runs on tablets, smartphones, and other devices. Make your content ready for the multi-device web!

Leave a reply

 Prev question

Next question