mysqldockerphp-5.6

revive an old php 5.6 website with docker


I'm reviving an old website still using PHP5.6 and mysql_connect, in order to update its code.

I was going to setup a docker environment with PHP 5.6 to make sure everything worked correctly, before doing the much needed update.

But I'm struggling with the installation of the mysql driver.

Here's my docker-compose.yml

version: '3'

services:
  db:
    image: mysql:5.5
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "edited for privacy"
      MYSQL_DATABASE: "edited for privacy"
      MYSQL_USER: "edited for privacy"
      MYSQL_PASSWORD: "edited for privacy"

  php:
    depends_on:
      - db
    build: .
    volumes:
      - ./:/var/www/html
    ports:
      - "8000:80"
    restart: always

volumes:
  db_data: {}

With this first dockerfile, I've got the following error

FROM php:5.6-apache

RUN apt-get install mysql-server mysql-client php5-mysql

RUN a2enmod rewrite
docker compose up -d
[+] Building 1.2s (6/7)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 139B                                                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/php:5.6-apache                                                                                                                                                                      0.8s
 => [auth] library/php:pull token for registry-1.docker.io                                                                                                                                                                             0.0s
 => CACHED [1/3] FROM docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                         0.0s
 => => resolve docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                                0.0s
 => ERROR [2/3] RUN apt-get install mysql-server mysql-client php5-mysql                                                                                                                                                               0.3s
------
 > [2/3] RUN apt-get install mysql-server mysql-client php5-mysql:
#0 0.292 Reading package lists...
#0 0.296 Building dependency tree...
#0 0.296 Reading state information...
#0 0.297 E: Unable to locate package mysql-server
#0 0.297 E: Unable to locate package mysql-client
#0 0.297 E: Unable to locate package php5-mysql
------
failed to solve: executor failed running [/bin/sh -c apt-get install mysql-server mysql-client php5-mysql]: exit code: 100

I thought I'd had to update first, but then I've got this error, and I don't know what to do.

FROM php:5.6-apache

RUN apt-get update && apt-get install -y \
    mysql-client \
    mysql-server \
    php5-mysql

RUN a2enmod rewrite
docker compose up -d
[+] Building 0.7s (5/6)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 189B                                                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/php:5.6-apache                                                                                                                                                                      0.4s
 => CACHED [1/3] FROM docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                         0.0s
 => => resolve docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                                0.0s
 => ERROR [2/3] RUN su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql                                                                                                                        0.3s
------
 > [2/3] RUN su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql:
#0 0.281 su: invalid option -- 'q'
#0 0.281 Usage: su [options] [LOGIN]
#0 0.281
#0 0.281 Options:
#0 0.281   -c, --command COMMAND         pass COMMAND to the invoked shell
#0 0.281   -h, --help                    display this help message and exit
#0 0.281   -, -l, --login                make the shell a login shell
#0 0.281   -m, -p,
#0 0.281   --preserve-environment        do not reset environment variables, and
#0 0.281                                 keep the same shell
#0 0.281   -s, --shell SHELL             use SHELL instead of the default in passwd
#0 0.281
------
failed to solve: executor failed running [/bin/sh -c su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql]: exit code: 2

I don't know what to do next, any help would be very welcomed.


Solution

  • It seems to work with this dockerfile, following instructions on https://prototype.php.net/versions/5.6/install/docker

    FROM php:5.6-apache
    
    RUN docker-php-ext-install -j$(nproc) mysql opcache
    
    RUN a2enmod rewrite