3
2

More than 1 year has passed since last update.

RHEL8.4にDocker x Laravelの環境を構築する

Posted at

概要

初めてRHEL(Red hat enterprise linux)上に1からLaravelの環境構築を行なったので、備忘録として手順を残しておこうと思います。
※当方、Red hatってなに?他のLinuxと何が違うの?サブスクリプション?ってレベルです。

前提

既にローカルでDockerにてLaravelの環境を作成しているものとします。
また今回は、LaravelのWelcomeページを表示する所まででゴールとする。

dockerコンテナは下記の2つ。
・app
→PHP(Laravel)用コンテナ。
・web
→nginx用コンテナ。

環境確認

[rarsQ@Test-api ~]$ sudo su
[root@Test-api rarsQ]# uname -a
Linux Test.jp 4.18.0-305.el8.x86_64 #1 SMP Thu Apr 29 08:54:30 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux

サブスクリプションの確認

Git,Docker等をインストールする為、サブスクリプションを登録する。
「サブスクライブ登録済み」になっていない場合は、登録作業を先に行う。

[root@Test-api rarsQ]# subscription-manager list
+-------------------------------------------+
    インストール済み製品のステータス
+-------------------------------------------+
製品名:           Red Hat Enterprise Linux for x86_64
製品 ID:          479
バージョン:       8.4
アーキテクチャー: x86_64
状態:             サブスクライブ済み
状態の詳細:
開始:             2018年05月30日
終了:             2023年05月30日

Gitのインストール

[root@Test-api rarsQ]# yum install git
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                                                                            15 kB/s | 4.5 kB     00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                                                                            31 MB/s |  39 MB     00:01
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                                                               20 kB/s | 4.1 kB     00:00
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                                                               37 MB/s |  45 MB     00:01
メタデータの期限切れの最終確認: 0:00:07 時間前の 2022年03月24日 18時10分47秒 に実施しました。
依存関係が解決しました。
===================================================================================================================================================================================
 パッケージ                            アーキテクチャー                バージョン                                  リポジトリー                                              サイズ
===================================================================================================================================================================================
インストール:
 git                                   x86_64                          2.27.0-1.el8                                rhel-8-for-x86_64-appstream-rpms                          164 k
依存関係のインストール:
 git-core                              x86_64                          2.27.0-1.el8                                rhel-8-for-x86_64-appstream-rpms                          5.7 M
 git-core-doc                          noarch                          2.27.0-1.el8                                rhel-8-for-x86_64-appstream-rpms                          2.5 M
 perl-Error                            noarch                          1:0.17025-2.el8                             rhel-8-for-x86_64-appstream-rpms                           46 k
 perl-Git                              noarch                          2.27.0-1.el8                                rhel-8-for-x86_64-appstream-rpms                           78 k

トランザクションの概要
===================================================================================================================================================================================
インストール  5 パッケージ

ダウンロードサイズの合計: 8.5 M
インストール後のサイズ: 45 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/5): perl-Git-2.27.0-1.el8.noarch.rpm                                                                                                            350 kB/s |  78 kB     00:00
(2/5): perl-Error-0.17025-2.el8.noarch.rpm                                                                                                         201 kB/s |  46 kB     00:00
(3/5): git-2.27.0-1.el8.x86_64.rpm                                                                                                                 993 kB/s | 164 kB     00:00
(4/5): git-core-doc-2.27.0-1.el8.noarch.rpm                                                                                                         11 MB/s | 2.5 MB     00:00
(5/5): git-core-2.27.0-1.el8.x86_64.rpm                                                                                                            8.7 MB/s | 5.7 MB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                                                13 MB/s | 8.5 MB     00:00
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                                                                                           1/1
  インストール中   : git-core-2.27.0-1.el8.x86_64                                                                                                                              1/5
  インストール中   : git-core-doc-2.27.0-1.el8.noarch                                                                                                                          2/5
  インストール中   : perl-Error-1:0.17025-2.el8.noarch                                                                                                                         3/5
  インストール中   : git-2.27.0-1.el8.x86_64                                                                                                                                   4/5
  インストール中   : perl-Git-2.27.0-1.el8.noarch                                                                                                                              5/5
  scriptletの実行中: perl-Git-2.27.0-1.el8.noarch                                                                                                                              5/5
  検証             : perl-Error-1:0.17025-2.el8.noarch                                                                                                                         1/5
  検証             : git-core-2.27.0-1.el8.x86_64                                                                                                                              2/5
  検証             : perl-Git-2.27.0-1.el8.noarch                                                                                                                              3/5
  検証             : git-2.27.0-1.el8.x86_64                                                                                                                                   4/5
  検証             : git-core-doc-2.27.0-1.el8.noarch                                                                                                                          5/5
Installed products updated.

インストール済み:
  git-2.27.0-1.el8.x86_64      git-core-2.27.0-1.el8.x86_64      git-core-doc-2.27.0-1.el8.noarch      perl-Error-1:0.17025-2.el8.noarch      perl-Git-2.27.0-1.el8.noarch

完了しました!

Dockerのインストール

yum-utilsパッケージをインストール

[root@Test-api rarsQ]# yum install -y yum-utils
Updating Subscription Management repositories.
メタデータの期限切れの最終確認: 1:02:24 時間前の 2022年03月24日 18時10分47秒 に実施しました。
依存関係が解決しました。
===================================================================================================================================================================================
 パッケージ                                      アーキテクチャー              バージョン                               リポジトリー                                         サイズ
===================================================================================================================================================================================
インストール:
 yum-utils                                       noarch                        4.0.21-4.el8_5                           rhel-8-for-x86_64-baseos-rpms                         73 k
アップグレード:
 dnf-plugins-core                                noarch                        4.0.21-4.el8_5                           rhel-8-for-x86_64-baseos-rpms                         70 k
 python3-dnf-plugins-core                        noarch                        4.0.21-4.el8_5                           rhel-8-for-x86_64-baseos-rpms                        234 k

トランザクションの概要
===================================================================================================================================================================================
インストール    1 パッケージ
アップグレード  2 パッケージ

ダウンロードサイズの合計: 377 k
パッケージのダウンロード:
(1/3): dnf-plugins-core-4.0.21-4.el8_5.noarch.rpm                                                                                                  288 kB/s |  70 kB     00:00
(2/3): yum-utils-4.0.21-4.el8_5.noarch.rpm                                                                                                         285 kB/s |  73 kB     00:00
(3/3): python3-dnf-plugins-core-4.0.21-4.el8_5.noarch.rpm                                                                                          854 kB/s | 234 kB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                                               1.3 MB/s | 377 kB     00:00
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                                                                                           1/1
  アップグレード中 : python3-dnf-plugins-core-4.0.21-4.el8_5.noarch                                                                                                            1/5
  アップグレード中 : dnf-plugins-core-4.0.21-4.el8_5.noarch                                                                                                                    2/5
  インストール中   : yum-utils-4.0.21-4.el8_5.noarch                                                                                                                           3/5
  整理             : dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                      4/5
  整理             : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                              5/5
  scriptletの実行中: python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                              5/5
  検証             : yum-utils-4.0.21-4.el8_5.noarch                                                                                                                           1/5
  検証             : python3-dnf-plugins-core-4.0.21-4.el8_5.noarch                                                                                                            2/5
  検証             : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                              3/5
  検証             : dnf-plugins-core-4.0.21-4.el8_5.noarch                                                                                                                    4/5
  検証             : dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                      5/5
Installed products updated.

アップグレード済み:
  dnf-plugins-core-4.0.21-4.el8_5.noarch                                               python3-dnf-plugins-core-4.0.21-4.el8_5.noarch
インストール済み:
  yum-utils-4.0.21-4.el8_5.noarch

完了しました!

Dockerリポジトリの追加

[root@Test-api rarsQ]# dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Updating Subscription Management repositories.
repo の追加: https://download.docker.com/linux/centos/docker-ce.repo

Dockerインストール実施

※podman, buildahが競合したので、--allowerasingオプションで置き換える。

[root@Test-api rarsQ]# dnf install --allowerasing  docker-ce docker-ce-cli containerd.io
Updating Subscription Management repositories.
Docker CE Stable - x86_64                                                                                                                           57 kB/s | 3.5 kB     00:00
依存関係が解決しました。
===================================================================================================================================================================================
 パッケージ                                 アーキテクチャー        バージョン                                                リポジトリー                                   サイズ
===================================================================================================================================================================================
インストール:
 containerd.io                              x86_64                  1.5.11-3.1.el8                                            docker-ce-stable                                29 M
     置き換え  runc.x86_64 1.0.0-70.rc92.module+el8.4.0+10607+f4da7515
 docker-ce                                  x86_64                  3:20.10.14-3.el8                                          docker-ce-stable                                22 M
 docker-ce-cli                              x86_64                  1:20.10.14-3.el8                                          docker-ce-stable                                30 M
依存関係のインストール:
 docker-ce-rootless-extras                  x86_64                  20.10.14-3.el8                                            docker-ce-stable                               4.6 M
 docker-scan-plugin                         x86_64                  0.17.0-3.el8                                              docker-ce-stable                               3.8 M
 libcgroup                                  x86_64                  0.41-19.el8                                               rhel-8-for-x86_64-baseos-rpms                   70 k
依存関係パッケージの削除:
 buildah                                    x86_64                  1.19.7-1.module+el8.4.0+10607+f4da7515                    @AppStream                                      27 M
 cockpit-podman                             noarch                  29-2.module+el8.4.0+10607+f4da7515                        @AppStream                                     3.8 M
 podman                                     x86_64                  3.0.1-6.module+el8.4.0+10607+f4da7515                     @AppStream                                      46 M
 podman-catatonit                           x86_64                  3.0.1-6.module+el8.4.0+10607+f4da7515                     @AppStream                                     760 k

トランザクションの概要
===================================================================================================================================================================================
インストール  6 パッケージ
削除          4 パッケージ

ダウンロードサイズの合計: 89 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/6): docker-ce-20.10.14-3.el8.x86_64.rpm                                                                                                          18 MB/s |  22 MB     00:01
(2/6): containerd.io-1.5.11-3.1.el8.x86_64.rpm                                                                                                      20 MB/s |  29 MB     00:01
(3/6): docker-ce-cli-20.10.14-3.el8.x86_64.rpm                                                                                                      19 MB/s |  30 MB     00:01
(4/6): docker-ce-rootless-extras-20.10.14-3.el8.x86_64.rpm                                                                                          11 MB/s | 4.6 MB     00:00
(5/6): docker-scan-plugin-0.17.0-3.el8.x86_64.rpm                                                                                                   18 MB/s | 3.8 MB     00:00
(6/6): libcgroup-0.41-19.el8.x86_64.rpm                                                                                                            166 kB/s |  70 kB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                                                45 MB/s |  89 MB     00:02
警告: /var/cache/dnf/docker-ce-stable-fa9dc42ab4cec2f4/packages/containerd.io-1.5.11-3.1.el8.x86_64.rpm: ヘッダー V4 RSA/SHA512 Signature、鍵 ID 621e9f35: NOKEY
Docker CE Stable - x86_64                                                                                                                           24 kB/s | 1.6 kB     00:00
GPG 鍵 0x621E9F35 をインポート中:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
これでよろしいですか? [y/N]: y
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                                                                                           1/1
  scriptletの実行中: docker-scan-plugin-0.17.0-3.el8.x86_64                                                                                                                    1/1
  インストール中   : docker-scan-plugin-0.17.0-3.el8.x86_64                                                                                                                   1/11
  scriptletの実行中: docker-scan-plugin-0.17.0-3.el8.x86_64                                                                                                                   1/11
  インストール中   : docker-ce-cli-1:20.10.14-3.el8.x86_64                                                                                                                    2/11
  scriptletの実行中: docker-ce-cli-1:20.10.14-3.el8.x86_64                                                                                                                    2/11
  scriptletの実行中: libcgroup-0.41-19.el8.x86_64                                                                                                                             3/11
  インストール中   : libcgroup-0.41-19.el8.x86_64                                                                                                                             3/11
  scriptletの実行中: libcgroup-0.41-19.el8.x86_64                                                                                                                             3/11
  インストール中   : containerd.io-1.5.11-3.1.el8.x86_64                                                                                                                      4/11
  scriptletの実行中: containerd.io-1.5.11-3.1.el8.x86_64                                                                                                                      4/11
  インストール中   : docker-ce-rootless-extras-20.10.14-3.el8.x86_64                                                                                                          5/11
  scriptletの実行中: docker-ce-rootless-extras-20.10.14-3.el8.x86_64                                                                                                          5/11
  インストール中   : docker-ce-3:20.10.14-3.el8.x86_64                                                                                                                        6/11
  scriptletの実行中: docker-ce-3:20.10.14-3.el8.x86_64                                                                                                                        6/11
  削除             : cockpit-podman-29-2.module+el8.4.0+10607+f4da7515.noarch                                                                                                 7/11
  削除             : podman-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64                                                                                                      8/11
  scriptletの実行中: podman-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64                                                                                                      8/11
  削除             : buildah-1.19.7-1.module+el8.4.0+10607+f4da7515.x86_64                                                                                                    9/11
  削除             : podman-catatonit-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64                                                                                           10/11
  廃止             : runc-1.0.0-70.rc92.module+el8.4.0+10607+f4da7515.x86_64                                                                                                 11/11
  scriptletの実行中: runc-1.0.0-70.rc92.module+el8.4.0+10607+f4da7515.x86_64                                                                                                 11/11
  検証             : containerd.io-1.5.11-3.1.el8.x86_64                                                                                                                      1/11
  検証             : runc-1.0.0-70.rc92.module+el8.4.0+10607+f4da7515.x86_64                                                                                                  2/11
  検証             : docker-ce-3:20.10.14-3.el8.x86_64                                                                                                                        3/11
  検証             : docker-ce-cli-1:20.10.14-3.el8.x86_64                                                                                                                    4/11
  検証             : docker-ce-rootless-extras-20.10.14-3.el8.x86_64                                                                                                          5/11
  検証             : docker-scan-plugin-0.17.0-3.el8.x86_64                                                                                                                   6/11
  検証             : libcgroup-0.41-19.el8.x86_64                                                                                                                             7/11
  検証             : buildah-1.19.7-1.module+el8.4.0+10607+f4da7515.x86_64                                                                                                    8/11
  検証             : cockpit-podman-29-2.module+el8.4.0+10607+f4da7515.noarch                                                                                                 9/11
  検証             : podman-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64                                                                                                     10/11
  検証             : podman-catatonit-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64                                                                                           11/11
Installed products updated.

インストール済み:
  containerd.io-1.5.11-3.1.el8.x86_64        docker-ce-3:20.10.14-3.el8.x86_64     docker-ce-cli-1:20.10.14-3.el8.x86_64     docker-ce-rootless-extras-20.10.14-3.el8.x86_64
  docker-scan-plugin-0.17.0-3.el8.x86_64     libcgroup-0.41-19.el8.x86_64
削除しました:
  buildah-1.19.7-1.module+el8.4.0+10607+f4da7515.x86_64           cockpit-podman-29-2.module+el8.4.0+10607+f4da7515.noarch   podman-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64
  podman-catatonit-3.0.1-6.module+el8.4.0+10607+f4da7515.x86_64

完了しました!

インストールの確認

[root@Test-api rarsQ]# dnf list installed | grep docker-ce
containerd.io.x86_64                               1.5.11-3.1.el8                                 @docker-ce-stable
docker-ce.x86_64                                   3:20.10.14-3.el8                               @docker-ce-stable
docker-ce-cli.x86_64                               1:20.10.14-3.el8                               @docker-ce-stable
docker-ce-rootless-extras.x86_64                   20.10.14-3.el8                                 @docker-ce-stable
docker-scan-plugin.x86_64                          0.17.0-3.el8                                   @docker-ce-stable

docker-composeのインストール

[root@Test-api rarsQ]# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   2371      0 --:--:-- --:--:-- --:--:--  2371
100 12.1M  100 12.1M    0     0  15.3M      0 --:--:-- --:--:-- --:--:-- 44.2M
[root@Test-api rarsQ]# sudo chmod +x /usr/local/bin/docker-compose
[root@Test-api rarsQ]# sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
[root@Test-api rarsQ]# docker-compose --version
docker-compose version 1.29.2, build 5becea4c

以上で、Git,dockerのインストールは完了。
ここまでくれば、あとは通常通りLaravelの環境作成するだけ。

Laravel環境の作成

プロジェクトのクローン

[rarsQ@Test-api ~]$ cd /var/www/html/
[rarsQ@Test-api html]$ sudo git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/hoge-api
Cloning into 'hoge-api'...
Username for 'https://git-codecommit.ap-northeast-1.amazonaws.com': rarsQ@test.jp+1-at-12346999445
Password for 'https://rarsQ@test.jp+1-at-12346999445@git-codecommit.ap-northeast-1.amazonaws.com':
remote: Counting objects: 335, done.
Receiving objects: 100% (335/335), 3.41 MiB | 6.17 MiB/s, done.
Resolving deltas: 100% (111/111), done.
[rarsQ@Test-api html]$ cd hoge-api/
[rarsQ@Test-api hoge-api]$ ls -la
合計 16
drwxr-xr-x  5 root root  105  3月 25 15:22 .
drwxr-xr-x  3 root root   29  3月 25 15:21 ..
drwxr-xr-x  8 root root  163  3月 25 15:22 .git
-rw-r--r--  1 root root 3897  3月 25 15:22 Makefile
-rw-r--r--  1 root root 1663  3月 25 15:22 README.md
drwxr-xr-x 11 root root 4096  3月 25 15:22 backend
-rw-r--r--  1 root root 1617  3月 25 15:22 docker-compose.yml
drwxr-xr-x  3 root root   20  3月 25 15:22 infra

dockerコンテナ立ち上げ

初回ビルドが実施される

[rarsQ@Test-api hoge-api]$ systemctl start docker
[rarsQ@Test-api hoge-api]$ sudo docker-compose up -d
Building app
Sending build context to Docker daemon  93.14MB
Step 1/10 : FROM php:7.4-fpm
 ---> da80dfec1b97
Step 2/10 : SHELL ["/bin/bash", "-oeux", "pipefail", "-c"]
 ---> Using cache
 ---> ad484553b9bb
Step 3/10 : ENV TZ=UTC   LANG=ja_JP.UTF-8   LANGUAGE=ja_JP:en   LC_ALL=ja_JP.UTF-8   COMPOSER_ALLOW_SUPERUSER=1   COMPOSER_HOME=/composer   LD_LIBRARY_PATH=/usr/local/instantclient   TNS_ADMIN=/usr/local/instantclient
 ---> Using cache
 ---> 2e6eeb526a65
Step 4/10 : COPY --from=composer:2.1 /usr/bin/composer /usr/bin/composer
 ---> Using cache
 ---> 6496e0de5601
Step 5/10 : COPY ./infra/docker/php/instantclient-basic-linux.x64-12.2.0.1.0.zip /tmp
 ---> be587957aae0
Step 6/10 : COPY ./infra/docker/php/instantclient-sdk-linux.x64-12.2.0.1.0.zip /tmp
 ---> 32182b6f03c7
.
.
.
.
.
Creating test-api_1 ... done
Creating test-web_1 ... done

composerインストール

[rarsQ@Test-api hoge-api]$ sudo docker-compose exec app bash
root@890fc9739e74:/work/backend# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 151 installs, 0 updates, 0 removals
  - Downloading composer/package-versions-deprecated (1.11.99.4)
  - Downloading symfony/polyfill-mbstring (v1.24.0)
  - Downloading mtdowling/jmespath.php (2.6.1)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-message (1.0.1)
  .
  .
  .
  Package manifest generated successfully.
99 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
root@890fc9739e74:/work/backend# exit
exit

.envの作成

[rarsQ@Test-api backend]$ cd backend/
[rarsQ@Test-api backend]$ sudo cp .env.example .env
[rarsQ@Test-api backend]$ ls -la
合計 1576
drwxr-xr-x 13 root root    4096  3月 25 16:51 .
drwxr-xr-x  5 root root     105  3月 25 15:38 ..
-rw-r--r--  1 root root     258  3月 25 15:22 .editorconfig
APP_NAME=Laravel
APP_ENV=production
-rw-r--r--  1 root root     901  3月 25 16:51 .env
-rw-r--r--  1 root root     901  3月 25 15:38 .env.example
APP_NAME=Laravel
-rw-r--r--  1 root root     111  3月 25 15:22 .gitattributes
-rw-r--r--  1 root root     207  3月 25 15:22 .gitignore
-rw-r--r--  1 root root     443  3月 25 15:22 .php-cs-fixer.dist.php
-rw-r--r--  1 root root     194  3月 25 15:22 .styleci.yml
-rw-r--r--  1 root root    4051  3月 25 15:22 README.md
drwxr-xr-x  8 root root      98  3月 25 15:38 app
-rwxr-xr-x  1 root root    1686  3月 25 15:22 artisan
drwxr-xr-x  3 root root      34  3月 25 15:22 bootstrap
-rw-r--r--  1 root root    2190  3月 25 15:38 composer.json
-rw-r--r--  1 root root  419071  3月 25 15:38 composer.lock
drwxr-xr-x  2 root root    4096  3月 25 15:38 config
drwxr-xr-x  5 root root      74  3月 25 15:22 database
drwxr-xr-x  3 root root      17  3月 25 15:38 doc
-rw-r--r--  1 root root 1122207  3月 25 15:38 package-lock.json
-rw-r--r--  1 root root     534  3月 25 15:38 package.json
-rw-r--r--  1 root root    1202  3月 25 15:22 phpunit.xml
drwxr-xr-x  2 root root      77  3月 25 15:22 public
drwxr-xr-x  6 root root      52  3月 25 15:22 resources
drwxr-xr-x  2 root root      75  3月 25 15:38 routes
-rw-r--r--  1 root root     563  3月 25 15:22 server.php
drwxr-xr-x  7 root root      78  3月 25 15:22 storage
drwxr-xr-x  4 root root      83  3月 25 15:22 tests
drwxr-xr-x 59 root root    4096  3月 25 16:49 vendor
-rw-r--r--  1 root root     559  3月 25 15:22 webpack.mix.js
[rarsQ@Test-api backend]$ sudo vi .env

本番用に.envを編集

必要に応じて、envファイルを適宜修正。

アプリケーションキーの生成

app(Laravel用コンテナ)に入ってアプリケーションキーを作成します。

[rarsQ@Test-api backend]$ cd ../
[rarsQ@Test-api hoge-api]$ sudo docker-compose exec app bash
root@890fc9739e74:/work/backend# php artisan key:generate
Application key set successfully.
root@890fc9739e74:/work/backend# exit
exit

フォルダ権限設定

※一般的にはstorage/logs,vendorのみで良いはず。
最後のコマンドは動作確認時エラーが出たので追記、775ではpermission errorとなった。

[rarsQ@Test-api hoge-api]$ sudo chmod -R 775 backend/storage/logs
[rarsQ@Test-api hoge-api]$ sudo chmod -R 775 backend/vendor/
[rarsQ@Test-api hoge-api]$ sudo chmod -R 777 backend/storage/framework/

マイグレーションの実行

必要であれば実行。

[rarsQ@Test-api hoge-api]$ docker-compose exec app bash
[rarsQ@Test-api hoge-api]$ php artisan migrate

動作確認

ここまでで一通り完了。
サーバーのIPアドレスにアクセスし、Laravelのwelcomeページが表示されるか確認する。

コンテナ停止

[rarsQ@Test-api hoge-api]$ sudo docker-compose stop
Stopping test-api_1 ... done
Stopping test-web_1 ... done

コンテナ起動

[rarsQ@Test-api hoge-api]$ sudo docker-compose up -d
Starting test-api_1 ... done
Starting test-web_1 ... done

終わりに

dockerが実行できる環境までいければ、あとはローカルと変わらないですね!
サブスクリプション周りやGitのインストール等、RHELで実行している記事があまり見当たらなかったので、残して見ました。
初めての環境作成だったので、こうした方が良い等があればご指摘いただけると幸いです。

以下、参考にさせていただきました!

デプロイ
https://laraweb.net/tutorial/6578/

docker
https://docs.docker.com/engine/install/rhel/#prerequisites。
https://docs.docker.com/engine/install/centos/
https://blog.ikappio.com/install-docker-ce-on-rehl8-derived-almalinux/#toc5
https://sourceexample.com/article/jp/eb1e18b1235e3bcfe1d6ffae9de9bf78/
https://souiunogaii.hatenablog.com/entry/OracleLinux8-docker-install#%E6%89%8B%E9%A0%86Docker%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%82%92%E3%82%BB%E3%83%83%E3%83%88%E3%82%A2%E3%83%83%E3%83%97

docker-compose
https://docs.docker.com/compose/install/

CodeCommit clone
https://www.hacknotes.jp/blog/codecommit-guide/

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2