8

I'm migrating a very old server (Debian etch) to Debian Stretch and every single app developed has PHP issues, it was expected. Some can be fixed, some can not (as several drupal 6 sites). In the future ever single app will be served under PHP7.0 but until that day comes I need PHP5.3 serving them.

I know that Debian stretch has some kind of "native" support for co-installable PHP versions but all examples I have found are with PHP5.6 (Jessie's version): https://pehapkari.cz/blog/2017/03/27/multiple-php-versions-the-easy-way/

Also, I have found some examples of PHP5.3 and PHP5.4 or PHP5.6 working together on Debian Jessie, Wheezy, etc but not for Debian Stretch (PHP7.0): https://superuser.com/questions/913792/php-5-3-10-on-debian-jessie

So, first, I need to know if it is posible to have PHP7.0 and PHP5.3 working together on apache2 on Debian Stretch.

Second, i need to figure out how can this be done.

I'm not sysadmin so my debian knowledge is growing day by day from scratch.

Thank you.

  • Is there a specific requirement to migrate to Stretch? Jessie is still supported, you could migrate to that instead. – Stephen Kitt Jul 18 '17 at 9:26
  • I have here a internal server working with PHP 5 and 7. I do agree with Stephen, Jessie is an easier path. Are you willing to live with the security problems? – Rui F Ribeiro Jul 18 '17 at 9:46
  • Sadly stretch is a requirement, I "recieve" the root user of a virtual server with the SO installed (debian 9), every thing else is up to me. I'm aware of the security problems with PHP5.3, it would be a temporary solution as I can migrate all the apps to work with PHP7.0 – raguchi Jul 18 '17 at 10:15
  • I give up with Debian Stretch, no way to have PHP 5.3. @RuiFRibeiro, your PHP5 version is 5.6, isn't it? Maybe I could have PHP5.3 and PHP7.0 in debian Jessie but i cann't see an easy way like with 5.6 (apt-get install php7.0-fpm php5-fpm). – raguchi Jul 21 '17 at 11:00
  • 5.6 exactly. It is more an hack than anything else, would not use it in an Internet server. – Rui F Ribeiro Jul 21 '17 at 13:11
5

One week later I managed to get it working but in a different way. I stopped messing with the host and started to learn how Docker can save my life.

This post gave me the key: Docker - Run Apache on host and container for different websites

My iniciatic read about docker was this one: PHP Web Development with Docker

Summarizing, I don't need to install apache2.2 & PHP5.3 in my host server, I can have an isolated container where I can install anything I need (usually one service) and forget about possible incompatibilities with the host OS version. Docker manages it all. So I can have one container with apache 2.2 + PHP 5.3 as it would be in a debian squeeze OS. Another container with apache 2.2 + PHP 5.4 as it would be in a Wheezy, another with apache 2.4 + PHP7.0 as in stretch and so on. All working as the same time and serving different domains. To achieve the latter make apache/nginx on the host to work as reverse proxy redirecting each domain to a different apache-php container thanks to docker port mapping. You don't even need to have apache/nginx on the host, it can be in a container also.

The docker way is to have each (micro)service in a container, so you can have mariaDB in another container, etc.

My steps (summarized): (I can not post more than to links, when i get enough reputation I will edit and add them)

0 - Read about docker (the more the better): how to build images with the Dockerfile, best practices, networking within docker,...

1 - Install Docker: follow official guide always.

2 - Create a dir with your future image name ( /home/user/docker/images/apache22php53 e.g.), inside create your Dockerfile and configs (virtualhost conf in this case) my Dockerfile was:

FROM debian:squeeze

LABEL maintainer="raguchi@gmail.com"

# squeeze new mirrors
RUN echo "deb http://archive.debian.org/debian/ squeeze contrib main non-free" > /etc/apt/sources.list

RUN apt-get update
# Common packages
RUN apt-get update && \
    apt-get install -y --force-yes curl wget

RUN apt-get update && \
    apt-get install -y --force-yes \
            apache2 \
            libapache2-mod-php5 \
            ntp \
        php5 \
        php5-curl \
        php5-gd \
        php5-ldap \
        php5-mcrypt \
        php5-mysql \
        vim

RUN a2enmod \
            php5 \
        rewrite \
        ssl


ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP    www-data
ENV APACHE_LOG_DIR  /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
# RUN     chown -R www-data:www-data /var/www
COPY     conf/apache/virtualhosts /etc/apache2/sites-enabled

# disable default virtualhost
RUN a2dissite 000-default

EXPOSE 80
EXPOSE 443

CMD     ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

Inside the dir put your virtualhost conf file inside the path: conf/apache/virtualhosts/

3 - build the image with (previous cd inside the dir):

sudo docker build -t apache22php53 .

4 - launch the container with:

sudo docker run -ti -d -p 2253:80 -v /var/www/html:/var/www --name apache22php53 apache22php53 /bin/bash

Docker will map (-p) 2253 host port to 80 container port. We are mounting (-v) also our host document root (/var/www/html) in the apache-container document root (in squeeze is /var/www ). The are setting also container name (--name).

5 - ssh to container with:

sudo docker exec -ti apache22php53 /bin/bash

and start apache if needed (as in my case). "exit" to get back to host cli.

6 - navigate to ...yourvhostdomain.com:2253 and you should see your apache running with PHP5.3 loaded.

This is the basics. After that you will learn about how to mount host data (www, databases, etc) inside containers, how containers can communicate between them and with the host (privates IPs in docker network), how to use docker-compose to set up multiple containers at once (web, database, etc), reverse proxy for multiple containers webservers, etc.

  • I marked my own answer as the accepted because it's the only solution i have tried and it worked for me. – raguchi Nov 8 '17 at 11:56
4

I've stumbled across a similar problem and managed to make it work.

I had to install a server with debian 9/nginx/php5.4, so while it does not exactly match your prerequisites, I assume the solution is similar. I will list the steps I took which solved it for me.

Basically, you need to install php from sources, and this poses a problem if you need openssl support (--with-openssl), because old versions of PHP (<7.0) don't support openssl>=1.1.0, which is the default in debian 9. So you have to build an older openssl version (I took 1.0.1u).

But let's install some dependencies first.

apt install build-essential checkinstall zip autoconf
apt install libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e-dev libkrb5-dev libcurl4-openssl-dev
apt install libxml2-dev libcurl4-openssl-dev libpcre3-dev libbz2-dev libjpeg-dev libpng-dev libfreetype6-dev libmcrypt-dev libmhash-dev freetds-dev libmariadbclient-dev-compat unixodbc-dev libxslt1-dev

Then we'll build openssl.

cd /opt/
wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1u.tar.gz
tar xzf openssl-1.0.1u.tar.gz
cd openssl-1.0.1u
./config shared --openssldir=/usr/local/openssl/ enable-ec_nistp_64_gcc_128
make depend
make
make install
ln -s /usr/local/openssl/lib /usr/local/openssl/lib/x86_64-linux-gnu

As a chain reaction, you will have to build libcurl and libc-client (for imap support) with your freshly built openssl. We'll start with libcurl.

cd /opt/
wget https://curl.haxx.se/download/curl-7.26.0.tar.gz
tar xzf curl-7.26.0.tar.gz
cd curl-7.26.0
env PKG_CONFIG_PATH=/usr/local/openssl/lib/pkgconfig LDFLAGS=-Wl,-rpath=/usr/local/openssl/lib ./configure --with-ssl=/usr/local/openssl --with-zlib --prefix=/usr/local/curl
make
make install

Then, libc-client. I actually used the sources from debian 8, since it included some patches. The build itself failed but still produced c-client.a, which is all I needed.

cd /tmp/
wget http://http.debian.net/debian/pool/main/u/uw-imap/uw-imap_2007f\~dfsg-2.dsc
wget http://http.debian.net/debian/pool/main/u/uw-imap/uw-imap_2007f\~dfsg.orig.tar.gz
wget http://http.debian.net/debian/pool/main/u/uw-imap/uw-imap_2007f\~dfsg-2.debian.tar.gz
dpkg-source -x uw-imap_2007f\~dfsg-2.dsc imap-2007f
mv imap-2007f /usr/local/
cd /usr/local/imap-2007f/
touch {ipv6,lnxok}
make slx SSLINCLUDE=/usr/local/openssl/include/ SSLLIB=/usr/local/openssl/lib EXTRAAUTHENTICATORS=gss
mkdir lib include
cp c-client/*.c lib/
cp c-client/*.h include/
cp c-client/c-client.a lib/libc-client.a
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a

With this, I had all I need to build PHP5.4. Please note that I had warning for postgresql bindings in compilation (because of local vs system openssl version mismatch), so I think you will have to build your own libpq if you wish to use them.

cd /opt/
PHP_VER=5.4.45
wget http://museum.php.net/php5/php-${PHP_VER}.tar.gz
tar xzf php-${PHP_VER}.tar.gz
cd php-${PHP_VER}
LDFLAGS="-Wl,-rpath=/usr/local/openssl/lib,-rpath=/usr/local/curl/lib" './configure'  --prefix=/usr/local/php-${PHP_VER} '--with-zlib-dir' '--with-freetype-dir' '--enable-fpm' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl=/usr/local/curl' '--with-mcrypt' '--with-zlib' '--with-gd' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-zlib' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-mbregex' '--with-mhash' '--enable-zip' '--with-pcre-regex' '--with-mysql' '--with-pdo-mysql' '--with-mysqli' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--enable-cgi' '--with-pear' '--enable-memcache' '--with-openssl=/usr/local/openssl' '--with-imap=/usr/local/imap-2007f' '--with-kerberos' '--with-imap-ssl' '--with-libdir=lib/x86_64-linux-gnu'
LDFLAGS="-Wl,-rpath=/usr/local/openssl/lib,-rpath=/usr/local/curl/lib" make
make install

The only things left are creation of php.ini and php-fpm.conf files, which are both trivial, configuration of php-fpm socket and the creation of an initscript (there are plenty example online, I can't post the full file here), and the configuration of your webserver (fastcgi on socket).

  • I'm getting problem with th emake line of the uw-imap_2007f compilation. There are many problems in the main declaration of /usr/local/imap-2007f/ipopd/ipop2d.c – dubis Nov 30 '18 at 14:37
  • Yes, this is expected. It should still generate a c-client/c-client.a file, which is all you need for the next steps. – Arza Dec 1 '18 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.