Installing PHP 5.3 on Debian Stretch (9)
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).
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="[email protected]"
# 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.