2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel8+PHP7.4のプロジェクトを構築

Posted at

課題

PHP7.4も終了しましたが、まだまだ、動いている環境があり、そこに追加したいサービスがあるため、環境構築を行った。

ほとんど、今更Laravel8+PHP7.4のプロジェクトを構築するを参考にしていますが、

Nodejsのバージョンでsailがビルドできなくなってしまった!

TL;DR

作成された、docker-compose.ymlファイルで、laravel.testbuildargsNODE_VERSIONを追加する

docker-compose.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/7.4
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
                NODE_VERSION: '${NODE_VERSION}' <- 追加する
        image: sail-7.4/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:

次に、.envNODE_VERSIONを追加して、バージョン指定する。
ここでは18を指定する。

.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:ADyJG3k66NmqQniijqqdr05Fxul+OFHQNQlB0lSdhxg=
APP_DEBUG=true
APP_URL=http://localhost

NODE_VERSION=18 <=これを追加

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

エラーとか経緯とか

ほとんど、今更Laravel8+PHP7.4のプロジェクトを構築するを参考にしてください。

その中で、./vendor/bin/sail buildを実行すると、以下のようなエラーとなります。

./vendor/bin/sail build
211.3 ## To install the Yarn package manager, run:
211.3      curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
211.3      echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
211.3      sudo apt-get update && sudo apt-get install yarn
211.3
211.3
211.4 Reading package lists...
211.9 Building dependency tree...
212.1 Reading state information...
212.2 The following NEW packages will be installed:
212.2   nodejs
212.4 0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
212.4 Need to get 27.2 MB of archives.
212.4 After this operation, 128 MB of additional disk space will be used.
212.4 Get:1 https://deb.nodesource.com/node_16.x focal/main amd64 nodejs amd64 16.20.2-deb-1nodesource1 [27.2 MB]
214.8 debconf: delaying package configuration, since apt-utils is not installed
214.8 Fetched 27.2 MB in 3s (10.7 MB/s)
214.8 Selecting previously unselected package nodejs.
(Reading database ... 21674 files and directories currently installed.)
214.8 Preparing to unpack .../nodejs_16.20.2-deb-1nodesource1_amd64.deb ...
214.8 Unpacking nodejs (16.20.2-deb-1nodesource1) ...
216.5 Setting up nodejs (16.20.2-deb-1nodesource1) ...
216.5 Processing triggers for man-db (2.9.1-1) ...
217.1 npm ERR! code EBADENGINE
217.1 npm ERR! engine Unsupported engine
217.1 npm ERR! engine Not compatible with your version of node/npm: npm@10.2.2
217.1 npm ERR! notsup Not compatible with your version of node/npm: npm@10.2.2
217.1 npm ERR! notsup Required: {"node":"^18.17.0 || >=20.5.0"}
217.1 npm ERR! notsup Actual:   {"npm":"8.19.4","node":"v16.20.2"}
217.1
217.1 npm ERR! A complete log of this run can be found in:
217.1 npm ERR!     /root/.npm/_logs/2023-11-02T12_35_40_074Z-debug-0.log
------
failed to solve: process "/bin/sh -c apt-get update     && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils     && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec083175675
6d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null     && echo \"deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main\" > /etc/apt/sources.list.d/ppa_ondrej_php.l
ist     && apt-get update     && apt-get install -y php7.4-cli php7.4-dev        php7.4-pgsql php7.4-sqlite3 php7.4-gd        php7.4-curl php7.4-memcached        php7.4-imap php7.4-mysql php7.4-mbstring        php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap        php7.4-i
ntl php7.4-readline php7.4-pcov        php7.4-msgpack php7.4-igbinary php7.4-ldap        php7.4-redis php7.4-xdebug     && php -r \"readfile('https://getcomposer.org/installer');\" | php -- --install-dir=/usr/bin/ --filename=composer     && curl -sLS https://deb.nodesource
.com/setup_$NODE_VERSION.x | bash -     && apt-get install -y nodejs     && npm install -g npm     && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null     && echo \"deb [signed-by=/usr/share/keyrings/yarnkey
.gpg] https://dl.yarnpkg.com/debian/ stable main\" > /etc/apt/sources.list.d/yarn.list     && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null     && echo \"deb [signed-by=/usr/share/keyrings/pgdg.gpg
] http://apt.postgresql.org/pub/repos/apt focal-pgdg main\" > /etc/apt/sources.list.d/pgdg.list     && apt-get update     && apt-get install -y yarn     && apt-get install -y mysql-client     && apt-get install -y postgresql-client-$POSTGRES_VERSION     && apt-get -y autoremove     && apt-get clean     && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*" did not complete successfully: exit code: 1

さすがに、nodejs v16はないので、動かない。。。

Imageで指定されているDockerfileを確認すると、node.jsのバージョンは変数で宣言されている!

2023-11-02_21h44_12.png

Dockerfile ARG入門を見ると、argsdocker-compose.ymlで上書きができるようだ!

ということで、先のようにnode.jsのバージョンを指定してビルドができました。

ちなみに、Laravel Mixと関係するとは思いますが、そこまでは検証ができていません。
とりあえず、Mixを使う予定はないので、こちらで良しと致しますm(_ _)m

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?