Install PHP 5.4 from DotDeb

In case if you want have latest php-5.4 both in CLI and with Apache-2.x it is better to install it through apt-get
You need to add these source to sources.list file:

deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all
deb http://packages.dotdeb.org squeeze-php54 all
deb-src http://packages.dotdeb.org squeeze-php54 all

If you are getting this error

W: GPG error: http://packages.dotdeb.org stable Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY E9C74FEEA2098A6E
W: GPG error: http://nginx.org squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

you need follow such steps:

gpg --keyserver keys.gnupg.net --recv-key 89DF5277
gpg -a --export 89DF5277 | sudo apt-key add -
gpg --keyserver keyserver.ubuntu.com --recv-key ABF5BD827BD9BF62
gpg -a --export ABF5BD827BD9BF62 | sudo apt-key add -
sudo apt-get update

HowTo Compile and Install php-5.4.x on Debian OS (squeeze)

Recently I was trying install latest PHP 5.4.x (at the moment of writing this is 5.4.10) version on my stable Debian OS (v6.0-squeeze-32bit).
As far as you may know, stable Debian proposes PHP-5.3.4 as latest available release. I wanted to use embedded into PHP-5.4 web-server.
I was thinking that install PHP-5.4 would be faster process then configuring new virtual host in Apache. Yep, lazy me! 🙂
Well, spoiling the story, I would like to say, that the overall process took 2-2.5 hours from me before I was able to launch my scripts.
To be honest, that was my first time when I was compiling PHP from source, and I feel I got great experience with that!
But okay, let’s look at the process step-by-step.

First of all, you may need install “libxml2-dev” linux library (don’t remember why, though :-)).
Oh, wait! Looks like it needed for you be able to configure you PHP installator.

sudo apt-get install libxml2-dev

I also believe that most web developers need to use DB with theirs scripts, thus they may need PDO php extension.
So, you need to compile PHP with this directive:

configure --with-pdo-mysql --with-mysql

(see http://php.net/manual/en/ref.pdo-mysql.php for more details)

Usually, good devloper uses debug tools extensively. As we all know most popular PHP debugger is a xdebug.
This package could be installed from pecl repository.
Before asking pecl to install xdebug, make sure you have php5-dev package installed in your system. With that package phpize is being shipped, which is required to install PHP extensions through pecl.
If you don’t have php5-dev install, you are going get this error message:

ERROR: `phpize’ failed

and here is your next command:

sudo apt-get install php5-dev

After that, you will be able install xdebug extension with help of pecl:

sudo pecl install xdebug

Next. Let’s assume you work with not only documents written solely in English, but with some other languages (Italian, Portugeese, Russion, Dutch, etc.)
Also let’s assume you need to handle dates written in non-english format (btw, about that look for my article about how one can handle dates written in languages different from English). php5-intl extension comes to help! Here http://php.net/manual/en/intl.installation.php you will find information how to enable this extension:

configure --enable-intl

If PHP’s configurator shows error message

“configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.”

you need install this Linux package:

apt-get install libicu-dev

These are development files for International Components for Unicode.

Next, it may happen that you need load remote http resources. Usually, that is done with curl (php5-curl).
I was not enable that extension because faced such message:

configure: error: Please reinstall the libcurl distribution

In such case you need install this Linux package:

sudo apt-get install libcurl4-gnutls-dev

(thanks to http://phpconfigure.com/2011/04/configure-error-please-reinstall-the-libcurl-distribution/)

In case if you need to deal with multibyte encodings and use PHP’s functions prefixed with mb_*, you need enable that as well:

configure --with-mbstring

Okay, as I said, after couple hours of fight I was able to finish with this configuration options and directives:

sudo ./configure --with-pdo-mysql --with-mysql --with-curl --enable-intl --enable-mbstring=all

As I said at the beginning, I was hoping that install PHP-5.4 would be faster then configure virtual host. How far away from truth was I!..
But I do not regret about my choice, because now I feel strong in believe that I have mastered some important things and have grown my professional level!

Fell free to add comments and ask things that left unclear for you.

PHP-5.4 Debian – no suhosin, xcache, xdebug extensions

Today I have upgraded my Debian OS 6.0 (configured with apt-pinning).
Among the updates when called the dist-upgrade rolled a number of modules installed for php5. PHP was updated as well, actually up to version 5.4.0-2. But … then began weird problem – any local site did not work! In the logs were strange errors for, say, a website based on the framework, YII there was a message:

 [Sun Mar 25 13:32:51 2012] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined function (null) () in / home / web / ccc / frontend / index.php on line 4

And on that line 4 was nothing special, except call to dirname (__FILE__)!
Google-searching on the Internet for the similar error I did not find anything. Posted a bug on php.net.
But it’s something nasty! Nothing at all works…
I began to dig further. I tried to run php scripts from the console, in order to check – was really dirname () removed? 🙂 And found a number of outstanding notifications warnings:

rodush @ rdushko :/ var / www $ php test.php
Failed loading / usr/lib/php5/20090626 + lfs / xdebug.so: / usr/lib/php5/20090626 + lfs / xdebug.so: cannot open shared object file: No such file or directory
PHP Warning: PHP Startup: Unable to load dynamic library ‘/ usr/lib/php5/20100525 + lfs / suhosin.so’ – / usr/lib/php5/20100525 + lfs / suhosin.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/ usr/lib/php5/20100525 + lfs / xhprof.so’ – / usr/lib/php5/20100525 + lfs / xhprof.so: cannot open shared object file: No such file or directory in Unknown on line 0

Although the directive dirname() in the test file worked fine, and included a file that I requested.
Having looked in the directory specified in the message, I discovered that those libraries are indeed absent!
So far decided not fooling: once the libraries will be available – I will get them updated, so I decided to remove the configs for php for that libraries.
Theese config ini files are located in the directory / etc/php5/conf.d /
just renamed all the config files, which have not come during update, to files with the suffix “old” (handy for the future 🙂 I think)

suhosin.ini.old xdebug.ini.old xcache.ini.old xhprof.ini.old

I tried to call test script from the console – no more warnings php! I tried to go to the sites in a browser, and – lo and behold! – It works!
Thats what the magic may happen in case if php complains that it is impossible to add extra modules library.
So, now you may know where to start if you faced similar strange issues.