【 PHP 】PHP8に入門してみた 20日目 環境構築を進める ( DBを構築する )

PHP8技術者認定初級試験 が始まるようなので 試験に向けて (できるだけ)勉強しようと思います! 使用する書籍は独習PHP 第4版(山田 祥寛)|翔泳社の本 (shoeisha.co.jp) となります。

環境構築を進める

DB(データベース)は後回し!と思っていたのですが参考書籍のイントロダクションでデータの登録が行われていました。

なのでDBをまずは起動しないといけないようです😑

DBがダウンしているので調査し起動する

とりあえずMariaサービス単体でコンテナ起動してみます。

PS C:\Users\ikeda> cd D:\dockers\files\php8_study\.devcontainer
PS D:\dockers\files\php8_study\.devcontainer> docker-compose up mysql
Creating network "devcontainer_default" with the default driver
Creating devcontainer_mysql_1 ... done
Attaching to devcontainer_mysql_1
mysql_1 | 2022-09-01 19:59:17+09:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.8.3+maria~jammy started.
mysql_1 | 2022-09-01 19:59:17+09:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
mysql_1 | command was: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_ja_0900_as_cs_ks --verbose --help --log-bin-index=/tmp/tmp.uVWTEMMQKH
mysql_1 | 2022-09-01 19:59:17 0 [ERROR] Unknown collation: 'utf8mb4_ja_0900_as_cs_ks'
devcontainer_mysql_1 exited with code 1
PS D:\dockers\files\php8_study\.devcontainer>

 

[ERROR] Unknown collation: 'utf8mb4_ja_0900_as_cs_ks'と言われてしまいましたね。

こちらのサイトに記載されているように、MariaDBでは'utf8mb4_ja_0900_as_cs_ks'は使用できなくなったとのことです。

[SQL]MariaDBで絵文字保存 – Fatware を参考に、utf8mb4_unicode_ciを使ってみることにしました。

今回の修正対象はdocker-compose.ymlです。

絵文字が保存できるようになるそうです。

(今回あまり関係なさそうです)

一度コンテナを停止・削除してコンテナを起動します。

どうやらうまく起動できたようですね。

PS D:\dockers\files\php8_study\.devcontainer> docker-compose stop mysql
PS D:\dockers\files\php8_study\.devcontainer> docker-compose rm -f mysql
Going to remove devcontainer_mysql_1
Removing devcontainer_mysql_1 ... done
PS D:\dockers\files\php8_study\.devcontainer> docker-compose up mysql
Creating devcontainer_mysql_1 ... done
Attaching to devcontainer_mysql_1
mysql_1 | 2022-09-01 20:14:39+09:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.8.3+maria~jammy started.
mysql_1 | 2022-09-01 20:14:39+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2022-09-01 20:14:39+09:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.8.3+maria~jammy started.
mysql_1 | 2022-09-01 20:14:39+09:00 [Note] [Entrypoint]: Initializing database files
mysql_1 |
mysql_1 |
mysql_1 | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
mysql_1 | To do so, start the server, then issue the following command:
mysql_1 |
mysql_1 | '/usr/bin/mysql_secure_installation'
mysql_1 |
mysql_1 | which will also give you the option of removing the test
mysql_1 | databases and anonymous user created by default. This is
mysql_1 | strongly recommended for production servers.
mysql_1 |
mysql_1 | See the MariaDB Knowledgebase at https://mariadb.com/kb
mysql_1 |
mysql_1 | Please report any problems at https://mariadb.org/jira
mysql_1 |
mysql_1 | The latest information about MariaDB is available at https://mariadb.org/.
mysql_1 |
mysql_1 | Consider joining MariaDB's strong and vibrant community:
mysql_1 | https://mariadb.org/get-involved/
mysql_1 |
mysql_1 | 2022-09-01 20:14:45+09:00 [Note] [Entrypoint]: Database files initialized
mysql_1 | 2022-09-01 20:14:45+09:00 [Note] [Entrypoint]: Starting temporary server
mysql_1 | 2022-09-01 20:14:45+09:00 [Note] [Entrypoint]: Waiting for server startup
mysql_1 | 2022-09-01 20:14:45 0 [Note] mysqld (server 10.8.3-MariaDB-1:10.8.3+maria~jammy) starting as process 97 ...
mysql_1 | 2022-09-01 20:14:45 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Number of transaction pools: 1
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
mysql_1 | 2022-09-01 20:14:45 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Using liburing
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1 | 2022-09-01 20:14:45 0 [Note] InnoDB: 128 rollback segments are active.
mysql_1 | 2022-09-01 20:14:46 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
mysql_1 | 2022-09-01 20:14:46 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
mysql_1 | 2022-09-01 20:14:46 0 [Note] InnoDB: log sequence number 46643; transaction id 14
mysql_1 | 2022-09-01 20:14:46 0 [Note] Plugin 'FEEDBACK' is disabled.
mysql_1 | 2022-09-01 20:14:46 0 [Warning] 'user' entry 'root@507622f38841' ignored in --skip-name-resolve mode.
mysql_1 | 2022-09-01 20:14:46 0 [Warning] 'proxies_priv' entry '@% root@507622f38841' ignored in --skip-name-resolve mode.
mysql_1 | 2022-09-01 20:14:46 0 [Note] mysqld: ready for connections.
mysql_1 | Version: '10.8.3-MariaDB-1:10.8.3+maria~jammy' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution
mysql_1 | 2022-09-01 20:14:46+09:00 [Note] [Entrypoint]: Temporary server started.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mysql_1 | 2022-09-01 20:14:49+09:00 [Note] [Entrypoint]: Securing system users (equivalent to running mysql_secure_installation)
mysql_1 | 2022-09-01 20:14:49+09:00 [Note] [Entrypoint]: Creating database docker
mysql_1 | 2022-09-01 20:14:49+09:00 [Note] [Entrypoint]: Creating user docker
mysql_1 | 2022-09-01 20:14:49+09:00 [Note] [Entrypoint]: Giving user docker access to schema docker
mysql_1 |
mysql_1 | 2022-09-01 20:14:49+09:00 [Note] [Entrypoint]: Stopping temporary server
mysql_1 | 2022-09-01 20:14:49 0 [Note] mysqld (initiated by: root[root] @ localhost []): Normal shutdown
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: FTS optimize thread exiting.
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: Starting shutdown...
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: Buffer pool(s) dump completed at 220901 20:14:49
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
mysql_1 | 2022-09-01 20:14:49 0 [Note] InnoDB: Shutdown completed; log sequence number 46643; transaction id 15
mysql_1 | 2022-09-01 20:14:49 0 [Note] mysqld: Shutdown complete
mysql_1 |
mysql_1 | 2022-09-01 20:14:50+09:00 [Note] [Entrypoint]: Temporary server stopped
mysql_1 |
mysql_1 | 2022-09-01 20:14:50+09:00 [Note] [Entrypoint]: MariaDB init process done. Ready for start up.
mysql_1 |
mysql_1 | 2022-09-01 20:14:50 0 [Note] mysqld (server 10.8.3-MariaDB-1:10.8.3+maria~jammy) starting as process 1 ...
mysql_1 | 2022-09-01 20:14:50 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Number of transaction pools: 1
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
mysql_1 | 2022-09-01 20:14:50 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Using liburing
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: 128 rollback segments are active.
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: log sequence number 46643; transaction id 14
mysql_1 | 2022-09-01 20:14:50 0 [Note] Plugin 'FEEDBACK' is disabled.
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1 | 2022-09-01 20:14:50 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
mysql_1 | 2022-09-01 20:14:50 0 [Note] InnoDB: Buffer pool(s) load completed at 220901 20:14:50
mysql_1 | 2022-09-01 20:14:50 0 [Note] Server socket created on IP: '0.0.0.0'.
mysql_1 | 2022-09-01 20:14:50 0 [Note] Server socket created on IP: '::'.
mysql_1 | 2022-09-01 20:14:50 0 [Note] mysqld: ready for connections.
mysql_1 | Version: '10.8.3-MariaDB-1:10.8.3+maria~jammy' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution

確認できたのでCtrl + C で抜けておきます(コンテナは停止します。)

docker-compose.yml

docker-compose.ymlは以下のようになりました。

version: "3.9"

services:
  workspace:
    build:
      context: ./docker/workspace
      args:
        USERNAME: ${USERNAME-vscode}
        USER_UID: ${USER_UID-1000}
        USER_GID: ${USER_GID-1000}
        TIME_ZONE: ${TIME_ZONE-UTC}
        LOCALE: ${LOCALE-C}
    tty: true
    volumes:
      - ../:/var/www
      - ./docker/workspace/config/php.ini:/usr/local/etc/php/conf.d/99-php.ini
    working_dir: /var/www

  nginx:
    build: ./docker/nginx
    ports:
      - "${IP_ADDRESS_SETTING}80:80"
      - "${IP_ADDRESS_SETTING}443:443"
    volumes:
      - ./docker/nginx/config:/etc/nginx/conf.d
      - ../.docker/nginx/log:/var/log/nginx
      - ../:/var/www
    environment:
      TZ: ${TIME_ZONE-UTC}

  php:
    build:
      context: ./docker/php
      args:
        USER_UID: ${USER_UID-1000}
        USER_GID: ${USER_GID-1000}
    volumes:
      - ./docker/php/config/php.ini:/usr/local/etc/php/php.ini
      - ./docker/php/config/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
      - ../:/var/www
    working_dir: /var/www

  mysql:
    image: mariadb:10.8.3
    ports:
      - "${IP_ADDRESS_SETTING}3306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD-docker}
      MYSQL_USER: ${DB_USERNAME-docker}
      MYSQL_PASSWORD: ${DB_PASSWORD-docker}
      MYSQL_DATABASE: ${DB_DATABASE-docker}
      TZ: ${TIME_ZONE-UTC}
    command:
      - mysqld
      - --character-set-server=utf8mb4
      #- --collation-server=utf8mb4_ja_0900_as_cs_ks
      - --collation-server=utf8mb4_unicode_ci


 

メモ

次はデータ投入!

PHPPHP

Posted by raika@blog