こんにちは!
スマレジの テックファーム(SES 部門)のWebエンジニア やまて(@r_yamate) と申します。
はじめに
前回は、Docker での開発環境構築の内容について投稿しました。
本連載の目次
本連載では以下の順序で進めています。
今回の ② Zend Framework のインストール は、PHPのパッケージ依存管理ツールである Composer で、Zend Framework をインストールします。具体的には、 zendframework/ZendSkeletonApplication をインストールします。
目次
- はじめに
- 1. Composer バージョン1系のインストールの状況確認
- 2. Docker イメージ・コンテナの作成・起動
- 3. Composer での Zend Framework のインストール
- 4. 自動で作成されたディレクトリ及びファイルの確認
- 5. Zend Framework の Welcome 画面の確認
- おわりに
1. Composer バージョン1系のインストールの状況確認
Dockerコンテナを作成・起動した時に、Composerもインストールされていることを composer -V
で確認します。
# r_yamate @ mbp in ~/Documents/code/zend-framework-crud-sample on git:feature-install-zend-framework o [11:44:43] $ docker-compose exec app composer -V Composer version 1.10.25 2022-01-21 10:02:15
Composer をインストールするコマンドはこちらの Dockerfile に記述しています。
docker/php/Dockerfile
FROM smaregi/php:7.4.19-fpm-alpine3.13 AS php-base # timezone environment ENV TZ=Asia/Tokyo \ # composer environment COMPOSER_ALLOW_SUPERUSER=1 RUN set -xe \ && apk add --no-cache git=2.30.2-r0 \ && docker-php-ext-enable xdebug # composer のインストール # (バージョンを1系に指定する理由は、2系であると依存関係のエラーが出るため) COPY --from=composer:1 /usr/bin/composer /usr/bin/composer WORKDIR /var/www/self-order-web-app-old-api
バージョンを1系に指定する理由は、2系であると Zend Framework をインストールしようとする際に、パッケージ依存関係のエラーが出るためです。
2. Docker イメージ・コンテナの作成・起動
Dockerの開発環境を作成・起動します。
docker-compose up -d --build
コマンド実行結果
# r_yamate @ mbp in ~/Documents/code/zend-framework-crud-sample on git:feature-install-zend-framework o [11:44:09] $ docker-compose up -d --build [+] Building 4.6s (24/24) FINISHED => [zend-framework-crud-sample_app internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 598B 0.0s => [zend-framework-crud-sample_web internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 334B 0.0s => [zend-framework-crud-sample_db internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 376B 0.0s => [zend-framework-crud-sample_app internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [zend-framework-crud-sample_web internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [zend-framework-crud-sample_db internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [zend-framework-crud-sample_app internal] load metadata for docker.io/smaregi/php:7.4.19-fpm-alpine3.13 2.8s => [zend-framework-crud-sample_web internal] load metadata for docker.io/library/nginx:1.18.0-alpine 2.7s => [zend-framework-crud-sample_db internal] load metadata for docker.io/library/mysql:5.6 2.7s => [zend-framework-crud-sample_web 1/4] FROM docker.io/library/nginx:1.18.0-alpine@sha256:93baf2ec1bfefd04d29eb070900dd5d79b0f79863653453397e55a5b663a6cb1 0.0s => [zend-framework-crud-sample_web internal] load build context 0.0s => => transferring context: 1.19kB 0.0s => [zend-framework-crud-sample_db 1/3] FROM docker.io/library/mysql:5.6@sha256:20575ecebe6216036d25dab5903808211f1e9ba63dc7825ac20cb975e34cfcae 0.0s => [zend-framework-crud-sample_db internal] load build context 0.0s => => transferring context: 705B 0.0s => CACHED [zend-framework-crud-sample_web 2/4] RUN apk --update --no-cache add git zip unzip 0.0s => [zend-framework-crud-sample_web 3/4] COPY ./docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf 0.0s => CACHED [zend-framework-crud-sample_db 2/3] COPY ./docker/mysql/my.cnf /etc/mysql/conf.d/my.cnf 0.0s => CACHED [zend-framework-crud-sample_db 3/3] COPY ./docker/mysql/initdb.d /docker-entrypoint-initdb.d 0.0s => [zend-framework-crud-sample_app] exporting to image 0.1s => => exporting layers 0.0s => => writing image sha256:14334f6fe2b3695ba9e9b2eba516d9015a54bb4d4a14dc8130d983e2b25127bd 0.0s => => naming to docker.io/library/zend-framework-crud-sample_db 0.0s => => writing image sha256:1f655333704263da0789580576fea4036a0917d86ea17752a4eee2480c0bc536 0.0s => => naming to docker.io/library/zend-framework-crud-sample_web 0.0s => => writing image sha256:1128f1f63e26051a86e2dc7310b48001a9433cb6ea458a5a7d3b349188241d8a 0.0s => => naming to docker.io/library/zend-framework-crud-sample_app 0.0s => [zend-framework-crud-sample_app] FROM docker.io/library/composer:1 1.4s => => resolve docker.io/library/composer:1 1.4s => [zend-framework-crud-sample_app php-base 1/4] FROM docker.io/smaregi/php:7.4.19-fpm-alpine3.13@sha256:df94a4d40fefa82b345367602a3d01cb29fc2615e1ac6da295c96fb364817b28 0.0s => [zend-framework-crud-sample_web 4/4] WORKDIR /var/www/zf-sample/public 0.0s => CACHED [zend-framework-crud-sample_app php-base 2/4] RUN set -xe && apk add --no-cache git=2.30.2-r0 && docker-php-ext-enable xdebug 0.0s => CACHED [zend-framework-crud-sample_app php-base 3/4] COPY --from=composer:1 /usr/bin/composer /usr/bin/composer 0.0s => [zend-framework-crud-sample_app php-base 4/4] WORKDIR /var/www/zf-sample 0.0s Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them [+] Running 5/5 ⠿ Network zend-framework-crud-sample_default Created 0.1s ⠿ Volume "zend-framework-crud-sample_db-data" Created 0.0s ⠿ Container zend-framework-crud-sample_db_1 Started 0.9s ⠿ Container zend-framework-crud-sample_app_1 Started 2.1s ⠿ Container zend-framework-crud-sample_web_1 Started
3. Composer での Zend Framework のインストール
Composer で zendframework/skeleton-application をインストールするコマンドを実行します。
インストールすると、doc_root/ に ファイルが自動で作成されます。
docker-compose exec app composer create-project zendframework/skeleton-application .
# r_yamate @ mbp in ~/Documents/code/zend-framework-crud-sample on git:feature-install-zend-framework o [16:08:08] $ docker-compose exec app composer create-project zendframework/skeleton-application . Creating a "zendframework/skeleton-application" project at "./" [InvalidArgumentException] Project directory "/var/www/zf-sample/." is not empty. create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]
上記のエラーがでて、インストールできませんでした。
ディレクトリが空ではない というエラーが出ており、Dockerコンテナを作成した際に作成される doc_root/public ディレクトリを一旦削除します(doc_root ディレクトリは削除しない)。
↓
再度、 Composer で zendframework/skeleton-application をインストールするコマンドを実行します。
docker-compose exec app composer create-project zendframework/skeleton-application .
コマンド実行結果
# r_yamate @ mbp in ~/Documents/code/zend-framework-crud-sample on git:feature-install-zend-framework o [15:56:05] C:1 $ docker-compose exec app composer create-project zendframework/skeleton-application . Creating a "zendframework/skeleton-application" project at "./" Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/ Info from https://repo.packagist.org: #StandWithUkraine Installing zendframework/skeleton-application (3.1.3) - Installing zendframework/skeleton-application (3.1.3): Downloading (100%) Created project in /var/www/zf-sample/. Loading composer repositories with package information Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/ Info from https://repo.packagist.org: #StandWithUkraine Updating dependencies (including require-dev) Package operations: 19 installs, 0 updates, 0 removals - Installing zendframework/zend-component-installer (2.1.2): Downloading (100%) - Installing zendframework/zend-skeleton-installer (0.1.7): Downloading (100%) - Installing zendframework/zend-stdlib (3.2.1): Downloading (100%) - Installing zendframework/zend-loader (2.6.1): Downloading (100%) - Installing zendframework/zend-eventmanager (3.2.1): Downloading (100%) - Installing zendframework/zend-json (3.1.2): Downloading (100%) - Installing zendframework/zend-view (2.11.4): Downloading (100%) - Installing psr/container (1.1.2): Downloading (100%) - Installing container-interop/container-interop (1.2.0): Downloading (100%) - Installing zendframework/zend-servicemanager (3.4.0): Downloading (100%) - Installing zendframework/zend-validator (2.13.0): Downloading (100%) - Installing zendframework/zend-escaper (2.6.1): Downloading (100%) - Installing zendframework/zend-uri (2.7.1): Downloading (100%) - Installing zendframework/zend-http (2.11.2): Downloading (100%) - Installing zendframework/zend-router (3.3.0): Downloading (100%) - Installing zendframework/zend-config (3.3.0): Downloading (100%) - Installing zendframework/zend-modulemanager (2.8.4): Downloading (100%) - Installing zendframework/zend-mvc (3.1.1): Downloading (100%) - Installing zfcampus/zf-development-mode (3.2.0): Downloading (100%) zendframework/zend-json suggests installing zendframework/zend-json-server (For implementing JSON-RPC servers) zendframework/zend-json suggests installing zendframework/zend-xml2json (For converting XML documents to JSON) zendframework/zend-view suggests installing zendframework/zend-authentication (Zend\Authentication component) zendframework/zend-view suggests installing zendframework/zend-feed (Zend\Feed component) zendframework/zend-view suggests installing zendframework/zend-filter (Zend\Filter component) zendframework/zend-view suggests installing zendframework/zend-i18n (Zend\I18n component) zendframework/zend-view suggests installing zendframework/zend-mvc-plugin-flashmessenger (zend-mvc-plugin-flashmessenger component, if you want to use the FlashMessenger view helper with zend-mvc versions 3 and up) zendframework/zend-view suggests installing zendframework/zend-navigation (Zend\Navigation component) zendframework/zend-view suggests installing zendframework/zend-paginator (Zend\Paginator component) zendframework/zend-view suggests installing zendframework/zend-permissions-acl (Zend\Permissions\Acl component) zendframework/zend-servicemanager suggests installing ocramius/proxy-manager (ProxyManager 1.* to handle lazy initialization of services) zendframework/zend-validator suggests installing psr/http-message (psr/http-message, required when validating PSR-7 UploadedFileInterface instances via the Upload and UploadFile validators) zendframework/zend-validator suggests installing zendframework/zend-db (Zend\Db component, required by the (No)RecordExists validator) zendframework/zend-validator suggests installing zendframework/zend-filter (Zend\Filter component, required by the Digits validator) zendframework/zend-validator suggests installing zendframework/zend-i18n (Zend\I18n component to allow translation of validation error messages) zendframework/zend-validator suggests installing zendframework/zend-math (Zend\Math component, required by the Csrf validator) zendframework/zend-validator suggests installing zendframework/zend-i18n-resources (Translations of validator messages) zendframework/zend-validator suggests installing zendframework/zend-session (Zend\Session component, ^2.8; required by the Csrf validator) zendframework/zend-http suggests installing paragonie/certainty (For automated management of cacert.pem) zendframework/zend-router suggests installing zendframework/zend-i18n (^2.7.4, if defining translatable HTTP path segments) zendframework/zend-config suggests installing zendframework/zend-filter (^2.7.2; install if you want to use the Filter processor) zendframework/zend-config suggests installing zendframework/zend-i18n (^2.7.4; install if you want to use the Translator processor) zendframework/zend-modulemanager suggests installing zendframework/zend-console (Zend\Console component) zendframework/zend-mvc suggests installing zendframework/zend-log (^2.9.1 To provide log functionality via LogFilterManager, LogFormatterManager, and LogProcessorManager) zendframework/zend-mvc suggests installing zendframework/zend-mvc-console (zend-mvc-console provides the ability to expose zend-mvc as a console application) zendframework/zend-mvc suggests installing zendframework/zend-mvc-i18n (zend-mvc-i18n provides integration with zend-i18n, including a translation bridge and translatable route segments) zendframework/zend-mvc suggests installing zendframework/zend-mvc-plugin-fileprg (To provide Post/Redirect/Get functionality around forms that container file uploads) zendframework/zend-mvc suggests installing zendframework/zend-mvc-plugin-flashmessenger (To provide flash messaging capabilities between requests) zendframework/zend-mvc suggests installing zendframework/zend-mvc-plugin-identity (To access the authenticated identity (per zend-authentication) in controllers) zendframework/zend-mvc suggests installing zendframework/zend-mvc-plugin-prg (To provide Post/Redirect/Get functionality within controllers) zendframework/zend-mvc suggests installing zendframework/zend-paginator (^2.7 To provide pagination functionality via PaginatorPluginManager) zendframework/zend-mvc suggests installing zendframework/zend-psr7bridge ((^0.2) To consume PSR-7 middleware within the MVC workflow) zendframework/zend-mvc suggests installing zendframework/zend-servicemanager-di (zend-servicemanager-di provides utilities for integrating zend-di and zend-servicemanager in your zend-mvc application) zendframework/zend-mvc suggests installing zendframework/zend-stratigility (zend-stratigility is required to use middleware pipes in the MiddlewareListener) zendframework/zend-mvc suggests installing http-interop/http-middleware (^0.4.1 to be used together with zend-stratigility) Package zendframework/zend-component-installer is abandoned, you should avoid using it. Use laminas/laminas-component-installer instead. Package zendframework/zend-skeleton-installer is abandoned, you should avoid using it. Use laminas/laminas-skeleton-installer instead. Package zendframework/zend-stdlib is abandoned, you should avoid using it. Use laminas/laminas-stdlib instead. Package zendframework/zend-loader is abandoned, you should avoid using it. Use laminas/laminas-loader instead. Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead. Package zendframework/zend-json is abandoned, you should avoid using it. Use laminas/laminas-json instead. Package zendframework/zend-view is abandoned, you should avoid using it. Use laminas/laminas-view instead. Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead. Package zendframework/zend-servicemanager is abandoned, you should avoid using it. Use laminas/laminas-servicemanager instead. Package zendframework/zend-validator is abandoned, you should avoid using it. Use laminas/laminas-validator instead. Package zendframework/zend-escaper is abandoned, you should avoid using it. Use laminas/laminas-escaper instead. Package zendframework/zend-uri is abandoned, you should avoid using it. Use laminas/laminas-uri instead. Package zendframework/zend-http is abandoned, you should avoid using it. Use laminas/laminas-http instead. Package zendframework/zend-router is abandoned, you should avoid using it. Use laminas/laminas-router instead. Package zendframework/zend-config is abandoned, you should avoid using it. Use laminas/laminas-config instead. Package zendframework/zend-modulemanager is abandoned, you should avoid using it. Use laminas/laminas-modulemanager instead. Package zendframework/zend-mvc is abandoned, you should avoid using it. Use laminas/laminas-mvc instead. Package zfcampus/zf-development-mode is abandoned, you should avoid using it. Use laminas/laminas-development-mode instead. Writing lock file Generating autoload files Do you want a minimal install (no optional packages)? Y/n Y Removing optional packages from composer.json Updating composer.json Removing zendframework/zend-skeleton-installer... - Removing zendframework/zend-skeleton-installer (0.1.7) Removed plugin zendframework/zend-skeleton-installer. Removing from composer.json Complete! > zf-development-mode enable You are now in development mode. > php bin/update-gitignore.php
Do you want a minimal install (no optional packages)? Y/n (最小限のインストール(オプションのパッケージなし)を希望しますか? Y/n)
と聞かれるので、 Y
を入力します。必要なパッケージは後で追加できるため、必要になったタイミングで都度、パッケージをインストールします。
4. 自動で作成されたディレクトリ及びファイルの確認
doc_root/ 以下については、zendframework/skeleton-application
のインストール時に、自動で以下のような構成でディレクトリ及びファイルが作成されます。
5. Zend Framework の Welcome 画面の確認
ブラウザで、 http://localhost/ にアクセスし、Zend Framework の Welcome 画面が表示されることを確認します。
このような画面が表示されれば、 Zend Framework が正しくインストールされています。
※ 正しく表示されず、nginx の 404 Not Found になる場合は、Dockerコンテナを再起動するなど試してみてください。
おわりに
今回の ② Zend Framework のインストール は、PHPのパッケージ依存管理ツールである Composer で、Zend Framework をインストールしました。
次回、 ③ 一覧画面の作成 を投稿します。
参考
- 公式ドキュメント(参考にしたページ)
- zendframework/ZendSkeletonApplication の GitHub(Zend Framework はアーカイブになっています)
本記事完了時点のソースコード
本記事完了時点のソースコードをGitHub上に公開しています。
以下は変更差分です。