Search code examples
phpdockerlegacy

How to containerize legacy app with PHP version 5.4.x?


I am new to PHP development and stuck for two days just to set up the PHP version in my local. I am trying to continue the legacy app that builds using PHP version 5.4.45. Firstly, I have been attempting to install PHP version 5.4.45 on my MacOS Ventura (13.4.1) devices from these sources. After I extract, configure, and make it seems that it has compatibility issues with my devices.

Since I have been stuck all day, I try to build a container to run the legacy app using Docker. I follow this guide and here is my docker file:

FROM php:5.4-apache-stretch

RUN docker-php-ext-install -j$(nproc) mysqli opcache

ADD php.ini /usr/local/etc/php.ini

and execute the docker command docker build -t first-php-docker . and it yields the error failed to solve: php:5.4-apache-stretch: failed to do request: Head "https://registry-1.docker.io/v2/library/php/manifests/5.4-apache-stretch": EOF and it seems the source is doesn't exist anymore.

Question:

  • How to make sure whether the php:5.4-apache-stretch image still exists or not?
    • If it still exists, how to build a container with that image as the base?

Solution

  • There's currently only one PHP 5.4 + Apache image available on Docker Hub

    php:5.4-apache.

    This image is only built for the AMD64 platform so you'll need to specify that if you're building on an M1 / M2 Mac.

    You should also use the pre-configured PHP_INI_DIR environment variable when adding your php.ini file. See Configuration.

    FROM --platform=linux/amd64 php:5.4-apache
    
    # ...
    
    ADD php.ini "$PHP_INI_DIR/php.ini"
    

    Without the above --platform specification, you will constantly get warnings like

    WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

    Note, this uses a Debian Jessie base image.