PHP 5.6 is currently outdated and no more supported, but sometimes, in real World, you could be forced to setup and debug legacy projects that works with outdated technologies.
I had to. And I always use Docker for this, of course. But I also need to use Xdebug in order to debug those legacy projects, and common Xdebug installation procedures don’t work with outdated PHP.
If fact, if you try, you will get back something like this:
root@9cdda704a4ee:/var/www/html# pecl install xdebug
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/xdebug requires PHP (version >= 7.2.0, version <= 8.1.99), installed version is 5.6.40
No valid packages found
install failed
So, I had to find a different way to quickly install Xdebug into my dev Docker container. And, because I think I’m not the only one that faced this problem, I decided to share this solution.
Starting from official PHP Apache2 Docker container, we simply have to install last historical release of Xdebug still valid for PHP 5.6 (should be 2.5.5) from source.
Follows a starting docker-compose structure that you can be extended as needed. It contains only 3 files:
docker-compose.yml
apache2/Dockerfile
apache2/php.ini
Let’s see file content.
First of all, file docker-compose.yml
must include php.ini file as volume, so we can add our xdebug configuration:
|
|
Then, in apache2/Dockerfile
file we must clone Xdebug source code and build it:
|
|
As last, at the end of docker/php.ini
, add following lines (or your preferred Xdebug configuration):
|
|
Build and run the container with:
docker-compose up -d
Then access to the container with and test Xdebug installation:
$ docker exec -it test-php-1 /bin/bash
root@9cdda704a4ee:/var/www/html# php -v
PHP 5.6.40 (cli) (built: Jan 23 2019 00:10:05)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
I hope it can be useful.
See also
- Split, reduce and convert PDF to JPEG using PHP ImageMagick
- Quickly setup HTTPS on PHP Apache2 Docker container with self-signed SSL certificate
- Building ZF3 composed pages using Nesting View Models and Forward Controller Plugin
- How to inject Zend Service Manager in ZF3 Controllers
- How to setup a Translate Controller Plugin in Zend Framework 3