見出し画像

docker-composeを利用して古いphpシステムを動作させる、conoha vpsで

あんまりやりたくないけど…ここではMoodle 1.9.19+としましょうか。

Moodle 1.9.19+

https://download.moodle.org/releases/legacy/

ここにしぶとく残っていたりする。

install

root@archive:~# apt install docker-compose
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cgroupfs-mount containerd
  criu docker.io libbinutils libctf-nobfd0 libctf0 libgprofng0 libintl-perl
  libintl-xs-perl libmodule-find-perl libmodule-scandeps-perl libnet1
  libproc-processtable-perl libprotobuf32 libsort-naturally-perl
  libterm-readkey-perl needrestart python3-distro python3-distutils
  python3-docker python3-dockerpty python3-docopt python3-dotenv
  python3-lib2to3 python3-protobuf python3-texttable python3-websocket runc
  sgml-base tini
Suggested packages:
  binutils-doc containernetworking-plugins docker-doc aufs-tools btrfs-progs
  debootstrap rinse rootlesskit xfsprogs zfs-fuse | zfsutils-linux
  needrestart-session | libnotify-bin sgml-base-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cgroupfs-mount containerd
  criu docker-compose docker.io libbinutils libctf-nobfd0 libctf0 libgprofng0
  libintl-perl libintl-xs-perl libmodule-find-perl libmodule-scandeps-perl
  libnet1 libproc-processtable-perl libprotobuf32 libsort-naturally-perl
  libterm-readkey-perl needrestart python3-distro python3-distutils
  python3-docker python3-dockerpty python3-docopt python3-dotenv
  python3-lib2to3 python3-protobuf python3-texttable python3-websocket runc
  sgml-base tini
0 upgraded, 35 newly installed, 0 to remove and 0 not upgraded.
Need to get 74.9 MB of archives.
After this operation, 311 MB of additional disk space will be used.
Do you want to continue? [Y/n]

一般ユーザーをdockerグループに所属させる

root@archive:~# adduser admin docker
Adding user `admin' to group `docker' ...
Done.

path

pathはさまざまな議論があると思うけど
/opt/moodle-deployment

にしまーす

$ sudo mkdir /opt/moodle-deployment
$ cd /opt/moodle-deployment/
$ sudo chown <ユーザー> .

とかしといたらいいんじゃないでしょうか

最低限のdocker-compose.yml

とりあえずtests/index.phpを表示するapacheを起動するとする

まず/opt/moodle-deployment/tests/index.phpを作成

$ mkdir tests
$ echo '<?php phpinfo();' > tests/index.php

docker-compose.yamlを作成

version: '3'

services:
  web:
    image: php:5.6-apache
    ports:
      - "80:80"
    volumes:
      - ./tests:/var/www/html

up

$ docker-compose up
Creating network "moodle-deployment_default" with the default driver
Pulling web (php:5.6-apache)...
5.6-apache: Pulling from library/php
5e6ec7f28fb7: Download complete
cf165947b5b7: Download complete
7bd37682846d: Downloading [===================>                               ]  26.84MB/67.44MB
99daf8e838e1: Download complete
ae320713efba: Downloading [===================================>               ]  12.04MB/17.13MB
ebcb99c48d8c: Waiting
9867e71b4ab6: Waiting
936eb418164a: Waiting
bc298e7adaf7: Pulling fs layer
ccd61b587bcd: Waiting
b2d4b347f67c: Waiting
56e9dde34152: Waiting
...


php5.6.40…

phpの設定をチューニングするための設定

これはカスタムイメージphp:5.6-apacheを使う最低限の設定ではあるが、mysql拡張が有効になっていないなど諸々の問題がある。

以下はchatgpt提案の構造だ

/opt/moodle-deployment
├── docker-compose.yml
├── php
│   └── Dockerfile
├── moodle
│   └── ... (Moodle source files)
└── moodledata
    └── ... (Moodle data files)

この php/Dockerfileで基本的なビルドを行う

# 基本イメージを選択
FROM php:5.6-apache

# 必要なパッケージとPHP拡張機能をインストール
RUN apt-get update && \
    apt-get install -y libpng-dev libjpeg-dev libxml2-dev && \
    docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd xmlrpc mysqli

これにより、gd、xmlrpc、mysqliが有効になる、はず

debianのphp5-gdパッケージとかは使えないから注意してほしい

ここで問題が生じる

$ docker-compose build --no-cache
Building web
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM php:5.6-apache
 ---> 24c791995c1e
Step 2/2 : RUN apt-get update &&     apt-get install -y libpng-dev libjpeg-dev libxml2-dev &&     docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ &&     docker-php-ext-install gd xmlrpc mysqli
 ---> Running in 8ec07d441102
Ign:1 http://deb.debian.org/debian stretch InRelease
Ign:2 http://security.debian.org/debian-security stretch/updates InRelease
Ign:3 http://security.debian.org/debian-security stretch/updates Release
Ign:4 http://deb.debian.org/debian stretch-updates InRelease
Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
Ign:6 http://deb.debian.org/debian stretch Release
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Ign:8 http://deb.debian.org/debian stretch-updates Release
Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Ign:10 http://deb.debian.org/debian stretch/main amd64 Packages
Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
Ign:10 http://deb.debian.org/debian stretch/main amd64 Packages
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Err:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
  404  Not Found [IP: 151.101.66.132 80]
Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:7 http://security.debian.org/debian-security stretch/updates/main all Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Ign:10 http://deb.debian.org/debian stretch/main amd64 Packages
Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Ign:10 http://deb.debian.org/debian stretch/main amd64 Packages
Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Ign:10 http://deb.debian.org/debian stretch/main amd64 Packages
Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Ign:9 http://deb.debian.org/debian stretch/main all Packages
Err:10 http://deb.debian.org/debian stretch/main amd64 Packages
  404  Not Found
Err:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
  404  Not Found
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Reading package lists...
W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages  404  Not Found [IP: 151.101.66.132 80]
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-amd64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update &&     apt-get install -y libpng-dev libjpeg-dev libxml2-dev &&     docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ &&     docker-php-ext-install gd xmlrpc mysqli' returned a non-zero code: 100
ERROR: Service 'web' failed to build : Build failed

古いのを動かすのはテクが要るンだよ…

このapt-lineはもう使えねえの。だからarchive.debian.orgに書き換えにゃならん。

まあ、問題だけわかってればchatgptに全部聞いたらいい。このようにsources.listを新しい値で強制上書きする

# 基本イメージを選択
FROM php:5.6-apache

# aptのリポジトリ設定を更新
RUN echo "deb http://archive.debian.org/debian/ stretch main contrib non-free" > /etc/apt/sources.list && \
    echo "deb-src http://archive.debian.org/debian/ stretch main contrib non-free" >> /etc/apt/sources.list && \
    echo "Acquire::Check-Valid-Until false;" > /etc/apt/apt.conf


# 必要なパッケージとPHP拡張機能をインストール
RUN apt-get update && \
    apt-get install -y libpng-dev libjpeg-dev libxml2-dev && \
    docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd xmlrpc mysqli

ビルドする

docker-compose build --no-cache

--no-cacheは何となく付けといてもこれくらいの規模なら大丈夫、か?。

$ docker-compose build --no-cache
Building web
Sending build context to Docker daemon   2.56kB
Step 1/3 : FROM php:5.6-apache
 ---> 24c791995c1e
Step 2/3 : RUN echo "deb http://archive.debian.org/debian/ stretch main contrib non-free" > /etc/apt/sources.list &&     echo "deb-src http://archive.debian.org/debian/ stretch main contrib non-free" >> /etc/apt/sources.list &&     echo "Acquire::Check-Valid-Until false;" > /etc/apt/apt.conf
 ---> Running in 774f16a7347f
Removing intermediate container 774f16a7347f
 ---> 03c1474c8b4c
Step 3/3 : RUN apt-get update &&     apt-get install -y libpng-dev libjpeg-dev libxml2-dev &&     docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ &&     docker-php-ext-install gd xmlrpc mysqli
 ---> Running in 290b0949cb80
Ign:1 http://archive.debian.org/debian stretch InRelease
Get:2 http://archive.debian.org/debian stretch Release [118 kB]
Get:3 http://archive.debian.org/debian stretch Release.gpg [3177 B]
Get:4 http://archive.debian.org/debian stretch/non-free Sources [79.1 kB]
Get:5 http://archive.debian.org/debian stretch/contrib Sources [44.5 kB]
Get:6 http://archive.debian.org/debian stretch/main Sources [6736 kB]
Get:7 http://archive.debian.org/debian stretch/main amd64 Packages [7080 kB]
Get:8 http://archive.debian.org/debian stretch/contrib amd64 Packages [50.7 kB]
Get:9 http://archive.debian.org/debian stretch/non-free amd64 Packages [78.3 kB]
Fetched 14.2 MB in 6s (2041 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  icu-devtools libicu-dev libicu57 libjpeg62-turbo libjpeg62-turbo-dev
  libpng-tools libpng16-16 zlib1g-dev
Suggested packages:
  icu-doc
The following NEW packages will be installed:
  icu-devtools libicu-dev libjpeg-dev libjpeg62-turbo libjpeg62-turbo-dev
  libpng-dev libpng-tools libpng16-16 libxml2-dev zlib1g-dev
The following packages will be upgraded:
  libicu57
1 upgraded, 10 newly installed, 0 to remove and 46 not upgraded.
Need to get 26.4 MB of archives.
After this operation, 99.7 MB of additional disk space will be used.
Get:1 http://archive.debian.org/debian stretch/main amd64 libicu57 amd64 57.1-6+deb9u4 [7699 kB]
Get:2 http://archive.debian.org/debian stretch/main amd64 icu-devtools amd64 57.1-6+deb9u4 [178 kB]
Get:3 http://archive.debian.org/debian stretch/main amd64 libicu-dev amd64 57.1-6+deb9u4 [16.5 MB]
Get:4 http://archive.debian.org/debian stretch/main amd64 libjpeg62-turbo amd64 1:1.5.1-2 [134 kB]
Get:5 http://archive.debian.org/debian stretch/main amd64 libjpeg62-turbo-dev amd64 1:1.5.1-2 [210 kB]
Get:6 http://archive.debian.org/debian stretch/main amd64 libjpeg-dev all 1:1.5.1-2 [56.1 kB]
Get:7 http://archive.debian.org/debian stretch/main amd64 libpng16-16 amd64 1.6.28-1+deb9u1 [280 kB]
Get:8 http://archive.debian.org/debian stretch/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-5 [205 kB]
Get:9 http://archive.debian.org/debian stretch/main amd64 libpng-dev amd64 1.6.28-1+deb9u1 [250 kB]

enableして

# systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker

restart always
を付けつつ

docker-compose up -d

すると

$ docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED         STATUS         PORTS                               NAMES
f243493e0e8c   moodle-deployment_web   "docker-php-entrypoi…"   4 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   moodle-deployment_web_1

など上がってくる

自動起動完了後の設定

mysqlの設定も書き加える。やはりrestart: alwaysする

version: '3'

services:
  web:
    build: ./php/
    ports:
      - "80:80"
    volumes:
      - ./tests:/var/www/html
    restart: always
  db:
    image: mysql:5.6
    environment:
      - MYSQL_DATABASE=moodle
      - MYSQL_USER=moodle
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=root_password
    volumes:
      - ./db_data:/var/lib/mysql
    restart: always

down からの upとかしてmysqlがpullされればokっちゃok。これもシステムの再起動テストをしておいてもよいだろう。

$ docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED         STATUS          PORTS                               NAMES
1fed5b289968   mysql:5.6               "docker-entrypoint.s…"   4 minutes ago   Up 32 seconds   3306/tcp                            moodle-deployment_db_1
ecb93030ab36   moodle-deployment_web   "docker-php-entrypoi…"   4 minutes ago   Up 32 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   moodle-deployment_web_1

mysql5.6が上がっとる

moodle

  web:
    build: ./php/
    ports:
      - "80:80"
    volumes:
      - ./moodle:/var/www/html
    restart: always

volumeを変更してmoodleのソースツリーディレクトリを与える

あやしい…

まあ、あやしいこともあるでしょうな

このシステムはdataディレクトリを用意する必要があるから、docker-compose.yamlを適当に変更してそれを作っておく。

version: '3'

services:
  web:
    build: ./php/
    ports:
      - "80:80"
    volumes:
      - ./moodle:/var/www/html
      - ./moodle_data:/var/moodledata
    restart: always
  db:
    image: mysql:5.6
    environment:
      - MYSQL_DATABASE=moodle
      - MYSQL_USER=moodle
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=root_password
    volumes:
      - ./db_data:/var/lib/mysql
    restart: always

権限を揃えておく

$ sudo chown www-data moodle moodle_data/ -R


設定にもとづき適当に設定する。passwordはもうちょいしっかりした方がええかもな。serverはこの場合コンテナをdbにしたからdbである。

おっと

おこられたねーw
単純にmysqliにすればいいってことだったみたい

モジュールチェックok
言語はもう古すぎてオンラインダウンロード不可能

何でもかんでも揃うと思っていたらアカンわね。


つわけで何かかんか動かすなど。

DBとかデーターとか

まあこういうのは大抵引き継ぎ案件だと思うんだけど、DBはmysqlのdumpを取ってきて入れるだけ。そのときゃdocker-compose exec -Tとか使う必要があるかもしれぬ





この記事が気に入ったらサポートをしてみませんか?