搭建Laravel8+PHP7.4的项目

问题

尽管PHP7.4已经结束了,但仍然有一些运行环境,因为还有一些需要添加的服务,所以进行了环境搭建。

大部分情况下,我现在正在参考搭建Laravel8+PHP7.4项目。

最近,我的 Node.js 版本无法构建 sail 了!

太长不读

在创建的docker-compose.yml文件中,将NODE_VERSION参数添加到laravel.test的build中。

# 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:

接下来,在.env文件中添加NODE_VERSION,并指定版本。在这里,我们指定版本号为18。

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时,会出现以下错误。

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,好像可以在docker-compose.yml中进行覆盖!

因此,按照前面的要求,我们可以指定node.js的版本并进行构建。

顺便说一下,我认为与Laravel Mix有关,但尚未进行验证。
暂时而言,我没有使用Mix的计划,所以我们将这个事情就这样了解决吧m(_ _)m

广告
将在 10 秒后关闭
bannerAds