Laravel 8 – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Thu, 28 May 2026 12:57:20 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 部署 Shopify PHP 主题应用扩展至生产环境的应用中(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7) https://www.shuijingwanwq.com/2023/07/20/7878/ https://www.shuijingwanwq.com/2023/07/20/7878/#respond Thu, 20 Jul 2023 01:42:15 +0000 https://www.shuijingwanwq.com/?p=7878 浏览量: 157

1、参考:部署 Shopify PHP 应用至生产环境(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7)

2、当在应用:learn-php-app-ubuntu-2004-0605 新建且部署主题应用扩展后。测试通过,符合预期。如图1

当在应用:learn-php-app-ubuntu-2004-0605 新建且部署主题应用扩展后。测试通过,符合预期

图1

3、上传本地环境中的应用:learn-php-app-ubuntu-2004-0605 中 web 下的代码至生产环境,目录:vendor、frontend/node_modules、frontend/dist 不上传。

4、上传代码至生产环境后,重新构建前端与后端。

[root@iZ23wv7v5ggZ frontend]# npm install
[root@iZ23wv7v5ggZ frontend]# SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef npm run build
[root@iZ23wv7v5ggZ frontend]# cd ..
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer build
> composer build-frontend-links
> ln -sf ../frontend/dist/assets public/assets && ln -sf ../frontend/dist/index.html public/index.html

5、在开发商店中测试生产环境的应用,可正常工作。

6、由于主题应用扩展需要基于 Shopify CLI 创建,但是生产环境中没有安装 Shopify CLI。创建与部署主题应用扩展只能够在本地环境中执行。只不过需要绑定的应用为生产环境中的应用(即合作伙伴中心的应用:learn-php-app-0605-prod)。复制learn-php-app-ubuntu-2004-0605 中的代码至目录:learn-php-app-0605-prod,目录:node_modules、web/vendor、web/frontend/node_modules、web/frontend/dist 不复制。最佳实践应该是这2个应用目录共用同一个 Git 仓库,以保持代码的同步。参考:Work on an existing app  。安装项目的依赖。

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$  sudo npm install

7、安装应用的依赖项后,检查版本以确保 Shopify CLI 可用。

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run shopify version

> learn-php-app-ubuntu-2004-0605@1.0.0 shopify
> shopify version

Current Shopify CLI version: 3.46.2
💡 Version 3.46.5 available! Run npm run shopify upgrade

8、运行 dev 命令,在第一次运行此命令时,将其连接到合作伙伴中心的现有应用程序:learn-php-app-0605-prod,选择对应的商店以预览应用,且不更新应用的 URL,以避免影响到生产环境的应用使用。如图2

运行 dev 命令,在第一次运行此命令时,将其连接到合作伙伴中心的现有应用程序:learn-php-app-0605-prod,选择对应的商店以预览应用,且不更新应用的 URL,以避免影响到生产环境的应用使用

图2

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run dev

> learn-php-app-ubuntu-2004-0605@1.0.0 dev
> shopify app dev


Looks like this is the first time you're running dev for this project.
Configure your preferences by answering a few questions.


Before you preview your work, it needs to be associated with an app.

?  Create this project as a new app on Shopify?

>  (y) Yes, create it as a new app
   (n) No, connect it to an existing app

✔  No, connect it to an existing app

?  Which existing app is this for?

>  learn-php-app-0605-prod
   learn-php-app-ubuntu-2004-0605
   app-partners-20230530
   theme-app-ext-example1
   theme-app-extension-example
   learn-node-app-20230524
   learn-php-app-20230510
   learn-node-app-20230509
   learn-app-20221019
   learn-app

✔  learn-php-app-0605-prod

?  Which store would you like to use to view your project?

>  shuijingwanwq-development
   shuijingwanwq-development3
   shuijingwanwq-development2

✔  shuijingwanwq-development

?  Have Shopify automatically update your app's URL in order to create a preview experience?

       Current app URL:        • https://learn-php-app-0605-prod.shuijingwanwq.com/

       Current redirect URLs:  • https://learn-php-app-0605-prod.shuijingwanwq.com/api/auth/callback

   (1) Always by default
   (2) Yes, this time
   (3) No, not now
>  (4) Never, don't ask again

✔  Never, don't ask again

╭─ info ───────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  To make URL updates manually, you can add the following URLs as redirects   │
│  in your Partners Dashboard [1]:                                             │
│                                                                              │
│                                                                              │
│    • https://tiger-foto-incident-sparc.trycloudflare.com/auth/callback       │
│    • https://tiger-foto-incident-sparc.trycloudflare.com/auth/shopify/callb  │
│      ack                                                                     │
│    • https://tiger-foto-incident-sparc.trycloudflare.com/api/auth/callback   │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://partners.shopify.com/2442779/apps/44885082113/edit

theme-app-extension-0612 (Theme App Extension)
Follow the dev doc instructions ( https://shopify.dev/apps/online-store/theme-app-extensions/getting-started#step-3-test-your-changes ) by deploying your work as a draft

2023-06-15 03:17:46 │ frontend   │
2023-06-15 03:17:46 │ frontend   │ > shopify-frontend-template-react@1.0.0 dev
2023-06-15 03:17:46 │ frontend   │ > vite
2023-06-15 03:17:46 │ frontend   │
2023-06-15 03:17:47 │ backend    │ > Composer\Config::disableProcessTimeout
2023-06-15 03:17:47 │ backend    │ > php artisan serve
2023-06-15 03:17:47 │ backend    │ PHP Warning:  require(/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/vendor/autoload.php): Failed to open
                                   stream: No such file or directory in /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan on line 18
2023-06-15 03:17:47 │ backend    │ PHP Fatal error:  Uncaught Error: Failed opening required
                                   '/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/vendor/autoload.php' (include_path='.:/usr/share/php') in
                                   /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan:18
2023-06-15 03:17:47 │ backend    │ Stack trace:
2023-06-15 03:17:47 │ backend    │ #0 {main}
2023-06-15 03:17:47 │ backend    │   thrown in /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan on line 18
2023-06-15 03:17:47 │ backend    │ Script php artisan serve handling the serve event returned with error code 255

Preview URL: https://tiger-foto-incident-sparc.trycloudflare.com?shop=shuijingwanwq-development.myshopify.com&host=c2h1a
Wppbmd3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu

── external error ──────────────────────────────────────────────────────────────

Error coming from `composer serve`

Command failed with exit code 255: composer serve
> Composer\Config::disableProcessTimeout
> php artisan serve
PHP Warning:  require(/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/vendor/autoload.php): Failed to open
stream: No such file or directory in /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan on line 18
PHP Fatal error:  Uncaught Error: Failed opening required
'/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/vendor/autoload.php' (include_path='.:/usr/share/php') in
/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan:18
Stack trace:
#0 {main}
  thrown in /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web/artisan on line 18
Script php artisan serve handling the serve event returned with error code 255

────────────────────────────────────────────────────────────────────────────────

9、执行命令:composer serve 时报错,因为 PHP 的依赖项还未安装。不过,主题应用扩展:theme-app-extension-0612 已经推送至合作伙伴中心。如图3

执行命令:composer serve 时报错,因为 PHP 的依赖项还未安装。不过,主题应用扩展:theme-app-extension-0612 已经推送至合作伙伴中心

图3

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web$ composer install

10、启用开发商店预览后,执行 deploy 命令后,可以创建扩展版本,然后安装过此应用的店铺便可以使用此主题应用扩展。无法创建扩展版本,不符合预期。如图4

启用开发商店预览后,执行 deploy 命令后,可以创建扩展版本,然后安装过此应用的店铺便可以使用此主题应用扩展。无法创建扩展版本,不符合预期

图4

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run deploy

> learn-php-app-ubuntu-2004-0605@1.0.0 deploy
> shopify app deploy

?  Make the following changes to your extensions in Shopify Partners?
✔  Yes, deploy to push changes


Deploying your work to Shopify Partners. It will be part of learn-php-app-ubuntu-2004-0605

 theme_extensions │ Running theme check on your Theme app extension...
 theme_extensions │ Checking /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/extensions/theme-app-extension-0612 ...
 theme_extensions │ 4 files inspected, 0 offenses detected, 0 offenses auto-correctable


╭─ success ────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Deployed to Shopify!                                                        │
│                                                                              │
│  Summary                                                                     │
│    • theme-app-extension-0612 is deployed to Shopify but not yet live        │
│                                                                              │
│  Next steps                                                                  │
│    • Publish theme-app-extension-0612 [1]                                    │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://partners.shopify.com/2442779/apps/44874072065/extensions/theme_app_extension/25583255553

11、发现仍然是被推送部署至复制前的应用 learn-php-app-ubuntu-2004-0605 。如图5

发现仍然是被推送部署至复制前的应用 learn-php-app-ubuntu-2004-0605

图5

12、重新运行开发(重新配置)命令。在执行过程中,存在:Pushed » ‘theme-app-extension-0612’ to a draft。已经可以创建应用扩展的版本。如图6

重新运行开发(重新配置)命令。在执行过程中,存在:Pushed » 'theme-app-extension-0612' to a draft。已经可以创建应用扩展的版本

图6

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run dev -- --reset

> learn-php-app-ubuntu-2004-0605@1.0.0 dev
> shopify app dev --reset


Before you preview your work, it needs to be associated with an app.

?  Create this project as a new app on Shopify?
✔  No, connect it to an existing app

?  Which existing app is this for?
✔  learn-php-app-0605-prod

?  Which store would you like to use to view your project?
✔  shuijingwanwq-development

?  Have Shopify automatically update your app's URL in order to create a preview experience?
✔  Never, don't ask again

╭─ info ───────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  To make URL updates manually, you can add the following URLs as redirects   │
│  in your Partners Dashboard [1]:                                             │
│                                                                              │
│                                                                              │
│    • https://shape-vaccine-crop-xl.trycloudflare.com/auth/callback           │
│    • https://shape-vaccine-crop-xl.trycloudflare.com/auth/shopify/callback   │
│    • https://shape-vaccine-crop-xl.trycloudflare.com/api/auth/callback       │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://partners.shopify.com/2442779/apps/44885082113/edit

theme-app-extension-0612 (Theme App Extension)
Follow the dev doc instructions ( https://shopify.dev/apps/online-store/theme-app-extensions/getting-started#step-3-test-your-changes ) by deploying your work as a draft

2023-06-15 05:54:27 │ frontend   │
2023-06-15 05:54:27 │ frontend   │ > shopify-frontend-template-react@1.0.0 dev
2023-06-15 05:54:27 │ frontend   │ > vite
2023-06-15 05:54:27 │ frontend   │
2023-06-15 05:54:29 │ webhooks   │ Sending APP_UNINSTALLED webhook to app server
2023-06-15 05:54:29 │ webhooks   │ App isn't responding yet, retrying in 5 seconds
2023-06-15 05:54:34 │ webhooks   │ App isn't responding yet, retrying in 5 seconds
2023-06-15 05:54:35 │ frontend   │
2023-06-15 05:54:35 │ frontend   │   VITE v4.3.9  ready in 7797 ms
2023-06-15 05:54:35 │ frontend   │
2023-06-15 05:54:35 │ frontend   │   ➜  Local:   http://localhost:33151/
2023-06-15 05:54:36 │ backend    │ > Composer\Config::disableProcessTimeout
2023-06-15 05:54:36 │ backend    │ > php artisan serve
2023-06-15 05:54:39 │ webhooks   │ App isn't responding yet, retrying in 5 seconds
2023-06-15 05:54:44 │ webhooks   │ App hasn't started in time, giving up
2023-06-15 05:54:44 │ webhooks   │ APP_UNINSTALLED webhook delivery failed
2023-06-15 05:54:54 │ backend    │ Starting Laravel development server: http://127.0.0.1:41775
2023-06-15 05:54:54 │ backend    │ [Thu Jun 15 13:54:54 2023] PHP 8.1.18 Development Server (http://127.0.0.1:41775) started
2023-06-15 05:55:21 │ extensions │
2023-06-15 05:55:21 │ extensions │ --------- Pushing theme files to App Ext. Host (96e4f9-DESKTOP-QLPK8QM) (#133838078137) on
                                   shuijingwanwq-development.myshopify.com
2023-06-15 05:55:21 │ extensions │ Pushing theme...     0%
2023-06-15 05:55:33 │ backend    │ [Thu Jun 15 13:55:33 2023] 127.0.0.1:42178 Accepted
2023-06-15 05:55:42 │ backend    │ [Thu Jun 15 13:55:42 2023] 127.0.0.1:42178 Closing
2023-06-15 05:55:42 │ backend    │ [Thu Jun 15 13:55:42 2023] 127.0.0.1:42184 Accepted
2023-06-15 05:55:45 │ backend    │ [Thu Jun 15 13:55:44 2023] 127.0.0.1:42184 Closing
2023-06-15 05:56:25 │ extensions │ Pushing theme...    36%
2023-06-15 05:56:27 │ extensions │ Pushing theme...    52%
2023-06-15 05:56:27 │ extensions │ Pushing theme...    68%
2023-06-15 05:56:27 │ extensions │ Pushing theme...    84%
2023-06-15 05:56:27 │ extensions │ Pushing theme...   100%
2023-06-15 05:56:29 │ extensions │ ------------------
2023-06-15 05:56:31 │ extensions │
2023-06-15 05:56:31 │ extensions │ --------- Viewing extension…
2023-06-15 05:56:31 │ extensions │ Enable your theme app extension:
2023-06-15 05:56:31 │ extensions │ https://partners.shopify.com/2442779/apps/44885082113/extensions/theme_app_extension/25719668737
2023-06-15 05:56:31 │ extensions │
2023-06-15 05:56:31 │ extensions │ Setup your theme app extension in the host theme:
2023-06-15 05:56:31 │ extensions │ https://shuijingwanwq-development.myshopify.com/admin/themes/133838078137/editor
2023-06-15 05:56:31 │ extensions │
2023-06-15 05:56:31 │ extensions │ Preview your theme app extension:
2023-06-15 05:56:31 │ extensions │ http://127.0.0.1:9292
2023-06-15 05:56:31 │ extensions │ ------------------
2023-06-15 05:56:34 │ extensions │ Pushed » 'theme-app-extension-0612' to a draft
2023-06-15 05:56:34 │ extensions │ - blocks/star_rating.liquid
2023-06-15 05:56:34 │ extensions │ - snippets/stars.liquid
2023-06-15 05:56:34 │ extensions │ - locales/en.default.json
2023-06-15 05:56:34 │ extensions │ - assets/thumbs-up.png
2023-06-15 06:39:08 │ extensions │ Stopping…

› Press p │ preview in your browser
› Press q │ quit

Preview URL: https://shape-vaccine-crop-xl.trycloudflare.com?shop=shuijingwanwq-development.myshopify.com&host=c2h1aWppb
md3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu

13、应用:learn-php-app-0605-prod 已经被分发至店铺:shuijingwanwq-development3。如图7

应用:learn-php-app-0605-prod 已经被分发至店铺:shuijingwanwq-development3

图7

14、创建主题应用扩展的版本并发布:1.0.0。如图8

创建主题应用扩展的版本并发布:1.0.0

图8

15、打开店铺:shuijingwanwq-development3 的任一主题的编辑器,可通过添加应用块的方式,使用主题应用扩展。如图9

打开店铺:shuijingwanwq-development3 的任一主题的编辑器,可通过添加应用块的方式,使用主题应用扩展

图9

16、查看首页,主题应用扩展已经显示。如图10

查看首页,主题应用扩展已经显示

图10

17、更新主题扩展应用的代码后,执行部署命令。发现仍然是部署至复制前的应用:learn-php-app-ubuntu-2004-0605

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run deploy

> learn-php-app-ubuntu-2004-0605@1.0.0 deploy
> shopify app deploy

?  Make the following changes to your extensions in Shopify Partners?
✔  Yes, deploy to push changes


Deploying your work to Shopify Partners. It will be part of learn-php-app-ubuntu-2004-0605

 theme_extensions │ Running theme check on your Theme app extension...
 theme_extensions │ Checking /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/extensions/theme-app-extension-0612 ...
 theme_extensions │ 4 files inspected, 0 offenses detected, 0 offenses auto-correctable


╭─ success ────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Deployed to Shopify!                                                        │
│                                                                              │
│  Summary                                                                     │
│    • theme-app-extension-0612 is deployed to Shopify but not yet live        │
│                                                                              │
│  Next steps                                                                  │
│    • Publish theme-app-extension-0612 [1]                                    │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://partners.shopify.com/2442779/apps/44874072065/extensions/theme_app_extension/25583255553

18、重新执行 env pull 命令,以指定应用为:learn-php-app-0605-prod。以更新现有的应用与应用扩展的环境变量。如图11

重新执行 env pull 命令,以指定应用为:learn-php-app-0605-prod。以更新现有的应用与应用扩展的环境变量

图11

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run shopify app env pull

> learn-php-app-ubuntu-2004-0605@1.0.0 shopify
> shopify app env pull

?  Which existing app is this for?
✔  learn-php-app-0605-prod

Updated .env to be:

SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
SHOPIFY_THEME_APP_EXTENSION_0612_ID=a680449a-9537-45bf-a010-4d8cadacf5e1

SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
SCOPES=write_products

Here's what changed:

- SHOPIFY_API_KEY=02c894a155c74ca837babfcf043ae4ed
+ SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
SHOPIFY_THEME_APP_EXTENSION_0612_ID=a680449a-9537-45bf-a010-4d8cadacf5e1
+ SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
+ SCOPES=write_products

19、再次执行部署命令,然后创建新的扩展版本:1.2.0 并且发布。等待了大约 3 分钟左右,首页发生变化,已经应用到新的更改,从 0615 变化为 0616。如图12

再次执行部署命令,然后创建新的扩展版本:1.2.0 并且发布。等待了大约 3 分钟左右,首页发生变化,已经应用到新的更改,从 0615 变化为 0616

图12

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ npm run deploy

> learn-php-app-ubuntu-2004-0605@1.0.0 deploy
> shopify app deploy

?  Make the following changes to your extensions in Shopify Partners?
✔  Yes, deploy to push changes


Deploying your work to Shopify Partners. It will be part of learn-php-app-0605-prod

 theme_extensions │ Running theme check on your Theme app extension...
 theme_extensions │ Checking /mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/extensions/theme-app-extension-0612 ...
 theme_extensions │ 4 files inspected, 0 offenses detected, 0 offenses auto-correctable


╭─ success ────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Deployed to Shopify!                                                        │
│                                                                              │
│  Summary                                                                     │
│    • theme-app-extension-0612 is deployed to Shopify but not yet live        │
│                                                                              │
│  Next steps                                                                  │
│    • Publish theme-app-extension-0612 [1]                                    │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://partners.shopify.com/2442779/apps/44885082113/extensions/theme_app_extension/25719668737

]]>
https://www.shuijingwanwq.com/2023/07/20/7878/feed/ 0
部署 Shopify PHP 应用至生产环境(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7) https://www.shuijingwanwq.com/2023/07/13/7855/ https://www.shuijingwanwq.com/2023/07/13/7855/#comments Thu, 13 Jul 2023 03:06:29 +0000 https://www.shuijingwanwq.com/?p=7855 浏览量: 326

1、现有一个 Shopify PHP 应用,已经可在开发环境中预览。如图1

现有一个 Shopify PHP 应用,已经可在开发环境中预览

图1

2、现准备将其部署至生产环境。如果需要部署应用至生产环境,Shopify 建议创建一个单独的应用。此应用与开发、测试环境共用代码库,但是在 Shopify 合作伙伴中心有自己的记录和配置。以避免在开发和测试过程中影响到生产环境的应用。使用 Shopify 合作伙伴
从头开始创建应用:learn-php-app-0605-prod。如图2

使用 Shopify 合作伙伴从头开始创建应用:learn-php-app-0605-prod

图2

3、检索环境变量,以便可以在稍后的步骤中设置它们。记下 SCOPES、SHOPIFY_API_KEY 和 SHOPIFY_API_SECRET 值。 您需要将这些值设置为托管应用程序的环境变量。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ npm run shopify app env show

> learn-php-app-ubuntu-2004-0605@1.0.0 shopify
> shopify app env show

?  Which existing app is this for?
✔  learn-php-app-0605-prod


    SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
    SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
    SCOPES=write_products



4、参考:基于阿里云的 ECS、RDS,将个人博客迁移升级至:Docker(基于预算考虑,最终未实现)、LNMP(CentOS 7.7、Nginx 1.16、MySQL 5.7、PHP 7.4)、HTTPS 的过程  ,之前的环境是基于 OneinStack 的自动安装。PHP 版本 7.4 已经不再符合 Shopify 应用的运行条件。需要升级至 8.1 版本,尽量与本地环境保持一致。


[root@iZ23wv7v5ggZ ~]# php -v
PHP 7.4.0 (cli) (built: Dec  5 2019 11:56:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies




wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ php -v
PHP 8.1.18 (cli) (built: Apr 14 2023 04:39:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies


5、参考:在 阿里云中的 CentOS 7.7 中卸载 PHP 7.4,然后安装 PHP 8

6、查看阿里云中的 ECS 的 Alibaba Cloud Linux 3 的 PHP 版本


[root@iZ23wv7v5ggZ ~]# php -v
PHP 8.1.19 (cli) (built: Jun  7 2023 11:34:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.19, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.19, Copyright (c), by Zend Technologies
[root@iZ23wv7v5ggZ ~]#



7、添加虚拟主机时,设置 SSL 证书失败:Let’s Encrypt Verify error! DNS problem,需要先设置域名的解析。


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Use HTTP Only
        2. Use your own SSL Certificate and Key
        3. Use Let's Encrypt to Create SSL Certificate and Key
        q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): learn-php-app-0605-prod.shuijingwanwq.com
domain=learn-php-app-0605-prod.shuijingwanwq.com

Please input the directory for the domain:learn-php-app-0605-prod.shuijingwanwq.com :
(Default directory: /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com):
Virtual Host Directory=/data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please select domain cert key length.
Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.
Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.

Please enter your cert key length (default 2048):

Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:44:59 PM CST 2023] Using CA: https://acme.zerossl.com/v2/DV90
[Wed Jun  7 04:44:59 PM CST 2023] Creating domain key
[Wed Jun  7 04:44:59 PM CST 2023] The domain key is here: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.key
[Wed Jun  7 04:44:59 PM CST 2023] Single domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:44:59 PM CST 2023] Getting domain auth token for each domain
[Wed Jun  7 04:45:05 PM CST 2023] Getting webroot for domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:45:05 PM CST 2023] Verifying: learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:45:07 PM CST 2023] Processing, The CA is processing your order, please just wait. (1/30)
[Wed Jun  7 04:45:11 PM CST 2023] learn-php-app-0605-prod.shuijingwanwq.com:Verify error:"error":{
[Wed Jun  7 04:45:11 PM CST 2023] Please add '--debug' or '--log' to check more details.
[Wed Jun  7 04:45:11 PM CST 2023] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
Error: Create Let's Encrypt SSL Certificate failed!
[root@iZ23wv7v5ggZ www.shuijingwanwq.com]#



8、在阿里云 云解析DNS 中添加记录。如图3

在阿里云 云解析DNS 中添加记录

图3

9、再次添加虚拟主机


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Use HTTP Only
        2. Use your own SSL Certificate and Key
        3. Use Let's Encrypt to Create SSL Certificate and Key
        q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): learn-php-app-0605-prod.shuijingwanwq.com
domain=learn-php-app-0605-prod.shuijingwanwq.com

Please input the directory for the domain:learn-php-app-0605-prod.shuijingwanwq.com :
(Default directory: /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com):
Virtual Host Directory=/data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please select domain cert key length.
Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.
Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.

Please enter your cert key length (default 2048):
[Wed Jun  7 04:51:49 PM CST 2023] Using CA: https://acme.zerossl.com/v2/DV90
[Wed Jun  7 04:51:49 PM CST 2023] Single domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:51:49 PM CST 2023] Getting domain auth token for each domain
[Wed Jun  7 04:51:54 PM CST 2023] Getting webroot for domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:51:54 PM CST 2023] Verifying: learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:51:55 PM CST 2023] Processing, The CA is processing your order, please just wait. (1/30)
[Wed Jun  7 04:52:01 PM CST 2023] Success
[Wed Jun  7 04:52:01 PM CST 2023] Verify finished, start to sign.
[Wed Jun  7 04:52:01 PM CST 2023] Lets finalize the order.
[Wed Jun  7 04:52:01 PM CST 2023] Le_OrderFinalize='https://acme.zerossl.com/v2/DV90/order/CLf6pxWJkdxtQylgNxS_Jg/finalize'
[Wed Jun  7 04:52:02 PM CST 2023] Order status is processing, lets sleep and retry.
[Wed Jun  7 04:52:02 PM CST 2023] Retry after: 15
[Wed Jun  7 04:52:18 PM CST 2023] Polling order status: https://acme.zerossl.com/v2/DV90/order/CLf6pxWJkdxtQylgNxS_Jg
[Wed Jun  7 04:52:20 PM CST 2023] Downloading cert.
[Wed Jun  7 04:52:20 PM CST 2023] Le_LinkCert='https://acme.zerossl.com/v2/DV90/cert/B2uRnJRfyVAP2B9aqQ2_Lw'
[Wed Jun  7 04:52:22 PM CST 2023] Cert success.
-----BEGIN CERTIFICATE-----
*******************
-----END CERTIFICATE-----
[Wed Jun  7 04:52:22 PM CST 2023] Your cert is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.cer
[Wed Jun  7 04:52:22 PM CST 2023] Your cert key is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.key
[Wed Jun  7 04:52:22 PM CST 2023] The intermediate CA cert is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/ca.cer
[Wed Jun  7 04:52:22 PM CST 2023] And the full chain certs is there: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/fullchain.cer

Do you want to add hotlink protection? [y/n]: y

Allow Rewrite rule? [y/n]: y

Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,codeigniter,laravel
thinkphp,pathinfo,discuz,typecho,ecshop,nextcloud,zblog,whmcs rewrite was exist.
(Default rewrite: other): laravel
You choose rewrite=laravel

Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
You access log file=/data/wwwlogs/learn-php-app-0605-prod.shuijingwanwq.com_nginx.log

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################
Your domain:                  learn-php-app-0605-prod.shuijingwanwq.com
Virtualhost conf:             /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf
Directory of:                 /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com
Rewrite rule:                 /usr/local/nginx/conf/rewrite/laravel.conf
Let's Encrypt SSL Certificate:/usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.crt
SSL Private Key:              /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.key
[root@iZ23wv7v5ggZ www.shuijingwanwq.com]#



10、添加FTP账号


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/pureftpd_vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#                 FTP virtual user account management                 #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. UserAdd
        2. UserMod
        3. UserPasswd
        4. UserDel
        5. ListAllUser
        6. ShowUser
        q. Exit
Please input the correct option: 1

Please input a username: learn-php-app-0605-prod.shuijingwanwq.com

Please input the password: XZzqpC4k3Clf6Oup26e

Please input the directory(Default directory: /data/wwwroot): /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com
Password:
Enter it again:
#####################################

[learn-php-app-0605-prod.shuijingwanwq.com] create successful!

You user name is : learn-php-app-0605-prod.shuijingwanwq.com
You Password is : ************
You directory is : /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com



11、此时,需要在本地环境中构建生产环境中的应用,避免在生产环境中构建,因为生产环境中暂不支持构建所需要的前提条件,比如说 npm、composer 等。SHOPIFY_API_KEY 需要使用 步骤 3 中检索出的变量值。复制应用目录 learn-php-app-ubuntu-2004-0605/web 为 learn-php-app-0605-prod。目录 learn-php-app-0605-prod 仅需要构建后,上传至生产环境,因此,开发环境的依赖文件皆不需要。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$ cd learn-php-app-0605-prod/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ ls -l
total 300
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 app
-rwxrwxrwx 1 wangqiang wangqiang   1690 Jun  5 15:02 artisan
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 bootstrap
-rwxrwxrwx 1 wangqiang wangqiang   2238 Jun  5 15:02 composer.json
-rwxrwxrwx 1 wangqiang wangqiang 304694 Jun  6 09:35 composer.lock
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 config
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 database
-rwxrwxrwx 1 wangqiang wangqiang    450 Jun  5 15:02 entrypoint.sh
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 frontend
-rwxrwxrwx 1 wangqiang wangqiang    860 Jun  5 15:00 nginx.conf
-rwxrwxrwx 1 wangqiang wangqiang   1202 Jun  5 15:00 phpunit.xml
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 public
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 resources
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 routes
-rwxrwxrwx 1 wangqiang wangqiang    563 Jun  5 15:00 server.php
-rwxrwxrwx 1 wangqiang wangqiang     75 Jun  5 15:00 shopify.web.toml
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 storage
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:42 vendor



12、编辑 .env ,设置为生产环境中的配置值


APP_NAME="Shopify PHP App 0605 Prod"
APP_ENV=production
APP_KEY=***********
APP_DEBUG=false

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=************
DB_PORT=3306
DB_DATABASE=learn_php_app_0605_prod
DB_USERNAME=learn_php_app_0605_prod
DB_PASSWORD=**********



13、构建前端与后端,报错:/bin/sh: 1: vite: not found,需要先执行:npm install 。如图4

构建前端与后端,报错:/bin/sh: 1: vite: not found,需要先执行:npm install

图4


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef yarn build
yarn run v1.22.15
$ vite build
/bin/sh: 1: vite: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ npm install
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.

added 354 packages, and audited 360 packages in 3m

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef npm run build

> shopify-frontend-template-react@1.0.0 build
> vite build

vite v4.3.9 building for production...
✓ 1966 modules transformed.
dist/assets/empty-state-8039a1e1.svg      0.26 kB │ gzip:   0.20 kB
dist/index.html                           0.48 kB │ gzip:   0.33 kB
dist/assets/home-trophy-d70b3542.png     20.65 kB
dist/assets/index-37530742.css          371.48 kB │ gzip:  45.42 kB
dist/assets/ko-ef9a93f5.js                0.21 kB │ gzip:   0.15 kB
dist/assets/ja-abb1af27.js                0.21 kB │ gzip:   0.15 kB
dist/assets/zh-4775ba45.js                0.21 kB │ gzip:   0.15 kB
dist/assets/th-32f01d1c.js                0.21 kB │ gzip:   0.15 kB
dist/assets/vi-72f55a87.js                0.23 kB │ gzip:   0.17 kB
dist/assets/nb-79727cd5.js                0.24 kB │ gzip:   0.17 kB
dist/assets/tr-d5c962f0.js                0.24 kB │ gzip:   0.17 kB
dist/assets/nl-ed6c02b1.js                0.28 kB │ gzip:   0.20 kB
dist/assets/de-5d4a5256.js                0.28 kB │ gzip:   0.20 kB
dist/assets/fi-e67a7779.js                0.28 kB │ gzip:   0.20 kB
dist/assets/da-9b835bb8.js                0.31 kB │ gzip:   0.22 kB
dist/assets/cs-d855408e.js                0.32 kB │ gzip:   0.23 kB
dist/assets/sv-8ac62b51.js                0.37 kB │ gzip:   0.25 kB
dist/assets/en-d265ad8d.js                0.41 kB │ gzip:   0.26 kB
dist/assets/es-fd2f35f4.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-227fd344.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-PT-a0c51464.js             0.41 kB │ gzip:   0.29 kB
dist/assets/pl-ab15c7ea.js                0.42 kB │ gzip:   0.29 kB
dist/assets/fr-23e50d95.js                0.43 kB │ gzip:   0.29 kB
dist/assets/it-08f76780.js                0.45 kB │ gzip:   0.30 kB
dist/assets/en-df34a502.js                1.53 kB │ gzip:   0.77 kB
dist/assets/de-2ae5c9fa.js                1.72 kB │ gzip:   0.90 kB
dist/assets/fr-5253333d.js                1.83 kB │ gzip:   0.94 kB
dist/assets/polyfill-force-11887b4b.js    5.21 kB │ gzip:   2.03 kB
dist/assets/zh-CN-cf74d136.js             7.72 kB │ gzip:   3.26 kB
dist/assets/zh-TW-6a74a185.js             7.86 kB │ gzip:   3.36 kB
dist/assets/ko-2cf626e6.js                8.18 kB │ gzip:   3.39 kB
dist/assets/ja-6f78282b.js                8.35 kB │ gzip:   3.58 kB
dist/assets/en-c240dff3.js                9.95 kB │ gzip:   2.95 kB
dist/assets/vi-e4ef4fd6.js                9.97 kB │ gzip:   3.34 kB
dist/assets/th-2a34d5e0.js               10.14 kB │ gzip:   3.77 kB
dist/assets/sv-a901b08f.js               10.22 kB │ gzip:   3.27 kB
dist/assets/da-1564850b.js               10.30 kB │ gzip:   3.26 kB
dist/assets/nb-0a6d8490.js               10.35 kB │ gzip:   3.25 kB
dist/assets/pl-a603e9c2.js               10.39 kB │ gzip:   3.39 kB
dist/assets/cs-3c753a97.js               10.40 kB │ gzip:   3.50 kB
dist/assets/fi-c0a9d95f.js               10.63 kB │ gzip:   3.41 kB
dist/assets/tr-bd45be97.js               10.68 kB │ gzip:   3.39 kB
dist/assets/it-8bb02787.js               10.72 kB │ gzip:   3.32 kB
dist/assets/pt-PT-af188c06.js            10.85 kB │ gzip:   3.34 kB
dist/assets/nl-0772ea77.js               10.89 kB │ gzip:   3.25 kB
dist/assets/pt-BR-8a1d5660.js            10.94 kB │ gzip:   3.36 kB
dist/assets/es-5e0e20e7.js               10.95 kB │ gzip:   3.39 kB
dist/assets/de-a04fe3bd.js               11.11 kB │ gzip:   3.35 kB
dist/assets/fr-1848494a.js               11.31 kB │ gzip:   3.48 kB
dist/assets/index-41437cc7.js            53.59 kB │ gzip:  18.93 kB
dist/assets/polyfill-904c231f.js        133.64 kB │ gzip:  40.74 kB
dist/assets/index-991532e3.js           618.82 kB │ gzip: 164.28 kB

(!) Some chunks are larger than 500 kBs after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 47.73s
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ composer build
> composer build-frontend-links
> ln -sf ../frontend/dist/assets public/assets && ln -sf ../frontend/dist/index.html public/index.html
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ cd public/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/public$ ls -l
total 0
lrwxrwxrwx 1 wangqiang wangqiang   23 Jun  6 10:06 assets -> ../frontend/dist/assets
-rwxrwxrwx 1 wangqiang wangqiang    0 Jun  5 15:00 favicon.ico
lrwxrwxrwx 1 wangqiang wangqiang   27 Jun  8 09:45 index.html -> ../frontend/dist/index.html
-rwxrwxrwx 1 wangqiang wangqiang 1743 Jun  5 15:00 index.php
-rwxrwxrwx 1 wangqiang wangqiang   24 Jun  5 15:00 robots.txt


14、基于 FTP 上传 目录 learn-php-app-0605-prod 下的所有文件。总计大小为 150 MB 左右。上传时间过长,最张决定在生产环境中构建。目录:vendor、frontend/node_modules 不上传。如图5

基于 FTP 上传 目录 learn-php-app-0605-prod 下的所有文件。总计大小为 150 MB 左右。上传时间过长,最张决定在生产环境中构建。目录:vendor、frontend/node_modules 不上传

图5

15、安装 Node.js 与 Composer,Node.js 安装后需要重启实例


[root@iZ23wv7v5ggZ ~]# ~/oneinstack/install.sh --node

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

Download Nodejs...
--2023-06-08 10:45:47--  https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v18.14.2/node-v18.14.2-linux-x64.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44201520 (42M) [application/octet-stream]
Saving to: ‘node-v18.14.2-linux-x64.tar.gz’

     0K .......... .......... .......... .......... ..........  0%  878K 49s
    50K .......... .......... .......... .......... ..........  0% 1.79M 36s
 43150K .......... .....                                      100% 14.2M=2.7s

2023-06-08 10:45:50 (15.7 MB/s) - ‘node-v18.14.2-linux-x64.tar.gz’ saved [44201520/44201520]

Nodejs installed successfully!
[xprober.php] found
####################Congratulations########################
Total OneinStack Install Time: 0 minutes

[root@iZ23wv7v5ggZ ~]# node -v
-bash: node: command not found

[root@iZ23wv7v5ggZ ~]# ~/oneinstack/addons.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#                    Install/Uninstall Extensions                     #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Install/Uninstall PHP Composer
        2. Install/Uninstall fail2ban
        3. Install/Uninstall ngx_lua_waf
        4. Install/Uninstall Python3.6
        q. Exit
Please input the correct option: 1

Please select an action:
        1. install
        2. uninstall
Please input a number:(Default 1 press Enter) 1

PHP Composer installed successfully!

What Are You Doing?
        1. Install/Uninstall PHP Composer
        2. Install/Uninstall fail2ban
        3. Install/Uninstall ngx_lua_waf
        4. Install/Uninstall Python3.6
        q. Exit
Please input the correct option: q
[root@iZ23wv7v5ggZ ~]# composer -V
Composer version 2.5.7 2023-05-24 15:00:39
[root@iZ23wv7v5ggZ ~]# node -v
v18.14.2



16、当FTP上传完毕后,创建数据库(连接信息与 .env 中的保持一致),生成APP_KEY ,执行数据库迁移,构建前端与后端



[root@iZ23wv7v5ggZ frontend]# npm install
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.

added 359 packages, and audited 360 packages in 17s

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 9.5.0 -> 9.7.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.7.1
npm notice Run npm install -g npm@9.7.1 to update!
npm notice
[root@iZ23wv7v5ggZ frontend]# SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef npm run build

> shopify-frontend-template-react@1.0.0 build
> vite build

vite v4.3.9 building for production...
✓ 1966 modules transformed.
dist/assets/empty-state-8039a1e1.svg      0.26 kB │ gzip:   0.20 kB
dist/index.html                           0.48 kB │ gzip:   0.33 kB
dist/assets/home-trophy-d70b3542.png     20.65 kB
dist/assets/index-37530742.css          371.48 kB │ gzip:  45.42 kB
dist/assets/ja-abb1af27.js                0.21 kB │ gzip:   0.15 kB
dist/assets/ko-ef9a93f5.js                0.21 kB │ gzip:   0.15 kB
dist/assets/th-32f01d1c.js                0.21 kB │ gzip:   0.15 kB
dist/assets/zh-4775ba45.js                0.21 kB │ gzip:   0.15 kB
dist/assets/vi-72f55a87.js                0.23 kB │ gzip:   0.17 kB
dist/assets/nb-79727cd5.js                0.24 kB │ gzip:   0.17 kB
dist/assets/tr-d5c962f0.js                0.24 kB │ gzip:   0.17 kB
dist/assets/de-5d4a5256.js                0.28 kB │ gzip:   0.20 kB
dist/assets/fi-e67a7779.js                0.28 kB │ gzip:   0.20 kB
dist/assets/nl-ed6c02b1.js                0.28 kB │ gzip:   0.20 kB
dist/assets/da-9b835bb8.js                0.31 kB │ gzip:   0.22 kB
dist/assets/cs-d855408e.js                0.32 kB │ gzip:   0.23 kB
dist/assets/sv-8ac62b51.js                0.37 kB │ gzip:   0.25 kB
dist/assets/en-d265ad8d.js                0.41 kB │ gzip:   0.26 kB
dist/assets/es-fd2f35f4.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-227fd344.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-PT-a0c51464.js             0.41 kB │ gzip:   0.29 kB
dist/assets/pl-ab15c7ea.js                0.42 kB │ gzip:   0.29 kB
dist/assets/fr-23e50d95.js                0.43 kB │ gzip:   0.29 kB
dist/assets/it-08f76780.js                0.45 kB │ gzip:   0.30 kB
dist/assets/en-df34a502.js                1.53 kB │ gzip:   0.77 kB
dist/assets/de-2ae5c9fa.js                1.72 kB │ gzip:   0.90 kB
dist/assets/fr-5253333d.js                1.83 kB │ gzip:   0.94 kB
dist/assets/polyfill-force-11887b4b.js    5.21 kB │ gzip:   2.03 kB
dist/assets/zh-CN-cf74d136.js             7.72 kB │ gzip:   3.26 kB
dist/assets/zh-TW-6a74a185.js             7.86 kB │ gzip:   3.36 kB
dist/assets/ko-2cf626e6.js                8.18 kB │ gzip:   3.39 kB
dist/assets/ja-6f78282b.js                8.35 kB │ gzip:   3.58 kB
dist/assets/en-c240dff3.js                9.95 kB │ gzip:   2.95 kB
dist/assets/vi-e4ef4fd6.js                9.97 kB │ gzip:   3.34 kB
dist/assets/th-2a34d5e0.js               10.14 kB │ gzip:   3.77 kB
dist/assets/sv-a901b08f.js               10.22 kB │ gzip:   3.27 kB
dist/assets/da-1564850b.js               10.30 kB │ gzip:   3.26 kB
dist/assets/nb-0a6d8490.js               10.35 kB │ gzip:   3.25 kB
dist/assets/pl-a603e9c2.js               10.39 kB │ gzip:   3.39 kB
dist/assets/cs-3c753a97.js               10.40 kB │ gzip:   3.50 kB
dist/assets/fi-c0a9d95f.js               10.63 kB │ gzip:   3.41 kB
dist/assets/tr-bd45be97.js               10.68 kB │ gzip:   3.39 kB
dist/assets/it-8bb02787.js               10.72 kB │ gzip:   3.32 kB
dist/assets/pt-PT-af188c06.js            10.85 kB │ gzip:   3.34 kB
dist/assets/nl-0772ea77.js               10.89 kB │ gzip:   3.25 kB
dist/assets/pt-BR-8a1d5660.js            10.94 kB │ gzip:   3.36 kB
dist/assets/es-5e0e20e7.js               10.95 kB │ gzip:   3.39 kB
dist/assets/de-a04fe3bd.js               11.11 kB │ gzip:   3.35 kB
dist/assets/fr-1848494a.js               11.31 kB │ gzip:   3.48 kB
dist/assets/index-41437cc7.js            53.59 kB │ gzip:  18.93 kB
dist/assets/polyfill-904c231f.js        133.64 kB │ gzip:  40.74 kB
dist/assets/index-991532e3.js           618.82 kB │ gzip: 164.28 kB

(!) Some chunks are larger than 500 kBs after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 21.56s
[root@iZ23wv7v5ggZ frontend]# cd ..
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - league/flysystem is locked to version 1.1.10 and an update of this package was not requested.
    - league/flysystem 1.1.10 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
  Problem 2
    - league/mime-type-detection is locked to version 1.11.0 and an update of this package was not requested.
    - league/mime-type-detection 1.11.0 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
  Problem 3
    - league/flysystem 1.1.10 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
    - laravel/framework v8.83.27 requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.10].
    - laravel/framework is locked to version v8.83.27 and an update of this package was not requested.

To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/php/etc/php.ini
    - /usr/local/php/etc/php.d/02-opcache.ini
    - /usr/local/php/etc/php.d/03-imagick.ini
    - /usr/local/php/etc/php.d/04-ldap.ini
    - /usr/local/php/etc/php.d/05-redis.ini
    - /usr/local/php/etc/php.d/07-mongodb.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-fileinfo` to temporarily ignore these required extensions.



17、安装 PHP 扩展 fileinfo 后,再次执行。报错:The Process class relies on proc_open, which is not available on your PHP installation.

[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 114 installs, 0 updates, 0 removals
proc_open is disabled so 'unzip' and '7z' commands cannot be used, zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Enabling proc_open and installing 'unzip' or '7z' (21.01+) may remediate them.
  - Downloading brick/math (0.11.0)
  - Downloading psr/log (2.0.0)
  - Downloading psr/cache (3.0.0)
  - Downloading doctrine/event-manager (2.0.0)
  - Downloading doctrine/deprecations (v1.1.1)
  - Downloading doctrine/cache (2.2.0)
  - Downloading doctrine/dbal (3.6.3)
  - Downloading doctrine/lexer (1.2.3)
  - Downloading symfony/polyfill-ctype (v1.27.0)
  - Downloading webmozart/assert (1.11.0)
  - Downloading dragonmantank/cron-expression (v3.3.2)
  - Downloading symfony/polyfill-php80 (v1.27.0)
  - Downloading symfony/polyfill-mbstring (v1.27.0)
  - Downloading symfony/var-dumper (v5.4.24)
  - Downloading symfony/polyfill-intl-normalizer (v1.27.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.27.0)
  - Downloading symfony/string (v6.3.0)
  - Downloading symfony/deprecation-contracts (v3.3.0)
  - Downloading psr/container (1.1.2)
  - Downloading symfony/service-contracts (v2.5.2)
  - Downloading symfony/polyfill-php73 (v1.27.0)
  - Downloading symfony/console (v5.4.24)
  - Downloading monolog/monolog (2.9.1)
  - Downloading voku/portable-ascii (1.6.1)
  - Downloading phpoption/phpoption (1.9.1)
  - Downloading graham-campbell/result-type (v1.1.1)
  - Downloading vlucas/phpdotenv (v5.5.0)
  - Downloading symfony/css-selector (v6.3.0)
  - Downloading tijsverkoyen/css-to-inline-styles (2.2.6)
  - Downloading symfony/routing (v5.4.22)
  - Downloading symfony/process (v5.4.24)
  - Downloading symfony/polyfill-php72 (v1.27.0)
  - Downloading symfony/polyfill-intl-idn (v1.27.0)
  - Downloading symfony/mime (v5.4.23)
  - Downloading symfony/http-foundation (v5.4.24)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v3.3.0)
  - Downloading symfony/event-dispatcher (v6.3.0)
  - Downloading symfony/error-handler (v5.4.24)
  - Downloading symfony/http-kernel (v5.4.24)
  - Downloading symfony/finder (v5.4.21)
  - Downloading symfony/polyfill-iconv (v1.27.0)
  - Downloading egulias/email-validator (2.1.25)
  - Downloading swiftmailer/swiftmailer (v6.3.0)
  - Downloading ramsey/collection (2.0.0)
  - Downloading ramsey/uuid (4.7.4)
  - Downloading psr/simple-cache (1.0.1)
  - Downloading opis/closure (3.6.3)
  - Downloading symfony/translation-contracts (v3.3.0)
  - Downloading symfony/translation (v6.3.0)
  - Downloading nesbot/carbon (2.67.0)
  - Downloading league/mime-type-detection (1.11.0)
  - Downloading league/flysystem (1.1.10)
  - Downloading nette/utils (v4.0.0)
  - Downloading nette/schema (v1.2.3)
  - Downloading dflydev/dot-access-data (v3.0.2)
  - Downloading league/config (v1.2.0)
  - Downloading league/commonmark (2.4.0)
  - Downloading laravel/serializable-closure (v1.3.0)
  - Downloading doctrine/inflector (2.0.6)
  - Downloading laravel/framework (v8.83.27)
  - Downloading facade/ignition-contracts (1.0.2)
  - Downloading facade/flare-client-php (1.10.0)
  - Downloading facade/ignition (2.17.7)
  - Downloading fakerphp/faker (v1.22.0)
  - Downloading fideloper/proxy (4.4.2)
  - Downloading fruitcake/php-cors (v1.2.0)
  - Downloading fruitcake/laravel-cors (v3.0.0)
  - Downloading guzzlehttp/promises (2.0.0)
  - Downloading symfony/yaml (v6.3.0)
  - Downloading laravel/sail (v1.22.0)
  - Downloading nikic/php-parser (v4.15.5)
  - Downloading psy/psysh (v0.11.18)
  - Downloading laravel/tinker (v2.8.1)
  - Downloading hamcrest/hamcrest-php (v2.0.1)
  - Downloading mockery/mockery (1.6.1)
  - Downloading filp/whoops (2.15.2)
  - Downloading nunomaduro/collision (v5.11.0)
  - Downloading sebastian/version (3.0.2)
  - Downloading sebastian/type (3.2.1)
  - Downloading sebastian/resource-operations (3.0.3)
  - Downloading sebastian/recursion-context (4.0.5)
  - Downloading sebastian/object-reflector (2.0.4)
  - Downloading sebastian/object-enumerator (4.0.4)
  - Downloading sebastian/global-state (5.0.5)
  - Downloading sebastian/exporter (4.0.5)
  - Downloading sebastian/environment (5.1.5)
  - Downloading sebastian/diff (4.0.5)
  - Downloading sebastian/comparator (4.0.8)
  - Downloading sebastian/code-unit (1.0.8)
  - Downloading sebastian/cli-parser (1.0.1)
  - Downloading phpunit/php-timer (5.0.3)
  - Downloading phpunit/php-text-template (2.0.4)
  - Downloading phpunit/php-invoker (3.1.1)
  - Downloading phpunit/php-file-iterator (3.0.6)
  - Downloading theseer/tokenizer (1.2.1)
  - Downloading sebastian/lines-of-code (1.0.3)
  - Downloading sebastian/complexity (2.0.2)
  - Downloading sebastian/code-unit-reverse-lookup (2.0.3)
  - Downloading phpunit/php-code-coverage (9.2.26)
  - Downloading phar-io/version (3.2.1)
  - Downloading phar-io/manifest (2.0.3)
  - Downloading myclabs/deep-copy (1.11.1)
  - Downloading doctrine/instantiator (2.0.0)
  - Downloading phpunit/phpunit (9.6.8)
  - Downloading psr/http-message (1.1)
  - Downloading psr/http-factory (1.0.2)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-client (1.0.2)
  - Downloading guzzlehttp/psr7 (2.5.0)
  - Downloading guzzlehttp/guzzle (7.7.0)
  - Downloading firebase/php-jwt (v6.5.0)
  - Downloading shopify/shopify-api (v5.0.0)
  - Downloading squizlabs/php_codesniffer (3.7.2)
  - Installing brick/math (0.11.0): Extracting archive
  - Installing psr/log (2.0.0): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing doctrine/event-manager (2.0.0): Extracting archive
  - Installing doctrine/deprecations (v1.1.1): Extracting archive
  - Installing doctrine/cache (2.2.0): Extracting archive
  - Installing doctrine/dbal (3.6.3): Extracting archive
  - Installing doctrine/lexer (1.2.3): Extracting archive
  - Installing symfony/polyfill-ctype (v1.27.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.2): Extracting archive
  - Installing symfony/polyfill-php80 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.24): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.27.0): Extracting archive
  - Installing symfony/string (v6.3.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.2): Extracting archive
  - Installing symfony/polyfill-php73 (v1.27.0): Extracting archive
  - Installing symfony/console (v5.4.24): Extracting archive
  - Installing monolog/monolog (2.9.1): Extracting archive
  - Installing voku/portable-ascii (1.6.1): Extracting archive
  - Installing phpoption/phpoption (1.9.1): Extracting archive
  - Installing graham-campbell/result-type (v1.1.1): Extracting archive
  - Installing vlucas/phpdotenv (v5.5.0): Extracting archive
  - Installing symfony/css-selector (v6.3.0): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.6): Extracting archive
  - Installing symfony/routing (v5.4.22): Extracting archive
  - Installing symfony/process (v5.4.24): Extracting archive
  - Installing symfony/polyfill-php72 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.27.0): Extracting archive
  - Installing symfony/mime (v5.4.23): Extracting archive
  - Installing symfony/http-foundation (v5.4.24): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.3.0): Extracting archive
  - Installing symfony/event-dispatcher (v6.3.0): Extracting archive
  - Installing symfony/error-handler (v5.4.24): Extracting archive
  - Installing symfony/http-kernel (v5.4.24): Extracting archive
  - Installing symfony/finder (v5.4.21): Extracting archive
  - Installing symfony/polyfill-iconv (v1.27.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
  - Installing ramsey/collection (2.0.0): Extracting archive
  - Installing ramsey/uuid (4.7.4): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.3): Extracting archive
  - Installing symfony/translation-contracts (v3.3.0): Extracting archive
  - Installing symfony/translation (v6.3.0): Extracting archive
  - Installing nesbot/carbon (2.67.0): Extracting archive
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Installing league/flysystem (1.1.10): Extracting archive
  - Installing nette/utils (v4.0.0): Extracting archive
  - Installing nette/schema (v1.2.3): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.2): Extracting archive
  - Installing league/config (v1.2.0): Extracting archive
  - Installing league/commonmark (2.4.0): Extracting archive
  - Installing laravel/serializable-closure (v1.3.0): Extracting archive
  - Installing doctrine/inflector (2.0.6): Extracting archive
  - Installing laravel/framework (v8.83.27): Extracting archive
  - Installing facade/ignition-contracts (1.0.2): Extracting archive
  - Installing facade/flare-client-php (1.10.0): Extracting archive
  - Installing facade/ignition (2.17.7): Extracting archive
  - Installing fakerphp/faker (v1.22.0): Extracting archive
  - Installing fideloper/proxy (4.4.2): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing fruitcake/laravel-cors (v3.0.0): Extracting archive
  - Installing guzzlehttp/promises (2.0.0): Extracting archive
  - Installing symfony/yaml (v6.3.0): Extracting archive
  - Installing laravel/sail (v1.22.0): Extracting archive
  - Installing nikic/php-parser (v4.15.5): Extracting archive
  - Installing psy/psysh (v0.11.18): Extracting archive
  - Installing laravel/tinker (v2.8.1): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.6.1): Extracting archive
  - Installing filp/whoops (2.15.2): Extracting archive
  - Installing nunomaduro/collision (v5.11.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.1): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.5): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.5): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.5): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.26): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing doctrine/instantiator (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.8): Extracting archive
  - Installing psr/http-message (1.1): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-client (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.5.0): Extracting archive
  - Installing guzzlehttp/guzzle (7.7.0): Extracting archive
  - Installing firebase/php-jwt (v6.5.0): Extracting archive
  - Installing shopify/shopify-api (v5.0.0): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.2): Extracting archive
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
 
In Process.php line 146:
 
  The Process class relies on proc_open, which is not available on your PHP installation.
 
 
install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--download-only] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [--audit] [--audit-format AUDIT-FORMAT] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]
 
 

18、参考:Jenkins 构建镜像时,报错:The Process class relies on proc_open, which is not available on your PHP installation.的解决 。 编辑 /usr/local/php/etc/php.ini,在 disable_functions 中删除 proc_open、proc_get_status


disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen

[root@iZ23wv7v5ggZ php]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!



19、执行数据库迁移时失败,报错:SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table

   Illuminate\Database\QueryException

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `failed_jobs` add unique `failed_jobs_uuid_unique`(`uuid`))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +9 vendor frames
  10  database/migrations/2019_08_19_000000_create_failed_jobs_table.php:24
      Illuminate\Support\Facades\Facade::__callStatic()

      +22 vendor frames
  33  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()


20、参考:阿里云RDS的参数配置,启用Innodb_large_prefix 。编辑 config/database.php,修改 ‘engine’ => null, 为 ‘engine’ => ‘InnoDB’,。再次执行数据库迁移,报错。SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘failed_jobs’ already exists。在数据库中删除掉所有表后,重新执行迁移。不再报错。


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (13.03ms)
Migrating: 2021_05_03_050717_create_sessions_table
Migrated:  2021_05_03_050717_create_sessions_table (11.62ms)
Migrating: 2021_05_05_071311_add_scope_expires_access_token_to_sessions
Migrated:  2021_05_05_071311_add_scope_expires_access_token_to_sessions (9.72ms)
Migrating: 2021_05_11_151158_add_online_access_info_to_sessions
Migrated:  2021_05_11_151158_add_online_access_info_to_sessions (9.32ms)
Migrating: 2021_05_17_152611_change_sessions_user_id_type
Migrated:  2021_05_17_152611_change_sessions_user_id_type (48.28ms)



21、构建后端。


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer build
> composer build-frontend-links
> ln -sf ../frontend/dist/assets public/assets && ln -sf ../frontend/dist/index.html public/index.html



22、访问应用首页:https://learn-php-app-0605-prod.shuijingwanwq.com/ 。响应 403。如图6

访问应用首页:https://learn-php-app-0605-prod.shuijingwanwq.com/ 。响应 403

图6

23、查看虚拟主机配置文件


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# cat /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf
server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.key;
  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
  ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;
  ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;
  ssl_conf_command Options PrioritizeChaCha;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache shared:SSL:10m;
  ssl_buffer_size 2k;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name learn-php-app-0605-prod.shuijingwanwq.com;
  access_log /data/wwwlogs/learn-php-app-0605-prod.shuijingwanwq.com_nginx.log combined;
  index index.html index.htm index.php;
  root /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

  include /usr/local/nginx/conf/rewrite/laravel.conf;
  #error_page 404 /404.html;
  #error_page 502 /502.html;
  location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
    valid_referers none blocked *.shuijingwanwq.com learn-php-app-0605-prod.shuijingwanwq.com;
    if ($invalid_referer) {
        return 403;
    }
  }
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    deny all;
  }
  location /.well-known {
    allow all;
  }
}
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# ^C
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# cat /usr/local/nginx/conf/rewrite/laravel.conf
location / {
  try_files $uri $uri/ /index.php?$query_string;
}
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]#



24、参考模板中的 nginx.conf,其内容如下


user www-data www-data;

events {
    worker_connections 1024;
}

http {
    index index.php index.html;

    upstream php {
        server 127.0.0.1:9000;
    }

    server {
        include /etc/nginx/mime.types;
        include /etc/nginx/default.d/*.conf;

        listen PORT;
        server_name 0.0.0.0;
        root /app/public;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ [^/]\.php(/|$) {
            include /etc/nginx/fastcgi_params;

            try_files $uri $uri/ /index.php?$uri;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

            fastcgi_pass   php;
            fastcgi_index  index.php;
        }
    }
}


25、编辑 /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf


  index index.php index.html;
  root /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/public;


26、响应 500,开启 debug,编辑 .env。报错:TypeError
Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/app/Lib/AuthRedirection.php on line 17 。不用理会,符合预期。如图7

报错:TypeErrorShopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/app/Lib/AuthRedirection.php on line 17

图7


APP_ENV=local
APP_DEBUG=true


27、更新合作伙伴仪表板中的 URL。如图8

更新合作伙伴仪表板中的 URL

图8

28、在合作伙伴仪表板中,转到应用程序的概览页面。在“测试您的应用”部分中,单击“选择商店”,然后选择一个商店来测试应用。如图9

在合作伙伴仪表板中,转到应用程序的概览页面。在“测试您的应用”部分中,单击“选择商店”,然后选择一个商店来测试应用

图9

29、安装应用时,报错:ops, something went wrong. 。原因应该在于请求参数有误。如图10

安装应用时,报错:ops, something went wrong. 。原因应该在于请求参数有误

图10


client_id: not_defined
scope: not_defined
redirect_uri: https://not_defined/api/auth/callback
state: b27be356-0010-43ae-b3b8-90a337314c0c
grant_options[]: 


30、编辑 .env,参考 .env.testing


APP_NAME="Shopify PHP App 0605 Prod"
APP_ENV=production
APP_KEY=base64:tPbLjWcISYL3Z/HS+OQS2GXvMPb0A7GlvNv6iFwFG6A=
APP_DEBUG=false
APP_URL=https://learn-php-app-0605-prod.shuijingwanwq.com

SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
SCOPES=write_products
HOST=learn-php-app-0605-prod.shuijingwanwq.com

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=**************
DB_PORT=3306
DB_DATABASE=learn_php_app_0605_prod
DB_USERNAME=learn_php_app_0605_prod
DB_PASSWORD=*********



31、不再报错。如图11

不再报错

图11

32、点击安装应用后,进入店铺后台,但是页面预览为空白。如图12

点击安装应用后,进入店铺后台,但是页面预览为空白

图12

33、重新构建前端与后端后,卸载应用。如图13

重新构建前端与后端后,卸载应用

图13

34、再次安装,刷新页面,页面不再空白,符合预期。如图14

再次安装,刷新页面,页面不再空白,符合预期

图14

]]>
https://www.shuijingwanwq.com/2023/07/13/7855/feed/ 1
在 WSL2 中的 Ubuntu-20.04 中创建应用:Shopify App Template – PHP https://www.shuijingwanwq.com/2023/07/01/7792/ https://www.shuijingwanwq.com/2023/07/01/7792/#comments Sat, 01 Jul 2023 02:06:44 +0000 https://www.shuijingwanwq.com/?p=7792 浏览量: 268

1、参考:在 WSL2 中的 Ubuntu-20.04 中安装 Shopify CLI 3.0(基于 Node.js),提前检查相应的要求是否满足

2、创建应用,选择 PHP 模板,报错:operation not permitted, copyfile

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$ npm init @shopify/app@latest
Need to install the following packages:
  @shopify/create-app@3.46.2
Ok to proceed? (y)

Welcome. Let’s get started by naming your app project. You can change it later.

?  Your app project name?
✔  learn-php-app-ubuntu-2004-0602

?  Which template would you like to use?
✔  php


╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  EPERM: operation not permitted, copyfile                                    │
│  '/tmp/cb635eef29c31a10687f90a7693d4848/app/web/storage/logs/.gitignore' ->  │
│   '/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web/storage/lo  │
│  gs/.gitignore'                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

npm notice
npm notice New minor version of npm available! 9.5.1 -> 9.6.7
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.7
npm notice Run npm install -g npm@9.6.7 to update!
npm notice
npm ERR! code 1
npm ERR! path /mnt/e/wwwroot/shopify-app
npm ERR! command failed
npm ERR! command sh -c create-app

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/wangqiang/.npm/_logs/2023-06-02T03_46_50_520Z-debug-0.log
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$

3、在命令 npm init @shopify/app@latest 前添加 sudo,以提升权限,不再报错

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$ sudo npm init @shopify/app@latest

Welcome. Let’s get started by naming your app project. You can change it later.

?  Your app project name?
✔  learn-php-app-ubuntu-2004-0602

?  Which template would you like to use?
✔  php

4、参考:安装 PHP 、Composer

wangqiang@DESKTOP-QLPK8QM:~$ sudo apt install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfwupdplugin1 libxmlb1
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap libjansson4 liblua5.2-0 php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache
  php7.4-readline ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom php-pear openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
info: Switch to mpm prefork for package libapache2-mod-php7.4
Module mpm_event disabled.
Enabling module mpm_prefork.
info: Executing deferred 'a2enmod php7.4' for package libapache2-mod-php7.4
Enabling module php7.4.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
invoke-rc.d: could not determine current runlevel
Setting up php7.4 (7.4.3-4ubuntu2.18) ...
Setting up php (2:7.4+75) ...
Processing triggers for ufw (0.36-6ubuntu1) ...
Processing triggers for systemd (245.4-4ubuntu3.21) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

Processing triggers for php7.4-cli (7.4.3-4ubuntu2.18) ...
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.18) ...
wangqiang@DESKTOP-QLPK8QM:~$ sudo apt install composer
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfwupdplugin1 libxmlb1
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  jsonlint libonig5 php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler
  php-json-schema php-mbstring php-psr-container php-psr-log php-symfony-console php-symfony-filesystem
  php-symfony-finder php-symfony-process php-symfony-service-contracts php7.4-mbstring
Preparing to unpack .../16-composer_1.10.1-1_all.deb ...
Unpacking composer (1.10.1-1) ...
Setting up php-symfony-finder (4.3.8+dfsg-1ubuntu1) ...
Setting up jsonlint (1.7.2-1) ...
Setting up php-psr-container (1.0.0-2) ...
Setting up php-symfony-service-contracts (1.1.8-1) ...
Setting up php-composer-ca-bundle (1.2.6-1) ...
Setting up php-symfony-process (4.3.8+dfsg-1ubuntu1) ...
Setting up php-symfony-filesystem (4.3.8+dfsg-1ubuntu1) ...
Setting up php-psr-log (1.1.2-1) ...
Setting up php-composer-semver (1.5.1-1) ...
Setting up php-json-schema (5.2.9-1) ...
Setting up php-composer-spdx-licenses (1.5.3-1) ...
Setting up libonig5:amd64 (6.9.4-1) ...
Setting up php-composer-xdebug-handler (1.4.0-1) ...
Setting up php7.4-mbstring (7.4.3-4ubuntu2.18) ...

Creating config file /etc/php/7.4/mods-available/mbstring.ini with new version
Setting up php-mbstring (2:7.4+75) ...
Setting up php-symfony-console (4.3.8+dfsg-1ubuntu1) ...
Setting up composer (1.10.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.18) ...
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.18) ...

5、创建应用程序后,设置 Laravel 应用程序。安装依赖包。提示:建议升级至 Composer 2。先卸载掉 Composer 1,再安装 Composer 2 。参考:后续使用:php composer.phar

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ composer install
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/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ composer -V
Composer 1.10.1 2020-03-13 20:34:27
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt-get remove composer
[sudo] password for wangqiang:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  jsonlint libfwupdplugin1 libonig5 libxmlb1 php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses
  php-composer-xdebug-handler php-json-schema php-mbstring php-psr-container php-psr-log php-symfony-console
  php-symfony-filesystem php-symfony-finder php-symfony-process php-symfony-service-contracts php7.4-mbstring
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  composer
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1996 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 66661 files and directories currently installed.)
Removing composer (1.10.1-1) ...
Processing triggers for man-db (2.9.1-1) ...
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ composer -V
-bash: /usr/bin/composer: No such file or directory
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 2.5.7) successfully installed to: /mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web/composer.phar
Use it: php composer.phar
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php composer.phar -V
Composer version 2.5.7 2023-05-24 15:00:39

6、提示:Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php composer.phar install
Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ apt-cache search php | grep cur
l
php-curl - CURL module for PHP [default]
php7.4-curl - CURL module for PHP
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt-get install php-curl
[sudo] password for wangqiang:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  jsonlint libfwupdplugin1 libonig5 libxmlb1 php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses
  php-composer-xdebug-handler php-json-schema php-mbstring php-psr-container php-psr-log php-symfony-console
  php-symfony-filesystem php-symfony-finder php-symfony-process php-symfony-service-contracts php7.4-mbstring
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  php7.4-curl
The following NEW packages will be installed:
  php-curl php7.4-curl
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.9 kB of archives.
After this operation, 148 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-curl amd64 7.4.3-4ubuntu2.18 [30.9 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 php-curl all 2:7.4+75 [2000 B]
Fetched 32.9 kB in 2s (16.1 kB/s)
Selecting previously unselected package php7.4-curl.
(Reading database ... 66332 files and directories currently installed.)
Preparing to unpack .../php7.4-curl_7.4.3-4ubuntu2.18_amd64.deb ...
Unpacking php7.4-curl (7.4.3-4ubuntu2.18) ...
Selecting previously unselected package php-curl.
Preparing to unpack .../php-curl_2%3a7.4+75_all.deb ...
Unpacking php-curl (2:7.4+75) ...
Setting up php7.4-curl (7.4.3-4ubuntu2.18) ...

Creating config file /etc/php/7.4/mods-available/curl.ini with new version
Setting up php-curl (2:7.4+75) ...
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.18) ...
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.18) ...

7、Your requirements could not be resolved to an installable set of packages. 根 composer.json 需要 php ~8.0.0 || ~8.1.0 || ~8.2.0 但您的 php 版本 (7.4.3) 不满足该要求。一些必需的扩展也没有启用。

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php composer.phar install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires php ~8.0.0 || ~8.1.0 || ~8.2.0 but your php version (7.4.3) does not satisfy that requirement.
  Problem 2
    - Root composer.json requires PHP extension ext-xml * but it is missing from your system. Install or enable PHP's xml extension.
  Problem 3
    - Root composer.json requires PHP extension ext-zip * but it is missing from your system. Install or enable PHP's zip extension.
  Problem 4
    - Root composer.json requires shopify/shopify-api ^5.0 -> satisfiable by shopify/shopify-api[v5.0.0].
    - shopify/shopify-api v5.0.0 requires php ~8.0.0 || ~8.1.0 || ~8.2.0 -> your php version (7.4.3) does not satisfy that requirement.
  Problem 5
    - Root composer.json requires squizlabs/php_codesniffer ^3.6 -> satisfiable by squizlabs/php_codesniffer[3.6.0, ..., 3.x-dev].
    - squizlabs/php_codesniffer[3.6.0, ..., 3.x-dev] require ext-xmlwriter * -> it is missing from your system. Install or enable PHP's xmlwriter extension.
  Problem 6
    - phpunit/phpunit[9.3.3, ..., 9.6.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
    - Root composer.json requires phpunit/phpunit ^9.3.3 -> satisfiable by phpunit/phpunit[9.3.3, ..., 9.6.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini
    - /etc/php/7.4/cli/conf.d/10-opcache.ini
    - /etc/php/7.4/cli/conf.d/10-pdo.ini
    - /etc/php/7.4/cli/conf.d/20-calendar.ini
    - /etc/php/7.4/cli/conf.d/20-ctype.ini
    - /etc/php/7.4/cli/conf.d/20-curl.ini
    - /etc/php/7.4/cli/conf.d/20-exif.ini
    - /etc/php/7.4/cli/conf.d/20-ffi.ini
    - /etc/php/7.4/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.4/cli/conf.d/20-ftp.ini
    - /etc/php/7.4/cli/conf.d/20-gettext.ini
    - /etc/php/7.4/cli/conf.d/20-iconv.ini
    - /etc/php/7.4/cli/conf.d/20-json.ini
    - /etc/php/7.4/cli/conf.d/20-mbstring.ini
    - /etc/php/7.4/cli/conf.d/20-phar.ini
    - /etc/php/7.4/cli/conf.d/20-posix.ini
    - /etc/php/7.4/cli/conf.d/20-readline.ini
    - /etc/php/7.4/cli/conf.d/20-shmop.ini
    - /etc/php/7.4/cli/conf.d/20-sockets.ini
    - /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.4/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.4/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.4/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xml --ignore-platform-req=ext-zip --ignore-platform-req=ext-xmlwriter --ignore-platform-req=ext-dom` to temporarily ignore these required extensions.

8、参考:在 WSL2 中的 Ubuntu-20.04 中卸载 PHP 7.4,然后安装 PHP 8 

9、继续安装 Composer 依赖

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt-get install php8.1-curl
[sudo] password for wangqiang:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  php8.1-curl
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 33.6 kB of archives.
After this operation, 152 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.1-curl amd64 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 [33.6 kB]
Fetched 33.6 kB in 2s (21.8 kB/s)
Selecting previously unselected package php8.1-curl.
(Reading database ... 65958 files and directories currently installed.)
Preparing to unpack .../php8.1-curl_8.1.18-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.1-curl (8.1.18-1+ubuntu20.04.1+deb.sury.org+1) ...
Setting up php8.1-curl (8.1.18-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.1/mods-available/curl.ini with new version
Processing triggers for libapache2-mod-php8.1 (8.1.18-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for php8.1-cli (8.1.18-1+ubuntu20.04.1+deb.sury.org+1) ...
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php composer.phar install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires PHP extension ext-xml * but it is missing from your system. Install or enable PHP's xml extension.
  Problem 2
    - Root composer.json requires PHP extension ext-zip * but it is missing from your system. Install or enable PHP's zip extension.
  Problem 3
    - Root composer.json requires squizlabs/php_codesniffer ^3.6 -> satisfiable by squizlabs/php_codesniffer[3.6.0, ..., 3.x-dev].
    - squizlabs/php_codesniffer[3.6.0, ..., 3.x-dev] require ext-xmlwriter * -> it is missing from your system. Install or enable PHP's xmlwriter extension.
  Problem 4
    - phpunit/phpunit[9.3.3, ..., 9.6.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
    - Root composer.json requires phpunit/phpunit ^9.3.3 -> satisfiable by phpunit/phpunit[9.3.3, ..., 9.6.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/8.1/cli/php.ini
    - /etc/php/8.1/cli/conf.d/10-opcache.ini
    - /etc/php/8.1/cli/conf.d/10-pdo.ini
    - /etc/php/8.1/cli/conf.d/20-calendar.ini
    - /etc/php/8.1/cli/conf.d/20-ctype.ini
    - /etc/php/8.1/cli/conf.d/20-curl.ini
    - /etc/php/8.1/cli/conf.d/20-exif.ini
    - /etc/php/8.1/cli/conf.d/20-ffi.ini
    - /etc/php/8.1/cli/conf.d/20-fileinfo.ini
    - /etc/php/8.1/cli/conf.d/20-ftp.ini
    - /etc/php/8.1/cli/conf.d/20-gettext.ini
    - /etc/php/8.1/cli/conf.d/20-iconv.ini
    - /etc/php/8.1/cli/conf.d/20-phar.ini
    - /etc/php/8.1/cli/conf.d/20-posix.ini
    - /etc/php/8.1/cli/conf.d/20-readline.ini
    - /etc/php/8.1/cli/conf.d/20-shmop.ini
    - /etc/php/8.1/cli/conf.d/20-sockets.ini
    - /etc/php/8.1/cli/conf.d/20-sysvmsg.ini
    - /etc/php/8.1/cli/conf.d/20-sysvsem.ini
    - /etc/php/8.1/cli/conf.d/20-sysvshm.ini
    - /etc/php/8.1/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xml --ignore-platform-req=ext-zip --ignore-platform-req=ext-xmlwriter --ignore-platform-req=ext-dom` to temporarily ignore these required extensions.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt-get install php8.1-xml
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt-get install php8.1-zip
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo php compos
er.phar install
[sudo] password for wangqiang:
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 114 installs, 0 updates, 0 removals
  - Downloading brick/math (0.11.0)
  - Downloading psr/log (2.0.0)
  - Downloading psr/cache (3.0.0)
  - Downloading doctrine/event-manager (2.0.0)
  - Downloading doctrine/deprecations (v1.1.0)
  - Downloading doctrine/cache (2.2.0)
  - Downloading doctrine/dbal (3.6.2)
  - Downloading doctrine/lexer (1.2.3)
  - Downloading symfony/polyfill-ctype (v1.27.0)
  - Downloading webmozart/assert (1.11.0)
  - Downloading dragonmantank/cron-expression (v3.3.2)
  - Downloading symfony/polyfill-php80 (v1.27.0)
  - Downloading symfony/polyfill-mbstring (v1.27.0)
  - Downloading symfony/var-dumper (v5.4.24)
  - Downloading symfony/polyfill-intl-normalizer (v1.27.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.27.0)
  - Downloading symfony/string (v6.3.0)
  - Downloading symfony/deprecation-contracts (v3.3.0)
  - Downloading psr/container (1.1.2)
  - Downloading symfony/service-contracts (v2.5.2)
  - Downloading symfony/polyfill-php73 (v1.27.0)
  - Downloading symfony/console (v5.4.24)
  - Downloading monolog/monolog (2.9.1)
  - Downloading voku/portable-ascii (1.6.1)
  - Downloading phpoption/phpoption (1.9.1)
  - Downloading graham-campbell/result-type (v1.1.1)
  - Downloading vlucas/phpdotenv (v5.5.0)
  - Downloading symfony/css-selector (v6.3.0)
  - Downloading tijsverkoyen/css-to-inline-styles (2.2.6)
  - Downloading symfony/routing (v5.4.22)
  - Downloading symfony/process (v5.4.24)
  - Downloading symfony/polyfill-php72 (v1.27.0)
  - Downloading symfony/polyfill-intl-idn (v1.27.0)
  - Downloading symfony/mime (v5.4.23)
  - Downloading symfony/http-foundation (v5.4.24)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v3.3.0)
  - Downloading symfony/event-dispatcher (v6.3.0)
  - Downloading symfony/error-handler (v5.4.24)
  - Downloading symfony/http-kernel (v5.4.24)
  - Downloading symfony/finder (v5.4.21)
  - Downloading symfony/polyfill-iconv (v1.27.0)
  - Downloading egulias/email-validator (2.1.25)
  - Downloading swiftmailer/swiftmailer (v6.3.0)
  - Downloading ramsey/collection (2.0.0)
  - Downloading ramsey/uuid (4.7.4)
  - Downloading psr/simple-cache (1.0.1)
  - Downloading opis/closure (3.6.3)
  - Downloading symfony/translation-contracts (v3.3.0)
  - Downloading symfony/translation (v6.3.0)
  - Downloading nesbot/carbon (2.67.0)
  - Downloading league/mime-type-detection (1.11.0)
  - Downloading league/flysystem (1.1.10)
  - Downloading nette/utils (v4.0.0)
  - Downloading nette/schema (v1.2.3)
  - Downloading dflydev/dot-access-data (v3.0.2)
  - Downloading league/config (v1.2.0)
  - Downloading league/commonmark (2.4.0)
  - Downloading laravel/serializable-closure (v1.3.0)
  - Downloading doctrine/inflector (2.0.6)
  - Downloading laravel/framework (v8.83.27)
  - Downloading facade/ignition-contracts (1.0.2)
  - Downloading facade/flare-client-php (1.10.0)
  - Downloading facade/ignition (2.17.7)
  - Downloading fakerphp/faker (v1.22.0)
  - Downloading fideloper/proxy (4.4.2)
  - Downloading fruitcake/php-cors (v1.2.0)
  - Downloading fruitcake/laravel-cors (v3.0.0)
  - Downloading guzzlehttp/promises (2.0.0)
  - Downloading symfony/yaml (v6.3.0)
  - Downloading laravel/sail (v1.22.0)
  - Downloading nikic/php-parser (v4.15.5)
  - Downloading psy/psysh (v0.11.18)
  - Downloading laravel/tinker (v2.8.1)
  - Downloading hamcrest/hamcrest-php (v2.0.1)
  - Downloading mockery/mockery (1.5.1)
  - Downloading filp/whoops (2.15.2)
  - Downloading nunomaduro/collision (v5.11.0)
  - Downloading sebastian/version (3.0.2)
  - Downloading sebastian/type (3.2.1)
  - Downloading sebastian/resource-operations (3.0.3)
  - Downloading sebastian/recursion-context (4.0.5)
  - Downloading sebastian/object-reflector (2.0.4)
  - Downloading sebastian/object-enumerator (4.0.4)
  - Downloading sebastian/global-state (5.0.5)
  - Downloading sebastian/exporter (4.0.5)
  - Downloading sebastian/environment (5.1.5)
  - Downloading sebastian/diff (4.0.5)
  - Downloading sebastian/comparator (4.0.8)
  - Downloading sebastian/code-unit (1.0.8)
  - Downloading sebastian/cli-parser (1.0.1)
  - Downloading phpunit/php-timer (5.0.3)
  - Downloading phpunit/php-text-template (2.0.4)
  - Downloading phpunit/php-invoker (3.1.1)
  - Downloading phpunit/php-file-iterator (3.0.6)
  - Downloading theseer/tokenizer (1.2.1)
  - Downloading sebastian/lines-of-code (1.0.3)
  - Downloading sebastian/complexity (2.0.2)
  - Downloading sebastian/code-unit-reverse-lookup (2.0.3)
  - Downloading phpunit/php-code-coverage (9.2.26)
  - Downloading phar-io/version (3.2.1)
  - Downloading phar-io/manifest (2.0.3)
  - Downloading myclabs/deep-copy (1.11.1)
  - Downloading doctrine/instantiator (2.0.0)
  - Downloading phpunit/phpunit (9.6.8)
  - Downloading psr/http-message (1.1)
  - Downloading psr/http-factory (1.0.2)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-client (1.0.2)
  - Downloading guzzlehttp/psr7 (2.5.0)
  - Downloading guzzlehttp/guzzle (7.7.0)
  - Downloading firebase/php-jwt (v6.5.0)
  - Downloading shopify/shopify-api (v5.0.0)
  - Downloading squizlabs/php_codesniffer (3.7.2)
  - Installing brick/math (0.11.0): Extracting archive
  - Installing psr/log (2.0.0): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing doctrine/event-manager (2.0.0): Extracting archive
  - Installing doctrine/deprecations (v1.1.0): Extracting archive
  - Installing doctrine/cache (2.2.0): Extracting archive
  - Installing doctrine/dbal (3.6.2): Extracting archive
  - Installing doctrine/lexer (1.2.3): Extracting archive
  - Installing symfony/polyfill-ctype (v1.27.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.2): Extracting archive
  - Installing symfony/polyfill-php80 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.24): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.27.0): Extracting archive
  - Installing symfony/string (v6.3.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.2): Extracting archive
  - Installing symfony/polyfill-php73 (v1.27.0): Extracting archive
  - Installing symfony/console (v5.4.24): Extracting archive
  - Installing monolog/monolog (2.9.1): Extracting archive
  - Installing voku/portable-ascii (1.6.1): Extracting archive
  - Installing phpoption/phpoption (1.9.1): Extracting archive
  - Installing graham-campbell/result-type (v1.1.1): Extracting archive
  - Installing vlucas/phpdotenv (v5.5.0): Extracting archive
  - Installing symfony/css-selector (v6.3.0): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.6): Extracting archive
  - Installing symfony/routing (v5.4.22): Extracting archive
  - Installing symfony/process (v5.4.24): Extracting archive
  - Installing symfony/polyfill-php72 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.27.0): Extracting archive
  - Installing symfony/mime (v5.4.23): Extracting archive
  - Installing symfony/http-foundation (v5.4.24): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.3.0): Extracting archive
  - Installing symfony/event-dispatcher (v6.3.0): Extracting archive
  - Installing symfony/error-handler (v5.4.24): Extracting archive
  - Installing symfony/http-kernel (v5.4.24): Extracting archive
  - Installing symfony/finder (v5.4.21): Extracting archive
  - Installing symfony/polyfill-iconv (v1.27.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
  - Installing ramsey/collection (2.0.0): Extracting archive
  - Installing ramsey/uuid (4.7.4): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.3): Extracting archive
  - Installing symfony/translation-contracts (v3.3.0): Extracting archive
  - Installing symfony/translation (v6.3.0): Extracting archive
  - Installing nesbot/carbon (2.67.0): Extracting archive
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Installing league/flysystem (1.1.10): Extracting archive
  - Installing nette/utils (v4.0.0): Extracting archive
  - Installing nette/schema (v1.2.3): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.2): Extracting archive
  - Installing league/config (v1.2.0): Extracting archive
  - Installing league/commonmark (2.4.0): Extracting archive
  - Installing laravel/serializable-closure (v1.3.0): Extracting archive
  - Installing doctrine/inflector (2.0.6): Extracting archive
  - Installing laravel/framework (v8.83.27): Extracting archive
  - Installing facade/ignition-contracts (1.0.2): Extracting archive
  - Installing facade/flare-client-php (1.10.0): Extracting archive
  - Installing facade/ignition (2.17.7): Extracting archive
  - Installing fakerphp/faker (v1.22.0): Extracting archive
  - Installing fideloper/proxy (4.4.2): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing fruitcake/laravel-cors (v3.0.0): Extracting archive
  - Installing guzzlehttp/promises (2.0.0): Extracting archive
  - Installing symfony/yaml (v6.3.0): Extracting archive
  - Installing laravel/sail (v1.22.0): Extracting archive
  - Installing nikic/php-parser (v4.15.5): Extracting archive
  - Installing psy/psysh (v0.11.18): Extracting archive
  - Installing laravel/tinker (v2.8.1): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.5.1): Extracting archive
  - Installing filp/whoops (2.15.2): Extracting archive
  - Installing nunomaduro/collision (v5.11.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.1): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.5): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.5): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.5): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.26): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing doctrine/instantiator (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.8): Extracting archive
  - Installing psr/http-message (1.1): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-client (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.5.0): Extracting archive
  - Installing guzzlehttp/guzzle (7.7.0): Extracting archive
  - Installing firebase/php-jwt (v6.5.0): Extracting archive
  - Installing shopify/shopify-api (v5.0.0): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.2): Extracting archive
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

10、安装 MySQL,参考:进入数据库

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo apt install mysql-server
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ mysql --version
mysql  Ver 8.0.33-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo /etc/init.d/mysql start
 * Starting MySQL database server mysqld                                                                su: warning: cannot change directory to /nonexistent: No such file or directory
                                                                                                 [ OK ]
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> CREATE DATABASE learn_php_app_ubuntu_2004_0602;
Query OK, 1 row affected (0.01 sec)

mysql> SHOW DATABASES;
+--------------------------------+
| Database                       |
+--------------------------------+
| information_schema             |
| learn_php_app_ubuntu_2004_0602 |
| mysql                          |
| performance_schema             |
| sys                            |
+--------------------------------+
5 rows in set (0.00 sec)

mysql>

11、编辑 .env

APP_NAME="Shopify PHP App Ubuntu-20.04"
APP_ENV=local
APP_KEY=
APP_DEBUG=true

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=learn_php_app_ubuntu_2004_0602
DB_USERNAME=
DB_PASSWORD=

12、执行数据库迁移命令时报错:Access denied for user ”@’localhost’ (using password: NO)

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php artisan migrate

   Illuminate\Database\QueryException

  SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = learn_php_app_ubuntu_2004_0602 and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +33 vendor frames
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

13、启动安全脚本提示符:sudo mysql_secure_installation 时,设置密码时提示:Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server.

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
 ... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

14、执行:sudo cat /etc/mysql/debian.cnf,使用文件中的用户名与密码重新设置 .env ,执行数据库迁移成功

APP_NAME="Shopify PHP App Ubuntu-20.04"
APP_ENV=local
APP_KEY=base64:YFa6CcsSTZ4d0u62FbrCmehnoEx9q9bM5OnqjnAxdeU=
APP_DEBUG=true

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=learn_php_app_ubuntu_2004_0602
DB_USERNAME=debian-sys-maint
DB_PASSWORD=nGWMLgJjXnsnhm7t

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602/web$ php artisan migrate
Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (106.88ms)
Migrating: 2021_05_03_050717_create_sessions_table
Migrated:  2021_05_03_050717_create_sessions_table (45.18ms)
Migrating: 2021_05_05_071311_add_scope_expires_access_token_to_sessions
Migrated:  2021_05_05_071311_add_scope_expires_access_token_to_sessions (27.42ms)
Migrating: 2021_05_11_151158_add_online_access_info_to_sessions
Migrated:  2021_05_11_151158_add_online_access_info_to_sessions (23.57ms)
Migrating: 2021_05_17_152611_change_sessions_user_id_type
Migrated:  2021_05_17_152611_change_sessions_user_id_type (630.37ms)

15、启动本地服务器,回到根目录,执行:npm run dev,报错,怀疑是第 3 步骤未执行彻底导致的问题。因为在第 3 步骤未提示:success

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602$ npm run dev

> learn-php-app-ubuntu-2004-0602@1.0.0 dev
> shopify app dev

?  Command `app dev` not found. Did you mean `theme dev`?
✔  Yes, confirm

╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  A store is required                                                         │
│                                                                              │
│  Specify the store passing --store={your_store_url} or set the               │
│  SHOPIFY_FLAG_STORE environment variable.                                    │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0602$

16、从头开始新建应用:learn-php-app-ubuntu-2004-0605,需要耐心等待一段时间,不要中途给中止了。如图1

从头开始新建应用:learn-php-app-ubuntu-2004-0605,需要耐心等待一段时间,不要中途给中止了

图1

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$ sudo npm init @shopify/app@latest

Welcome. Let’s get started by naming your app project. You can change it later.

?  Your app project name?
✔  learn-php-app-ubuntu-2004-0605

?  Which template would you like to use?
✔  php


╭─ success ────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  learn-php-app-ubuntu-2004-0605 is ready for you to build!                   │
│                                                                              │
│  Next steps                                                                  │
│    • Run `cd learn-php-app-ubuntu-2004-0605`                                 │
│    • For extensions, run `npm run generate extension`                        │
│    • To see your app, run `npm run dev`                                      │
│                                                                              │
│  Reference                                                                   │
│    • Shopify docs [1]                                                        │
│    • For an overview of commands, run `npm run shopify app -- --help`        │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://shopify.dev

17、再次从第 4 步骤开始操作,一些步骤可以跳过。执行第 15 步骤,报错:To investigate the issue, examine this stack trace。重新执行即可。进入安装应用。如图2

再次从第 4 步骤开始操作,一些步骤可以跳过。执行第 15 步骤,报错:To investigate the issue, examine this stack trace。重新执行即可。进入安装应用

图2

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ composer -V
Composer version 2.5.5 2023-03-21 11:50:05
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605/web$ composer install
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605/web$ cp .env.example .env
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605/web$ php artisan key:generate
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605/web$ php artisan migrate
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ npm run dev

> learn-php-app-ubuntu-2004-0605@1.0.0 dev
> shopify app dev


To run this command, log in to Shopify Partners.
👉 Press any key to open the login page on your browser

Auto-open timed out. Open the login page: Log in to Shopify Partners ( http://accounts.shopify.com/oauth/authorize?client_id=fbdb2649-e327-4907-8f67-908d24cfd7e3&scope=openid+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.graphql+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.themes+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.storefront-renderer.devtools+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.app.cli.access&redirect_uri=http%3A%2F%2F127.0.0.1%3A3456&state=5cba6732fe773fac2a7e9a95ddf3ab686b3a9b7231168d58f339f17dcaa1&response_type=code&code_challenge_method=S256&code_challenge=gozZ6hqQIOzwYdzxuX2RaOUgpaRz9A8gUlUoC6Wy6Vw )

✔ Logged in.

Looks like this is the first time you're running dev for this project.
Configure your preferences by answering a few questions.


Before you preview your work, it needs to be associated with an app.

?  Create this project as a new app on Shopify?
✔  Yes, create it as a new app

?  App name:
✔  learn-php-app-ubuntu-2004-0605

✔ Using your default dev store (shuijingwanwq-development) to preview your project.
╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│                                                                              │
│  To investigate the issue, examine this stack trace:                         │
│    at pollTunnelStatus (@shopify/app/src/cli/services/dev/urls.ts:106)       │
│      if (result.status === 'error') return reject(new                        │
│      BugError(result.message))                                               │
│    at (@shopify/app/src/cli/services/dev/urls.ts:120)                        │
│      pollTunnelStatus()                                                      │
│    at new Promise                                                            │
│    at pollTunnelURL (@shopify/app/src/cli/services/dev/urls.ts:101)          │
│      return new Promise<string>((resolve, reject) => {                       │
│    at generateFrontendURL (@shopify/app/src/cli/services/dev/urls.ts:89)     │
│      const url = await pollTunnelURL(options.tunnelClient)                   │
│    at dev (@shopify/app/src/cli/services/dev.ts:121)                         │
│      generateFrontendURL({                                                   │
│    at run (@shopify/app/src/cli/commands/app/dev.ts:106)                     │
│      await dev({                                                             │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ npm run dev

> learn-php-app-ubuntu-2004-0605@1.0.0 dev
> shopify app dev

╭─ info ───────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Using your previous dev settings:                                           │
│                                                                              │
│    • Org:          王强                                                      │
│    • App:          learn-php-app-ubuntu-2004-0605                            │
│    • Dev store:    shuijingwanwq-development.myshopify.com                   │
│    • Update URLs:  Not yet configured                                        │
│                                                                              │
│  To reset your default dev config, run `npm run dev -- --reset`              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

?  Have Shopify automatically update your app's URL in order to create a preview experience?
✔  Always by default

2023-06-06 01:51:12 │ frontend │
2023-06-06 01:51:12 │ frontend │ > shopify-frontend-template-react@1.0.0 dev
2023-06-06 01:51:12 │ frontend │ > vite
2023-06-06 01:51:12 │ frontend │
2023-06-06 01:51:18 │ backend  │ > Composer\Config::disableProcessTimeout
2023-06-06 01:51:18 │ backend  │ > php artisan serve
2023-06-06 01:51:20 │ frontend │
2023-06-06 01:51:20 │ frontend │   VITE v4.3.9  ready in 7780 ms
2023-06-06 01:51:20 │ frontend │
2023-06-06 01:51:20 │ frontend │   ➜  Local:   http://localhost:33597/
2023-06-06 01:51:26 │ backend  │ Starting Laravel development server: http://127.0.0.1:44681
2023-06-06 01:51:27 │ backend  │ [Tue Jun  6 09:51:26 2023] PHP 8.1.18 Development Server (http://127.0.0.1:44681) started
2023-06-06 01:51:47 │ backend  │ [Tue Jun  6 09:51:47 2023] 127.0.0.1:34304 Accepted
2023-06-06 01:51:54 │ backend  │ [Tue Jun  6 09:51:54 2023] 127.0.0.1:34304 Closing
2023-06-06 01:51:54 │ backend  │ [Tue Jun  6 09:51:54 2023] 127.0.0.1:34310 Accepted
2023-06-06 01:51:56 │ backend  │ [Tue Jun  6 09:51:56 2023] 127.0.0.1:34310 Closing
2023-06-06 01:53:17 │ backend  │ [Tue Jun  6 09:53:17 2023] 127.0.0.1:34320 Accepted
2023-06-06 01:53:22 │ backend  │ [Tue Jun  6 09:53:22 2023] 127.0.0.1:34320 Closing
2023-06-06 01:53:22 │ backend  │ [Tue Jun  6 09:53:22 2023] 127.0.0.1:34326 Accepted
2023-06-06 01:53:26 │ backend  │ [Tue Jun  6 09:53:25 2023] 127.0.0.1:34326 Closing

› Press p │ preview in your browser
› Press q │ quit

Preview URL: https://instructional-attend-excellent-gig.trycloudflare.com?shop=shuijingwanwq-development.myshopify.com&h
ost=c2h1aWppbmd3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu

18、安装应用时报错:Shopify\Exception\CookieNotFoundException Could not find the current session id in the cookies。如图3

安装应用时报错:Shopify\Exception\CookieNotFoundException Could not find the current session id in the cookies

图3

19、再次运行:npm run dev,打开浏览器,不再报错。如图4

再次运行:npm run dev,打开浏览器,不再报错

图4

]]>
https://www.shuijingwanwq.com/2023/07/01/7792/feed/ 1
使用 Shopify CLI 创建应用(基于 PHP 应用程序模板),且在商店中安装 https://www.shuijingwanwq.com/2022/10/21/7090/ https://www.shuijingwanwq.com/2022/10/21/7090/#respond Fri, 21 Oct 2022 01:39:57 +0000 https://www.shuijingwanwq.com/?p=7090 浏览量: 132

1、导航到要在其中创建应用程序的目录(E:\wwwroot\shopify-app)。您的应用程序将在一个新的子目录中创建。如图1

导航到要在其中创建应用程序的目录(E:\wwwroot\shopify-app)。您的应用程序将在一个新的子目录中创建

图1

PS E:\wwwroot\shopify-app> pwd

Path
----
E:\wwwroot\shopify-app


2、运行以下命令之一以创建新应用,然后选择要开始使用的应用模板的语言:Node、PHP 或 Ruby。选择 PHP。下图显示了在终端中成功创建的应用程序。如图2

运行以下命令之一以创建新应用,然后选择要开始使用的应用模板的语言:Node、PHP 或 Ruby。选择 PHP。下图显示了在终端中成功创建的应用程序

图2

PS E:\wwwroot\shopify-app> yarn create @shopify/app
yarn create v1.22.15
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning Your current version of Yarn is out of date. The latest version is "1.22.19", while you're on "1.22.15".
success Installed "@shopify/create-app@3.16.3" with binaries:
      - create-app

Welcome. Let’s get started by naming your app. You can change it later.
✔ Your app's name? · learn-app
✔ Which template would you like to use? · php
✔ Downloaded template from https://github.com/Shopify/shopify-app-template-php#cli_three
✔ App initialized
  ✔ Liquid parsed
  ✔ Updated package.json
✔ Dependencies installed with yarn
  ✔ Installed dependencies in /
  ✔ Installed dependencies in /web/frontend/
✔ Completed clean up
✔ Git repository initialized

  learn-app is ready for you to build! Remember to cd learn-app
  Check the setup instructions in your README file
  To preview your project, run yarn dev
  To add extensions, run yarn generate extension
  For more details on all that you can build, see the docs: shopify.dev (​https://shopify.dev​) ✨

  For help and a list of commands, enter yarn shopify app --help

Done in 1828.53s.

3、启动本地开发服务器。导航到您新创建的应用程序目录:E:\wwwroot\shopify-app\learn-app

4、设置你的 Laravel 应用。参考:https://github.com/Shopify/shopify-app-template-php/tree/cli_three#setting-up-your-laravel-app 。由于 Windows 终端中 touch 命令不可用,在 PhpStorm 中新建 storage/db.sqlite。新建路径中的数据源,驱动程序选择 SQLite,名称为 db。如图3、图4

由于 Windows 终端中 touch 命令不可用,在 PhpStorm 中新建 storage/db.sqlite。新建路径中的数据源,驱动程序选择 SQLite,名称为 db

图3

 

由于 Windows 终端中 touch 命令不可用,在 PhpStorm 中新建 storage/db.sqlite。新建路径中的数据源,驱动程序选择 SQLite,名称为 db

图4

PS E:\wwwroot\shopify-app\learn-app> cd web
PS E:\wwwroot\shopify-app\learn-app\web> ls


    目录: E:\wwwroot\shopify-app\learn-app\web


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2022/10/14     14:54                app
d-----        2022/10/14     14:54                bootstrap
d-----        2022/10/14     14:54                config
d-----        2022/10/14     14:54                database
d-----        2022/10/14     14:54                frontend
d-----        2022/10/14     14:54                public
d-----        2022/10/14     14:54                resources
d-----        2022/10/14     14:54                routes
d-----        2022/10/14     14:54                storage
-a----        2022/10/14     14:50            261 .env.example
-a----        2022/10/14     14:50            370 .env.testing
-a----        2022/10/14     14:50           1743 artisan
-a----        2022/10/14     14:50           2282 composer.json
-a----        2022/10/14     14:50            469 entrypoint.sh
-a----        2022/10/14     14:50            898 nginx.conf
-a----        2022/10/14     14:50           1233 phpunit.xml
-a----        2022/10/14     14:50            584 server.php
-a----        2022/10/14     14:50             80 shopify.web.toml


PS E:\wwwroot\shopify-app\learn-app\web> composer install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 114 installs, 0 updates, 0 removals
  - Locking brick/math (0.9.3)
  - Locking dflydev/dot-access-data (v3.0.1)
  - Locking doctrine/cache (2.2.0)
  - Locking doctrine/dbal (3.4.5)
  - Locking doctrine/deprecations (v1.0.0)
  - Locking doctrine/event-manager (1.2.0)
  - Locking doctrine/inflector (2.0.5)
  - Locking doctrine/instantiator (1.4.1)
  - Locking doctrine/lexer (1.2.3)
  - Locking dragonmantank/cron-expression (v3.3.2)
  - Locking egulias/email-validator (2.1.25)
  - Locking facade/flare-client-php (1.10.0)
  - Locking facade/ignition (2.17.6)
  - Locking facade/ignition-contracts (1.0.2)
  - Locking fakerphp/faker (v1.20.0)
  - Locking fideloper/proxy (4.4.2)
  - Locking filp/whoops (2.14.5)
  - Locking firebase/php-jwt (v5.5.1)
  - Locking fruitcake/laravel-cors (v3.0.0)
  - Locking fruitcake/php-cors (v1.2.0)
  - Locking graham-campbell/result-type (v1.1.0)
  - Locking guzzlehttp/guzzle (7.5.0)
  - Locking guzzlehttp/promises (1.5.2)
  - Locking guzzlehttp/psr7 (2.4.1)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking laravel/framework (v8.83.25)
  - Locking laravel/sail (v1.16.2)
  - Locking laravel/serializable-closure (v1.2.2)
  - Locking laravel/tinker (v2.7.2)
  - Locking league/commonmark (2.3.5)
  - Locking league/config (v1.1.1)
  - Locking league/flysystem (1.1.10)
  - Locking league/mime-type-detection (1.11.0)
  - Locking mockery/mockery (1.5.1)
  - Locking monolog/monolog (2.8.0)
  - Locking myclabs/deep-copy (1.11.0)
  - Locking nesbot/carbon (2.62.1)
  - Locking nette/schema (v1.2.2)
  - Locking nette/utils (v3.2.8)
  - Locking nikic/php-parser (v4.15.1)
  - Locking nunomaduro/collision (v5.11.0)
  - Locking opis/closure (3.6.3)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpoption/phpoption (1.9.0)
  - Locking phpunit/php-code-coverage (9.2.17)
  - Locking phpunit/php-file-iterator (3.0.6)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.5.25)
  - Locking psr/cache (1.0.1)
  - Locking psr/container (1.1.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (1.1.4)
  - Locking psr/simple-cache (1.0.1)
  - Locking psy/psysh (v0.11.8)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking ramsey/collection (1.2.2)
  - Locking ramsey/uuid (4.2.3)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.8)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.4)
  - Locking sebastian/environment (5.1.4)
  - Locking sebastian/exporter (4.0.5)
  - Locking sebastian/global-state (5.0.5)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.4)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (3.2.0)
  - Locking sebastian/version (3.0.2)
  - Locking shopify/shopify-api (v4.1.0)
  - Locking squizlabs/php_codesniffer (3.7.1)
  - Locking swiftmailer/swiftmailer (v6.3.0)
  - Locking symfony/console (v5.4.14)
  - Locking symfony/css-selector (v5.4.11)
  - Locking symfony/deprecation-contracts (v2.5.2)
  - Locking symfony/error-handler (v5.4.14)
  - Locking symfony/event-dispatcher (v5.4.9)
  - Locking symfony/event-dispatcher-contracts (v2.5.2)
  - Locking symfony/finder (v5.4.11)
  - Locking symfony/http-foundation (v5.4.14)
  - Locking symfony/http-kernel (v5.4.14)
  - Locking symfony/mime (v5.4.14)
  - Locking symfony/polyfill-ctype (v1.26.0)
  - Locking symfony/polyfill-iconv (v1.26.0)
  - Locking symfony/polyfill-intl-grapheme (v1.26.0)
  - Locking symfony/polyfill-intl-idn (v1.26.0)
  - Locking symfony/polyfill-intl-normalizer (v1.26.0)
  - Locking symfony/polyfill-mbstring (v1.26.0)
  - Locking symfony/polyfill-php72 (v1.26.0)
  - Locking symfony/polyfill-php73 (v1.26.0)
  - Locking symfony/polyfill-php80 (v1.26.0)
  - Locking symfony/polyfill-php81 (v1.26.0)
  - Locking symfony/process (v5.4.11)
  - Locking symfony/routing (v5.4.11)
  - Locking symfony/service-contracts (v2.5.2)
  - Locking symfony/string (v5.4.14)
  - Locking symfony/translation (v5.4.14)
  - Locking symfony/translation-contracts (v2.5.2)
  - Locking symfony/var-dumper (v5.4.14)
  - Locking theseer/tokenizer (1.2.1)
  - Locking tijsverkoyen/css-to-inline-styles (2.2.5)
  - Locking vlucas/phpdotenv (v5.4.1)
  - Locking voku/portable-ascii (1.6.1)
  - Locking webmozart/assert (1.11.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 114 installs, 0 updates, 0 removals
  - Downloading brick/math (0.9.3)
  - Downloading psr/log (1.1.4)
  - Downloading psr/cache (1.0.1)
  - Downloading doctrine/event-manager (1.2.0)
  - Downloading doctrine/dbal (3.4.5)
  - Downloading symfony/polyfill-ctype (v1.26.0)
  - Downloading webmozart/assert (1.11.0)
  - Downloading dragonmantank/cron-expression (v3.3.2)
  - Downloading symfony/polyfill-php80 (v1.26.0)
  - Downloading symfony/polyfill-mbstring (v1.26.0)
  - Downloading symfony/var-dumper (v5.4.14)
  - Downloading symfony/polyfill-intl-normalizer (v1.26.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.26.0)
  - Downloading symfony/string (v5.4.14)
  - Downloading psr/container (1.1.2)
  - Downloading symfony/service-contracts (v2.5.2)
  - Downloading symfony/polyfill-php73 (v1.26.0)
  - Downloading symfony/console (v5.4.14)
  - Downloading monolog/monolog (2.8.0)
  - Downloading voku/portable-ascii (1.6.1)
  - Downloading vlucas/phpdotenv (v5.4.1)
  - Downloading symfony/css-selector (v5.4.11)
  - Downloading symfony/routing (v5.4.11)
  - Downloading symfony/process (v5.4.11)
  - Downloading symfony/polyfill-php72 (v1.26.0)
  - Downloading symfony/polyfill-intl-idn (v1.26.0)
  - Downloading symfony/mime (v5.4.14)
  - Downloading symfony/http-foundation (v5.4.14)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v2.5.2)
  - Downloading symfony/event-dispatcher (v5.4.9)
  - Downloading symfony/error-handler (v5.4.14)
  - Downloading symfony/http-kernel (v5.4.14)
  - Downloading symfony/finder (v5.4.11)
  - Downloading symfony/polyfill-iconv (v1.26.0)
  - Downloading egulias/email-validator (2.1.25)
  - Downloading swiftmailer/swiftmailer (v6.3.0)
  - Downloading symfony/polyfill-php81 (v1.26.0)
  - Downloading ramsey/collection (1.2.2)
  - Downloading ramsey/uuid (4.2.3)
  - Downloading psr/simple-cache (1.0.1)
  - Downloading symfony/translation-contracts (v2.5.2)
  - Downloading symfony/translation (v5.4.14)
  - Downloading league/flysystem (1.1.10)
  - Downloading nette/utils (v3.2.8)
  - Downloading nette/schema (v1.2.2)
  - Downloading dflydev/dot-access-data (v3.0.1)
  - Downloading league/config (v1.1.1)
  - Downloading laravel/serializable-closure (v1.2.2)
  - Downloading laravel/framework (v8.83.25)
  - Downloading facade/ignition-contracts (1.0.2)
  - Downloading facade/flare-client-php (1.10.0)
  - Downloading facade/ignition (2.17.6)
  - Downloading fideloper/proxy (4.4.2)
  - Downloading fruitcake/php-cors (v1.2.0)
  - Downloading fruitcake/laravel-cors (v3.0.0)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-message (1.0.1)
  - Downloading psr/http-factory (1.0.1)
  - Downloading guzzlehttp/psr7 (2.4.1)
  - Downloading laravel/sail (v1.16.2)
  - Downloading psy/psysh (v0.11.8)
  - Downloading laravel/tinker (v2.7.2)
  - Downloading mockery/mockery (1.5.1)
  - Downloading nunomaduro/collision (v5.11.0)
  - Downloading sebastian/version (3.0.2)
  - Downloading sebastian/type (3.2.0)
  - Downloading sebastian/resource-operations (3.0.3)
  - Downloading sebastian/recursion-context (4.0.4)
  - Downloading sebastian/object-reflector (2.0.4)
  - Downloading sebastian/object-enumerator (4.0.4)
  - Downloading sebastian/global-state (5.0.5)
  - Downloading sebastian/exporter (4.0.5)
  - Downloading sebastian/environment (5.1.4)
  - Downloading sebastian/diff (4.0.4)
  - Downloading sebastian/comparator (4.0.8)
  - Downloading sebastian/code-unit (1.0.8)
  - Downloading sebastian/cli-parser (1.0.1)
  - Downloading phpunit/php-timer (5.0.3)
  - Downloading phpunit/php-text-template (2.0.4)
  - Downloading phpunit/php-invoker (3.1.1)
  - Downloading phpunit/php-file-iterator (3.0.6)
  - Downloading sebastian/lines-of-code (1.0.3)
  - Downloading sebastian/complexity (2.0.2)
  - Downloading sebastian/code-unit-reverse-lookup (2.0.3)
  - Downloading phpunit/php-code-coverage (9.2.17)
  - Downloading phar-io/version (3.2.1)
  - Downloading phar-io/manifest (2.0.3)
  - Downloading phpunit/phpunit (9.5.25)
  - Downloading psr/http-client (1.0.1)
  - Downloading guzzlehttp/guzzle (7.5.0)
  - Downloading firebase/php-jwt (v5.5.1)
  - Downloading shopify/shopify-api (v4.1.0)
  - Installing brick/math (0.9.3): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing psr/cache (1.0.1): Extracting archive
  - Installing doctrine/deprecations (v1.0.0): Extracting archive
  - Installing doctrine/event-manager (1.2.0): Extracting archive
  - Installing doctrine/cache (2.2.0): Extracting archive
  - Installing doctrine/dbal (3.4.5): Extracting archive
  - Installing doctrine/lexer (1.2.3): Extracting archive
  - Installing symfony/polyfill-ctype (v1.26.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.2): Extracting archive
  - Installing symfony/polyfill-php80 (v1.26.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.26.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.14): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.26.0): Extracting archive
  - Installing symfony/string (v5.4.14): Extracting archive
  - Installing symfony/deprecation-contracts (v2.5.2): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.2): Extracting archive
  - Installing symfony/polyfill-php73 (v1.26.0): Extracting archive
  - Installing symfony/console (v5.4.14): Extracting archive
  - Installing monolog/monolog (2.8.0): Extracting archive
  - Installing voku/portable-ascii (1.6.1): Extracting archive
  - Installing phpoption/phpoption (1.9.0): Extracting archive
  - Installing graham-campbell/result-type (v1.1.0): Extracting archive
  - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
  - Installing symfony/css-selector (v5.4.11): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.5): Extracting archive
  - Installing symfony/routing (v5.4.11): Extracting archive
  - Installing symfony/process (v5.4.11): Extracting archive
  - Installing symfony/polyfill-php72 (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.26.0): Extracting archive
  - Installing symfony/mime (v5.4.14): Extracting archive
  - Installing symfony/http-foundation (v5.4.14): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v2.5.2): Extracting archive
  - Installing symfony/event-dispatcher (v5.4.9): Extracting archive
  - Installing symfony/error-handler (v5.4.14): Extracting archive
  - Installing symfony/http-kernel (v5.4.14): Extracting archive
  - Installing symfony/finder (v5.4.11): Extracting archive
  - Installing symfony/polyfill-iconv (v1.26.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
  - Installing symfony/polyfill-php81 (v1.26.0): Extracting archive
  - Installing ramsey/collection (1.2.2): Extracting archive
  - Installing ramsey/uuid (4.2.3): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.3): Extracting archive
  - Installing symfony/translation-contracts (v2.5.2): Extracting archive
  - Installing symfony/translation (v5.4.14): Extracting archive
  - Installing nesbot/carbon (2.62.1): Extracting archive
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Installing league/flysystem (1.1.10): Extracting archive
  - Installing nette/utils (v3.2.8): Extracting archive
  - Installing nette/schema (v1.2.2): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
  - Installing league/config (v1.1.1): Extracting archive
  - Installing league/commonmark (2.3.5): Extracting archive
  - Installing laravel/serializable-closure (v1.2.2): Extracting archive
  - Installing doctrine/inflector (2.0.5): Extracting archive
  - Installing laravel/framework (v8.83.25): Extracting archive
  - Installing facade/ignition-contracts (1.0.2): Extracting archive
  - Installing facade/flare-client-php (1.10.0): Extracting archive
  - Installing facade/ignition (2.17.6): Extracting archive
  - Installing fakerphp/faker (v1.20.0): Extracting archive
  - Installing fideloper/proxy (4.4.2): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing fruitcake/laravel-cors (v3.0.0): Extracting archive
  - Installing guzzlehttp/promises (1.5.2): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-message (1.0.1): Extracting archive
  - Installing psr/http-factory (1.0.1): Extracting archive
  - Installing guzzlehttp/psr7 (2.4.1): Extracting archive
  - Installing laravel/sail (v1.16.2): Extracting archive
  - Installing nikic/php-parser (v4.15.1): Extracting archive
  - Installing psy/psysh (v0.11.8): Extracting archive
  - Installing laravel/tinker (v2.7.2): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.5.1): Extracting archive
  - Installing filp/whoops (2.14.5): Extracting archive
  - Installing nunomaduro/collision (v5.11.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.0): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.4): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.5): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.4): Extracting archive
  - Installing sebastian/diff (4.0.4): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.17): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.0): Extracting archive
  - Installing doctrine/instantiator (1.4.1): Extracting archive
  - Installing phpunit/phpunit (9.5.25): Extracting archive
  - Installing psr/http-client (1.0.1): Extracting archive
  - Installing guzzlehttp/guzzle (7.5.0): Extracting archive
  - Installing firebase/php-jwt (v5.5.1): Extracting archive
  - Installing shopify/shopify-api (v4.1.0): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.1): Extracting archive
68 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PS E:\wwwroot\shopify-app\learn-app\web> ls


    目录: E:\wwwroot\shopify-app\learn-app\web


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2022/10/14     14:54                bootstrap
d-----        2022/10/14     14:54                database
d-----        2022/10/14     14:54                frontend
d-----        2022/10/14     14:54                public
d-----        2022/10/14     14:54                resources
d-----        2022/10/14     14:54                routes
d-----        2022/10/14     14:54                storage
d-----        2022/10/14     15:26                vendor
-a----        2022/10/14     14:50            261 .env
-a----        2022/10/14     14:50            261 .env.example
-a----        2022/10/14     14:50            370 .env.testing
-a----        2022/10/14     14:50           1743 artisan
-a----        2022/10/14     14:50           2282 composer.json
-a----        2022/10/14     15:26         303790 composer.lock
-a----        2022/10/14     14:50            469 entrypoint.sh
-a----        2022/10/14     14:50            898 nginx.conf
-a----        2022/10/14     14:50           1233 phpunit.xml
-a----        2022/10/14     14:50            584 server.php
-a----        2022/10/14     14:50             80 shopify.web.toml


PS E:\wwwroot\shopify-app\learn-app\web> touch storage/db.sqlite
touch : 无法将“touch”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 行:1 字符: 1
+ touch storage/db.sqlite
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (touch:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS E:\wwwroot\shopify-app\learn-app\web> php artisan key:generate
PS E:\wwwroot\shopify-app\learn-app\web> ls


    目录: E:\wwwroot\shopify-app\learn-app\web


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2022/10/14     14:54                app
d-----        2022/10/14     14:54                bootstrap
d-----        2022/10/14     14:54                config
d-----        2022/10/14     14:54                database
d-----        2022/10/14     14:54                frontend
d-----        2022/10/14     14:54                public
d-----        2022/10/14     14:54                resources
d-----        2022/10/14     14:54                routes
d-----        2022/10/14     15:42                storage
d-----        2022/10/14     15:26                vendor
-a----        2022/10/14     15:44            337 .env
-a----        2022/10/14     14:50            261 .env.example
-a----        2022/10/14     14:50            370 .env.testing
-a----        2022/10/14     14:50           1743 artisan
-a----        2022/10/14     14:50           2282 composer.json
-a----        2022/10/14     15:26         303790 composer.lock
-a----        2022/10/14     14:50            469 entrypoint.sh
-a----        2022/10/14     14:50            898 nginx.conf
-a----        2022/10/14     14:50           1233 phpunit.xml
-a----        2022/10/14     14:50            584 server.php
-a----        2022/10/14     14:50             80 shopify.web.toml


5、在您的数据库中创建必要的 Shopify 表,报错:Illuminate\Database\QueryException could not find driver (SQL: PRAGMA foreign_keys = ON;)。如图5

在您的数据库中创建必要的 Shopify 表,报错:Illuminate\Database\QueryException  could not find driver (SQL: PRAGMA foreign_keys = ON;)

图5

PS E:\wwwroot\shopify-app\learn-app\web> php artisan migrate

   Illuminate\Database\QueryException

  could not find driver (SQL: PRAGMA foreign_keys = ON;)

  at E:\wwwroot\shopify-app\learn-app\web\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

  1   E:\wwwroot\shopify-app\learn-app\web\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("could not find driver")

  2   E:\wwwroot\shopify-app\learn-app\web\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("sqlite:E:\wwwroot\shopify-app\learn-app\web\storage\db.sqlite", [])
PS E:\wwwroot\shopify-app\learn-app\web>

6、编辑 php.ini,extension=pdo_sqlite。重启 PHP 。查看数据库,表新建成功。如图6

编辑 php.ini,extension=pdo_sqlite。重启 PHP 。查看数据库,表新建成功

图6

PS E:\wwwroot\shopify-app\learn-app\web> php artisan migrate
Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (249.14ms)
Migrating: 2021_05_03_050717_create_sessions_table
Migrated:  2021_05_03_050717_create_sessions_table (188.38ms)
Migrating: 2021_05_05_071311_add_scope_expires_access_token_to_sessions
Migrated:  2021_05_05_071311_add_scope_expires_access_token_to_sessions (315.43ms)
Migrating: 2021_05_11_151158_add_online_access_info_to_sessions
Migrated:  2021_05_11_151158_add_online_access_info_to_sessions (822.19ms)
Migrating: 2021_05_17_152611_change_sessions_user_id_type
Migrated:  2021_05_17_152611_change_sessions_user_id_type (1,303.13ms)
PS E:\wwwroot\shopify-app\learn-app\web>

7、要为您的应用启动本地服务器,请运行以下命令。如图7

要为您的应用启动本地服务器,请运行以下命令

图7

PS E:\wwwroot\shopify-app\learn-app> yarn dev
yarn run v1.22.15
$ shopify app dev
✔ Dependencies installed

To run this command, log in to Shopify Partners.
👉 Press any key to open the login page on your browser
✔ Logged in.

Looks like this is the first time you're running dev for this project.
Configure your preferences by answering a few questions.

✔ App Name · learn-app
✅ Success! learn-app has been created on your Partners account.
✔ Using your default dev store (shuijingwanwq-development) to preview your project.
✅ Success! Converted shuijingwanwq-development.myshopify.com to a Test store.

To make your local code accessible to your dev store, you need to use a Shopify-trusted tunneling service called ngrok. To sign up and get an auth token: https://dashboard.ngrok.com/get-started/your-authtoken (​https://dashboard.ngrok.com/get-started/your-authtoken​)

✔ Enter your ngrok token. · *************************************************
✅ Success! The tunnel is running and you can now view your app.

For your convenience, we've given your app a default URL: https://4a94-66-175-216-239.ngrok.io.

You can update your app's URL anytime in the Partners Dashboard (​https://partners.shopify.com/2442779/apps/12958171137/edit​). But once your app is live, updating its URL will disrupt merchant access.


Shareable app URL

  https://4a94-66-175-216-239.ngrok.io?shop=shuijingwanwq-development.myshopify.com&host=c2h1aWppbmd3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu

frontend |
frontend | > dev
frontend | > vite
frontend |
frontend |
frontend |   vite v2.9.15 dev server running at:
frontend |
frontend |   > Network:  http://192.168.56.1:57522/
frontend |   > Network:  http://192.168.10.1:57522/
frontend |   > Network:  http://192.168.89.86:57522/
frontend |   > Local:    http://localhost:57522/
frontend |   > Network:  http://172.17.176.1:57522/
frontend |
frontend |   ready in 2602ms.
frontend |
backend  | > Composer\Config::disableProcessTimeout
backend  | > php artisan serve
backend  | Starting Laravel development server: http://127.0.0.1:57518
backend  | [Fri Oct 14 16:52:21 2022] PHP 7.4.27 Development Server (http://127.0.0.1:57518) started

8、期间需要输入 ngrok 的 Authtoken。如图8

期间需要输入 ngrok 的 Authtoken

图8

9、启动 Laravel 开发服务器:http://127.0.0.1:57518 。在浏览器中打开。报错:Argument 1 passed to Shopify\Utils::sanitizeShopDomain() must be of the type string, null given, called in E:\wwwroot\shopify-app\learn-app\web\app\Lib\AuthRedirection.php on line 17 。原因在于未在网址中带上参数:shop。如图9

启动 Laravel 开发服务器:http://127.0.0.1:57518 。在浏览器中打开。报错:Argument 1 passed to Shopify\Utils::sanitizeShopDomain() must be of the type string, null given, called in E:\wwwroot\shopify-app\learn-app\web\app\Lib\AuthRedirection.php on line 17 。原因在于未在网址中带上参数:shop

图9

10、在开发商店中安装您的应用。打开 Shareable app URL:https://4a94-66-175-216-239.ngrok.io?shop=shuijingwanwq-development.myshopify.com&host=c2h1aWppbmd3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu 。打开 URL 时,系统会提示您在开发商店中安装应用程序。单击安装应用程序以在商店中安装应用程序。如图10

在开发商店中安装您的应用。打开 Shareable app URL:https://4a94-66-175-216-239.ngrok.io?shop=shuijingwanwq-development.myshopify.com&host=c2h1aWppbmd3YW53cS1kZXZlbG9wbWVudC5teXNob3BpZnkuY29tL2FkbWlu 。打开 URL 时,系统会提示您在开发商店中安装应用程序。单击安装应用程序以在商店中安装应用程序

图10

11、安装过程中报错:Shopify\Exception\CookieNotFoundException Could not find the current session id in the cookies。如图11

安装过程中报错:Shopify\Exception\CookieNotFoundException Could not find the current session id in the cookies

图11

12、重新从第 7 步骤开始执行,跳过第 9 步骤。您现在有一个安装了新应用程序的开发商店。如图12

重新从第 7 步骤开始执行,跳过第 9 步骤。您现在有一个安装了新应用程序的开发商店

图12

]]>
https://www.shuijingwanwq.com/2022/10/21/7090/feed/ 0
在 Laravel 6、LightHouse 5、Module 中使用 @rules 指令时,应用 exists 规则时的本地化实现 https://www.shuijingwanwq.com/2022/04/29/6354/ https://www.shuijingwanwq.com/2022/04/29/6354/#respond Fri, 29 Apr 2022 01:12:38 +0000 https://www.shuijingwanwq.com/?p=6354 浏览量: 105 1、当语言区域为 en 时,当验证的参数不存在时,响应:The selected theme id is invalid.。如图1
当语言区域为 en 时,当验证的参数不存在时,响应:The selected theme id is invalid.

图1



{
  "errors": [
    {
      "message": "Validation failed for the field [onlineStoreThemeEditorSessionCreate].",
      "extensions": {
        "validation": {
          "themeId": [
            "The selected theme id is invalid."
          ]
        },
        "category": "validation"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "onlineStoreThemeEditorSessionCreate"
      ],
      "trace": ...
    }
  ],
  "data": {
    "onlineStoreThemeEditorSessionCreate": null
  }
}


2、当语言区域为 zh_CN 时,当验证的参数不存在时,响应:所选的theme id无效。预期为:所选的主题ID无效。如图2
当语言区域为 zh_CN 时,当验证的参数不存在时,响应:所选的theme id无效。预期为:所选的主题ID无效。

图2



{
  "errors": [
    {
      "message": "Validation failed for the field [onlineStoreThemeEditorSessionCreate].",
      "extensions": {
        "validation": {
          "themeId": [
            "所选的theme id无效。"
          ]
        },
        "category": "validation"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "onlineStoreThemeEditorSessionCreate"
      ],
      "trace": ...
    }
  ],
  "data": {
    "onlineStoreThemeEditorSessionCreate": null
  }
}


3、查看 GraphQL 代码实现,/Modules/ThemeStore/Resources/graphql/theme_editor.graphql


extend type Mutation {
    "创建主题编辑会话"
    onlineStoreThemeEditorSessionCreate(themeId: ID! @rules(apply: ["exists:theme_asset,theme_id"])): ThemeEditorSessionCreatePayload @field(resolver: "Modules\\ThemeStore\\Resolver\\ThemeEditor\\CreateThemeEditorSessionResolver")
}

type ThemeEditorSessionCreatePayload
{
    "会话"
    session: Session!
}




4、查看 语言文件 ,/Modules/ThemeStore/Resources/lang/zh_CN/validation.php,已经指定了 theme_id 的自定义属性名称,但是,并未生效
<pre class="wp-block-syntaxhighlighter-code">

<?php

return [

    'attributes' => [
        'theme_id' => '主题ID',
    ],
];


</pre>
5、即使将此配置放至语言文件 /resources/lang/zh_CN/validation.php 中,仍然未生效,响应:所选的theme_id无效。但是,其默认是使用的此语言文件的配置。将验证规则消息放在任何语言的 validation.php 中名为 attributes 的键中,验证消息的 :attribute 部分不会被翻译(模块上下文)。
<pre class="wp-block-syntaxhighlighter-code">

<?php

return [

	'exists' => '所选的:attribute无效。',

    'attributes' => [
        'theme_id' => '主题ID',
    ],
];


</pre>
6、在 Laravel v8.7.90、nwidart/laravel-modules 8.2.0 中,编辑 /resources/lang/zh_CN/validation.php ,attributes 会生效。


    /**
     * 显示创建博客文章的表单
     *
     * @return Response
     */
    public function create(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'theme_id' => 'required|exists:users,id',
        ]);

        if ($validator->fails()) {
            dd($validator->errors());
        }

        // 保存博客文章…

        return view('blog::post.create');
    }


<pre class="wp-block-syntaxhighlighter-code">

<?php
return [
    'exists' => '所选的:attribute无效。resources',

    'attributes' => [
        'theme_id' => '主题ID',
    ],
];


</pre>


Illuminate\Support\MessageBag {#361 ▼
  #messages: array:1 [▼
    "theme_id" => array:1 [▼
      0 => "所选的主题ID无效。resources"
    ]
  ]
  #format: ":message"
}


7、决定在当前版本:Laravel v6.20.43、nwidart/laravel-modules 7.3.0 中,模拟步骤6的实现。以确定是否与框架、模块包的版本有关,进而导致在应用的根目录中,attributes 不生效的问题。确定是无关的。那么原因在于 LightHouse 5。
<pre class="wp-block-syntaxhighlighter-code">

<?php
return [
    'array' => ':attribute必须是一个数组。',

    'attributes' => [
        'filter' => '过滤器'
    ],
];


</pre>


{
  "message": "The given data was invalid.",
  "errors": {
    "filter": [
      "过滤器必须是一个数组。"
    ]
  },
  "status_code": 422,
  "debug": {
    "line": 385,
    "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Validation\\Validator.php",
    "class": "Illuminate\\Validation\\ValidationException",
    "trace": ...
  }
}


8、参考:https://github.com/nuwave/lighthouse/issues/1773 ,虽然已经在 @rules 指令上实现了翻译功能,但是实现得不够彻底。即验证属性未支持。开发者建议:https://lighthouse-php.com/master/security/validation.html#validator-classes 。支持通过任意 PHP 代码定义规则。 9、暂时不准备编写一个自定义规则。决定在非英语环境下,属性名未翻译为对应的语言,暂且接受。且语言文件在根目录下,不在对应的模块目录下。  ]]>
https://www.shuijingwanwq.com/2022/04/29/6354/feed/ 0
Laravel 8.x(LaraBBS) 部署至 阿里云 ECS,基于 MySQL、Redis、Supervisor、Crontab 实现 https://www.shuijingwanwq.com/2022/01/28/5867/ https://www.shuijingwanwq.com/2022/01/28/5867/#respond Fri, 28 Jan 2022 09:14:42 +0000 https://www.shuijingwanwq.com/?p=5867 浏览量: 200 1、Laravel 8.x(LaraBBS) 在本地开发环境已经实现。如图1
Laravel 8.x(LaraBBS) 在本地开发环境已经实现

图1

2、基于 Xshell 7,登录至 阿里云 ECS。查看操作系统版本。列出所有版本信息,执行命令:lsb_release -a。版本:CentOS 7.7。如图2
基于 Xshell 7,登录至 阿里云 ECS。查看操作系统版本。列出所有版本信息,执行命令:lsb_release -a。版本:CentOS 7.7

图2



[root@iZ23wv7v5ggZ ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.7.1908 (Core)
Release:	7.7.1908
Codename:	Core



3、参考网址:https://oneinstack.com/ ,基于 OneinStack 来部署。由于此 ECS 中之前已经基于 OneinStack 部署过网站。因此,一些步骤会跳过。事先将云盘创建快照备份,以防万一造成数据损失。如图3
参考网址:https://oneinstack.com/ ,基于 OneinStack 来部署。由于此 ECS 中之前已经基于 OneinStack 部署过网站。因此,一些步骤会跳过。事先将云盘创建快照备份,以防万一造成数据损失

图3

4、建议在快照进度等于 100%,即状态成功后,才开始操作 ECS。如图4
建议在快照进度等于 100%,即状态成功后,才开始操作 ECS

图4

5、在 ECS 上已经部署成功的网址:https://www.shuijingwanwq.com/ 。参考网址:https://www.shuijingwanwq.com/2016/04/25/1050/ 6、目录:/root/oneinstack 早已经存在。如图5
目录:/root/oneinstack 早已经存在

图5

7、查看当前的 PHP 版本:7.4。如图6
查看当前的 PHP 版本:7.4

图6



[root@iZ23wv7v5ggZ oneinstack]# php -v
PHP 7.4.0 (cli) (built: Dec  5 2019 11:56:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies


8、升级脚本工具,不影响正在运行环境。执行命令:/upgrade.sh –oneinstack。如图7
升级脚本工具,不影响正在运行环境。执行命令:/upgrade.sh --oneinstack。

图7



[root@iZ23wv7v5ggZ oneinstack]# ./upgrade.sh --oneinstack

#######################################################################
#       OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+      #
#              Upgrade Software versions for OneinStack               #
#       For more information please visit https://oneinstack.com      #
#######################################################################

Congratulations! OneinStack upgrade successful! 

[root@iZ23wv7v5ggZ oneinstack]# 



9、参考网址:https://oneinstack.com/install/ ,添加虚拟主机,执行命令:./vhost.sh。报错:Error: Create Let’s Encrypt SSL Certificate failed! 。原因在于不存在相应的 DNS 记录。如图8
参考网址:https://oneinstack.com/install/ ,添加虚拟主机,执行命令:./vhost.sh。报错:Error: Create Let's Encrypt SSL Certificate failed! 。原因在于不存在相应的 DNS 记录

图8



[root@iZ23wv7v5ggZ oneinstack]# ./vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 8+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
	1. Use HTTP Only
	2. Use your own SSL Certificate and Key
	3. Use Let's Encrypt to Create SSL Certificate and Key
	q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): app-wangqiang-larabbs.shuijingwanwq.com
domain=app-wangqiang-larabbs.shuijingwanwq.com

Please input the directory for the domain:app-wangqiang-larabbs.shuijingwanwq.com :
(Default directory: /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com): 
Virtual Host Directory=/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please enter your email: shuijingwanwq@163.com

[Fri Jan  7 10:36:05 CST 2022] Unknown parameter : -m

Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for app-wangqiang-larabbs.shuijingwanwq.com
[Fri Jan  7 10:36:10 CST 2022] Creating domain key
[Fri Jan  7 10:36:10 CST 2022] The domain key is here: /root/.acme.sh/app-wangqiang-larabbs.shuijingwanwq.com/app-wangqiang-larabbs.shuijingwanwq.com.key
[Fri Jan  7 10:36:10 CST 2022] Single domain='app-wangqiang-larabbs.shuijingwanwq.com'
[Fri Jan  7 10:36:10 CST 2022] Getting domain auth token for each domain
[Fri Jan  7 10:36:14 CST 2022] Getting webroot for domain='app-wangqiang-larabbs.shuijingwanwq.com'
[Fri Jan  7 10:36:15 CST 2022] Verifying: app-wangqiang-larabbs.shuijingwanwq.com
[Fri Jan  7 10:36:19 CST 2022] app-wangqiang-larabbs.shuijingwanwq.com:Verify error:DNS problem: NXDOMAIN looking up A for app-wangqiang-larabbs.shuijingwanwq.com - check that a DNS record exists for this domain
[Fri Jan  7 10:36:19 CST 2022] Please add '--debug' or '--log' to check more details.
[Fri Jan  7 10:36:19 CST 2022] See: https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh
Error: Create Let's Encrypt SSL Certificate failed! 
[root@iZ23wv7v5ggZ oneinstack]# 



10、检查此域是否存在 DNS 记录。先在 DNS 中添加相应的域名:app-wangqiang-larabbs.shuijingwanwq.com 。如图9
检查此域是否存在 DNS 记录。先在 DNS 中添加相应的域名:app-wangqiang-larabbs.shuijingwanwq.com

图9

11、再次执行命令:./vhost.sh。添加虚拟主机成功。如图10
再次执行命令:./vhost.sh。添加虚拟主机成功

图10



[root@iZ23wv7v5ggZ oneinstack]# ./vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 8+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
	1. Use HTTP Only
	2. Use your own SSL Certificate and Key
	3. Use Let's Encrypt to Create SSL Certificate and Key
	q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): app-wangqiang-larabbs.shuijingwanwq.com
domain=app-wangqiang-larabbs.shuijingwanwq.com

Please input the directory for the domain:app-wangqiang-larabbs.shuijingwanwq.com :
(Default directory: /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com): 
Virtual Host Directory=/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please enter your email: shuijingwanwq@163.com

[Fri Jan  7 10:48:20 CST 2022] Unknown parameter : -m
[Fri Jan  7 10:48:24 CST 2022] Single domain='app-wangqiang-larabbs.shuijingwanwq.com'
[Fri Jan  7 10:48:24 CST 2022] Getting domain auth token for each domain
[Fri Jan  7 10:48:29 CST 2022] Getting webroot for domain='app-wangqiang-larabbs.shuijingwanwq.com'
[Fri Jan  7 10:48:29 CST 2022] Verifying: app-wangqiang-larabbs.shuijingwanwq.com
[Fri Jan  7 10:48:34 CST 2022] Success
[Fri Jan  7 10:48:34 CST 2022] Verify finished, start to sign.
[Fri Jan  7 10:48:34 CST 2022] Lets finalize the order, Le_OrderFinalize: https://acme-v02.api.letsencrypt.org/acme/finalize/73156074/53280741960
[Fri Jan  7 10:48:37 CST 2022] Download cert, Le_LinkCert: https://acme-v02.api.letsencrypt.org/acme/cert/04ed99c0b6706b74ad4a5a19389500b0add1
[Fri Jan  7 10:48:38 CST 2022] Cert success.
-----BEGIN CERTIFICATE-----
xxxxxxxxxx
-----END CERTIFICATE-----
[Fri Jan  7 10:48:38 CST 2022] Your cert is in  /root/.acme.sh/app-wangqiang-larabbs.shuijingwanwq.com/app-wangqiang-larabbs.shuijingwanwq.com.cer 
[Fri Jan  7 10:48:38 CST 2022] Your cert key is in  /root/.acme.sh/app-wangqiang-larabbs.shuijingwanwq.com/app-wangqiang-larabbs.shuijingwanwq.com.key 
[Fri Jan  7 10:48:39 CST 2022] The intermediate CA cert is in  /root/.acme.sh/app-wangqiang-larabbs.shuijingwanwq.com/ca.cer 
[Fri Jan  7 10:48:39 CST 2022] And the full chain certs is there:  /root/.acme.sh/app-wangqiang-larabbs.shuijingwanwq.com/fullchain.cer 

Do you want to add hotlink protection? [y/n]: y

Allow Rewrite rule? [y/n]: y

Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,codeigniter,laravel
thinkphp,pathinfo,discuz,typecho,ecshop,nextcloud,zblog,whmcs rewrite was exist.
(Default rewrite: other): laravel
You choose rewrite=laravel

Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
You access log file=/data/wwwlogs/app-wangqiang-larabbs.shuijingwanwq.com_nginx.log

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 8+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################
Your domain:                  app-wangqiang-larabbs.shuijingwanwq.com
Virtualhost conf:             /usr/local/nginx/conf/vhost/app-wangqiang-larabbs.shuijingwanwq.com.conf
Directory of:                 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com
Rewrite rule:                 /usr/local/nginx/conf/rewrite/laravel.conf
Let's Encrypt SSL Certificate:/usr/local/nginx/conf/ssl/app-wangqiang-larabbs.shuijingwanwq.com.crt
SSL Private Key:              /usr/local/nginx/conf/ssl/app-wangqiang-larabbs.shuijingwanwq.com.key
[root@iZ23wv7v5ggZ oneinstack]# ^C
[root@iZ23wv7v5ggZ oneinstack]# 



12、管理FTP账号,执行命令:./pureftpd_vhost.sh 。如图11
管理FTP账号,执行命令:./pureftpd_vhost.sh

图11



[root@iZ23wv7v5ggZ oneinstack]# ./pureftpd_vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 8+ and Ubuntu 16+      #
#                 FTP virtual user account management                 #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
	1. UserAdd
	2. UserMod
	3. UserPasswd
	4. UserDel
	5. ListAllUser
	6. ShowUser
	q. Exit
Please input the correct option: 1

Please input a username: app-wangqiang-larabbs.shuijingwanwq.com

Please input the password: s0etwJ9DGm3e6CwP

Please input the directory(Default directory: /data/wwwroot): /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com
Password: 
Enter it again: 
#####################################

[app-wangqiang-larabbs.shuijingwanwq.com] create successful! 

You user name is : app-wangqiang-larabbs.shuijingwanwq.com
You Password is : xxxxxxxxxx
You directory is : /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com


What Are You Doing?
	1. UserAdd
	2. UserMod
	3. UserPasswd
	4. UserDel
	5. ListAllUser
	6. ShowUser
	q. Exit
Please input the correct option: q
[root@iZ23wv7v5ggZ oneinstack]# 



13、打开 FlashFXP,通过 FTP 上传源代码至 目录:/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com 。如图12
打开 FlashFXP,通过 FTP 上传源代码至 目录:/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com

图12

14、登录阿里云 RDS 控制台,创建数据库:app_wangqiang_larabbs,且授权帐号:app_wangqiang_larabbs。如图13
登录阿里云 RDS 控制台,创建数据库:app_wangqiang_larabbs,且授权帐号:app_wangqiang_larabbs

图13

15、登录 RDS 实例后,已经存在数据库:app_wangqiang_larabbs。如图14
登录 RDS 实例后,已经存在数据库:app_wangqiang_larabbs

图14

16、编辑虚拟主机配置文件:/usr/local/nginx/conf/vhost/app-wangqiang-larabbs.shuijingwanwq.com.conf 。网站根目录添加 /public。然后重启 Nginx 服务,执行命令:service nginx restart。如图15
编辑虚拟主机配置文件:/usr/local/nginx/conf/vhost/app-wangqiang-larabbs.shuijingwanwq.com.conf 。网站根目录添加 /public。然后重启 Nginx 服务,执行命令:service nginx restart

图15



[root@iZ23wv7v5ggZ oneinstack]# cat /usr/local/nginx/conf/vhost/app-wangqiang-larabbs.shuijingwanwq.com.conf
server {
  listen 80;
  listen 443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/app-wangqiang-larabbs.shuijingwanwq.com.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/app-wangqiang-larabbs.shuijingwanwq.com.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name app-wangqiang-larabbs.shuijingwanwq.com;
  access_log /data/wwwlogs/app-wangqiang-larabbs.shuijingwanwq.com_nginx.log combined;
  index index.html index.htm index.php;
  root /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/public;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
  
  include /usr/local/nginx/conf/rewrite/laravel.conf;
  #error_page 404 /404.html;
  #error_page 502 /502.html;
  location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
    valid_referers none blocked *.shuijingwanwq.com app-wangqiang-larabbs.shuijingwanwq.com;
    if ($invalid_referer) {
        return 403;
    }
  }
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    deny all;
  }
  location /.well-known {
    allow all;
  }
}
[root@iZ23wv7v5ggZ oneinstack]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service



17、查看 Laravel 的伪静态配置文件,/usr/local/nginx/conf/rewrite/laravel.conf


[root@iZ23wv7v5ggZ oneinstack]# cat /usr/local/nginx/conf/rewrite/laravel.conf
location / {
  try_files $uri $uri/ /index.php?$query_string;
}
[root@iZ23wv7v5ggZ oneinstack]# 


18、第 13 步骤完成后,设置 Laravel 目录权限。参考网址:https://learnku.com/laravel/t/62112 。www 是我的 web 服务的 用户与用户组。目录设置为 755,所有的文件设置为 644。权限方面,已经被 OneinStack 自动设置好了的。因此,像目录:/bootstrap/cache、/storage、/public/uploads,皆无需要再设置额外的权限。如图16
第 13 步骤完成后,设置 Laravel 目录权限。参考网址:https://learnku.com/laravel/t/62112 。www 是我的 web 服务的 用户与用户组。目录设置为 755,所有的文件设置为 644。权限方面,已经被 OneinStack 自动设置好了的。因此,像目录:/bootstrap/cache、/storage、/public/uploads,皆无需要再设置额外的权限

图16

19、在 ECS 中编辑文件 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/.env。 20、执行数据库迁移与填充,执行成功。如图17
执行数据库迁移与填充,执行成功

图17



[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# php artisan migrate:refresh --seed
Migration table not found.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (47.50ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (29.91ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (36.63ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (40.31ms)
Migrating: 2021_12_31_134920_add_avatar_and_introduction_to_users_table
Migrated:  2021_12_31_134920_add_avatar_and_introduction_to_users_table (240.63ms)
Migrating: 2021_12_31_155234_create_categories_table
Migrated:  2021_12_31_155234_create_categories_table (37.03ms)
Migrating: 2021_12_31_155935_seed_categories_data
Migrated:  2021_12_31_155935_seed_categories_data (12.72ms)
Migrating: 2021_12_31_161159_create_topics_table
Migrated:  2021_12_31_161159_create_topics_table (62.53ms)
Migrating: 2022_01_04_175444_create_replies_table
Migrated:  2022_01_04_175444_create_replies_table (49.36ms)
Migrating: 2022_01_05_101230_create_notifications_table
Migrated:  2022_01_05_101230_create_notifications_table (72.61ms)
Migrating: 2022_01_05_101456_add_notification_count_to_users_table
Migrated:  2022_01_05_101456_add_notification_count_to_users_table (41.74ms)
Migrating: 2022_01_05_114704_create_permission_tables
Migrated:  2022_01_05_114704_create_permission_tables (462.25ms)
Migrating: 2022_01_05_115758_seed_roles_and_permissions_data
Migrated:  2022_01_05_115758_seed_roles_and_permissions_data (252.50ms)
Migrating: 2022_01_05_164147_create_links_table
Migrated:  2022_01_05_164147_create_links_table (40.32ms)
Migrating: 2022_01_05_170327_add_references
Migrated:  2022_01_05_170327_add_references (133.90ms)
Migrating: 2022_01_06_094656_add_last_actived_at_to_users_table
Migrated:  2022_01_06_094656_add_last_actived_at_to_users_table (25.63ms)
Seeding: Database\Seeders\UsersTableSeeder
Seeded:  Database\Seeders\UsersTableSeeder (188.79ms)
Seeding: Database\Seeders\TopicsTableSeeder
Seeded:  Database\Seeders\TopicsTableSeeder (1,517.44ms)
Seeding: Database\Seeders\RepliesTableSeeder
Seeded:  Database\Seeders\RepliesTableSeeder (4,513.18ms)
Seeding: Database\Seeders\LinksTableSeeder
Seeded:  Database\Seeders\LinksTableSeeder (25.96ms)
Database seeding completed successfully.
[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# 



21、打开网址:https://app-wangqiang-larabbs.shuijingwanwq.com/ ,提示:InvalidArgumentException No hint path defined for [sudosu]. 。如图18
打开网址:https://app-wangqiang-larabbs.shuijingwanwq.com/ ,提示:InvalidArgumentException No hint path defined for [sudosu].

图18

22、编辑文件 config/sudosu.php ,添加 com


    'allowed_tlds' => ['dev', 'local', 'com'],


23、在命令行启动队列系统,报错:Symfony\Component\Process\Exception\LogicException 。 The Process class relies on proc_open, which is not available on your PHP installation.。如图19
在命令行启动队列系统,报错:Symfony\Component\Process\Exception\LogicException 。  The Process class relies on proc_open, which is not available on your PHP installation.

图19



[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# php artisan queue:listen

   Symfony\Component\Process\Exception\LogicException 

  The Process class relies on proc_open, which is not available on your PHP installation.

  at vendor/symfony/process/Process.php:146
    142▕      */
    143▕     public function __construct(array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
    144▕     {
    145▕         if (!\function_exists('proc_open')) {
  ➜ 146▕             throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.');
    147▕         }
    148▕ 
    149▕         $this->commandline = $command;
    150▕         $this->cwd = $cwd;

      +16 vendor frames 
  17  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()



24、编辑 /usr/local/php/etc/php.ini 文件,搜索 disable_functions,将其值中的 proc_open 、proc_get_status 删除掉。然后重启 PHP 服务 。如图20
编辑 /usr/local/php/etc/php.ini 文件,搜索 disable_functions,将其值中的 proc_open 、proc_get_status 删除掉。然后重启 PHP 服务

图20



[root@iZ23wv7v5ggZ etc]# vi php.ini
[root@iZ23wv7v5ggZ etc]# 
[root@iZ23wv7v5ggZ etc]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@iZ23wv7v5ggZ etc]# 



25、在命令行启动队列系统,队列在启动完成后会进入监听状态。但是,仍然报错: Symfony\Component\Process\Exception\ProcessTimedOutException 。 The process “‘/usr/local/php/bin/php’ ‘artisan’ ‘queue:work’ ‘–once’ ‘–name=default’ ‘–queue=default’ ‘–backoff=0’ ‘–memory=128’ ‘–sleep=3’ ‘–tries=1′” exceeded the timeout of 60 seconds.。添加选项 –timeout=0,不再报错。如图21
在命令行启动队列系统,队列在启动完成后会进入监听状态。但是,仍然报错: Symfony\Component\Process\Exception\ProcessTimedOutException 。  The process "'/usr/local/php/bin/php' 'artisan' 'queue:work' '--once' '--name=default' '--queue=default' '--backoff=0' '--memory=128' '--sleep=3' '--tries=1'" exceeded the timeout of 60 seconds.。添加选项 --timeout=0,不再报错

图21

<pre class="wp-block-syntaxhighlighter-code">

[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# php artisan queue:listen
[2022-01-07 17:04:21][9iy9L39pxxNvZ7NL9YQ0xQMXxI4EwI0j] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:04:22][9iy9L39pxxNvZ7NL9YQ0xQMXxI4EwI0j] Failed:     App\Jobs\TranslateSlug
[2022-01-07 17:04:23][oho1xFRRasdVKHL8f4T19vz51vwzf241] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:04:24][oho1xFRRasdVKHL8f4T19vz51vwzf241] Failed:     App\Jobs\TranslateSlug
[2022-01-07 17:04:25][qCqFpPSu9ImA0JggR4IiMlIKLWL3EB8H] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:04:28][qCqFpPSu9ImA0JggR4IiMlIKLWL3EB8H] Failed:     App\Jobs\TranslateSlug
[2022-01-07 17:04:28][uxRYiXpFXEXBvpPxJTDKIDkCCXAgBTG9] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:04:29][uxRYiXpFXEXBvpPxJTDKIDkCCXAgBTG9] Failed:     App\Jobs\TranslateSlug
[2022-01-07 17:04:29][kgqbausYzFSzLYgjlAvvXfrgVaGBwZME] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:04:29][kgqbausYzFSzLYgjlAvvXfrgVaGBwZME] Failed:     App\Jobs\TranslateSlug
[2022-01-07 17:04:30][wdweaoBl2V2k0iCCwynnjE3imiHxmUZK] Processing: App\Jobs\TranslateSlug

   Symfony\Component\Process\Exception\ProcessTimedOutException 

  The process "'/usr/local/php/bin/php' 'artisan' 'queue:work' '--once' '--name=default' '--queue=default' '--backoff=0' '--memory=128' '--sleep=3' '--tries=1'" exceeded the timeout of 60 seconds.

  at vendor/symfony/process/Process.php:1204
    1200▕ 
    1201▕         if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
    1202▕             $this->stop(0);
    1203▕ 
  ➜ 1204▕             throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
    1205▕         }
    1206▕ 
    1207▕         if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
    1208▕             $this->stop(0);

      +18 vendor frames 
  19  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# php artisan queue:listen --timeout=0
[2022-01-07 17:08:38][crCkj0LVPcowMiTlvjeGcGNHkPh1E4rY] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:39][crCkj0LVPcowMiTlvjeGcGNHkPh1E4rY] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:40][a6UvDyYukqW1sUSNcbjw7P6QzpFnt1dU] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:42][a6UvDyYukqW1sUSNcbjw7P6QzpFnt1dU] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:43][m8I0VIyZL9TguYR0XnxINv72wLgXqDCv] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:43][m8I0VIyZL9TguYR0XnxINv72wLgXqDCv] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:44][NM3oLDGUOhcsT5cIy9tAiM4WR1kOHTDw] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:46][NM3oLDGUOhcsT5cIy9tAiM4WR1kOHTDw] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:46][AGlsFITpj9Aqy2Iu0SOJZoxyNYcTl7ax] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:47][AGlsFITpj9Aqy2Iu0SOJZoxyNYcTl7ax] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:48][F8UO802DJzIt6nrIfAd5KZU0SmrFWg60] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:49][F8UO802DJzIt6nrIfAd5KZU0SmrFWg60] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:49][uN38Doj9q9xwDWtQcU7dGZLOub3W9Sqg] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:50][uN38Doj9q9xwDWtQcU7dGZLOub3W9Sqg] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:50][i2Fpvio1WVFbCbVFwmM8F6Gm9FWgveYq] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:51][i2Fpvio1WVFbCbVFwmM8F6Gm9FWgveYq] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:52][Ac7q3FzkUum0PN6jMVWYCqbbXRfInRM3] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:52][Ac7q3FzkUum0PN6jMVWYCqbbXRfInRM3] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:53][JstjmnEAp5ttbdPyqLXri7SwMs8Q7ple] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:54][JstjmnEAp5ttbdPyqLXri7SwMs8Q7ple] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:55][k7n2iJdSelQcgQWXsrjyci4KG1vNsAlq] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:55][k7n2iJdSelQcgQWXsrjyci4KG1vNsAlq] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:56][LcSujDiTXczEUgE1YZ5Cwf459he4yxSD] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:57][LcSujDiTXczEUgE1YZ5Cwf459he4yxSD] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:57][t2Umbs1fLco6N4ZfjYkEEbMdEHje0r9d] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:08:59][t2Umbs1fLco6N4ZfjYkEEbMdEHje0r9d] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:08:59][m4ttqh4axQ6JpFPQoL6Skpa1qBPAB6EC] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:01][m4ttqh4axQ6JpFPQoL6Skpa1qBPAB6EC] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:01][ARlo5v4zTyv3RUyKlBiR6HiYiwtuY6r5] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:03][ARlo5v4zTyv3RUyKlBiR6HiYiwtuY6r5] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:03][0DAnnrmFlwmZ6u1DGpZT0lL3fVc2GoTP] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:05][0DAnnrmFlwmZ6u1DGpZT0lL3fVc2GoTP] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:05][RXGEod7NPKnjrvzp0LB0xG7tumOTZQB3] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:07][RXGEod7NPKnjrvzp0LB0xG7tumOTZQB3] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:08][ebi2yS5WyyaZgfdHHdM0bPr6voETTHOY] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:10][ebi2yS5WyyaZgfdHHdM0bPr6voETTHOY] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:10][oCUs3UGYliYMEIldq3bOvbXEAuHJxH74] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:11][oCUs3UGYliYMEIldq3bOvbXEAuHJxH74] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:12][qS3aEkUuUx7s9eekD6txazQFCGXdZf95] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:12][qS3aEkUuUx7s9eekD6txazQFCGXdZf95] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:13][0M5eGoCrf44T0bHqi6CSnJWhIcRScx7V] Processing: App\Jobs\TranslateSlug
[2022-01-07 17:09:13][0M5eGoCrf44T0bHqi6CSnJWhIcRScx7V] Processed:  App\Jobs\TranslateSlug
[2022-01-07 17:09:14][ILzNa3JxWqzi4hMEbKsywvspJR0cSG7V] Processing: App\Jobs\TranslateSlug
^C
[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# 


</pre>
26、发现队列作业未按预期起作用,查看表:failed_jobs,里面存在一些失败的队列记录。可以忽略掉,因为这是偶发事件,应该是一瞬间的调用频率过高所导致。如图22
发现队列作业未按预期起作用,查看表:failed_jobs,里面存在一些失败的队列记录。可以忽略掉,因为这是偶发事件,应该是一瞬间的调用频率过高所导致

图22

<pre class="wp-block-syntaxhighlighter-code">

GuzzleHttp\Exception\ServerException: Server error: `GET http://api.fanyi.baidu.com/api/trans/vip/translate?q=Aut+et+assumenda+esse+necessitatibus+et+soluta+quia+temporibus.&from=zh&to=en&appid=20220104001046264&salt=1641546261&sign=6bf4c1c8f9779e1124e4e7b9a0dacd93` resulted in a `502 No data received from server or forwarder` response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
  <title>502 - (truncated...)
 in /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\Exception\RequestException::create()
#1 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#2 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler()
#3 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run()
#5 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Promise\Promise->wait()
#10 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request()
#11 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/app/Handlers/SlugTranslateHandler.php(42): GuzzleHttp\Client->get()
#12 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/app/Jobs/TranslateSlug.php(29): App\Handlers\SlugTranslateHandler->translate()
#13 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Jobs\TranslateSlug->handle()
#14 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#15 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#16 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#17 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call()
#18 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#19 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#20 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#21 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#22 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\Bus\Dispatcher->dispatchNow()
#23 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#24 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#26 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#27 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#28 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(428): Illuminate\Queue\Jobs\Job->fire()
#29 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process()
#30 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(329): Illuminate\Queue\Worker->runJob()
#31 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\Queue\Worker->runNextJob()
#32 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker()
#33 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
#34 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#35 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#36 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#37 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call()
#38 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#39 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/symfony/console/Command/Command.php(298): Illuminate\Console\Command->execute()
#40 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#41 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/symfony/console/Application.php(1005): Illuminate\Console\Command->run()
#42 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#43 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#44 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\Component\Console\Application->run()
#45 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#46 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#47 {main}

</pre>
27、在开发环境中,我们为了测试方便,直接在命令行里调用 artisan queue:listen 进行队列监控。然而在生产环境中,我们需要配置一个进程管理工具来监控 queue:work 进程的状态并在需要时进行重启。安装 Supervisor,Supervisor 是一个用于 Linux 操作系统的进程监视器。如果它失败了,它将自动重启 queue 进程。安装 Supervisor,你可以使用以下命令。报错:[Errno 14] HTTP Error 502 – Bad Gateway


[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# yum install supervisor
Loaded plugins: fastestmirror
Determining fastest mirrors
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package supervisor.noarch 0:3.4.0-1.el7 will be installed
--> Processing Dependency: python-meld3 >= 0.6.5 for package: supervisor-3.4.0-1.el7.noarch
--> Processing Dependency: python-setuptools for package: supervisor-3.4.0-1.el7.noarch
--> Running transaction check
---> Package python-meld3.x86_64 0:0.6.10-1.el7 will be installed
---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
--> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
--> Running transaction check
---> Package python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 will be installed
--> Processing Dependency: python-ipaddress for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
--> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
--> Running transaction check
---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
---> Package python-ipaddress.noarch 0:1.0.16-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================
 Package                                           Arch                 Version                      Repository          Size
==============================================================================================================================
Installing:
 supervisor                                        noarch               3.4.0-1.el7                  epel               498 k
Installing for dependencies:
 python-backports                                  x86_64               1.0-8.el7                    base               5.8 k
 python-backports-ssl_match_hostname               noarch               3.5.0.1-1.el7                base                13 k
 python-ipaddress                                  noarch               1.0.16-2.el7                 base                34 k
 python-meld3                                      x86_64               0.6.10-1.el7                 epel                73 k
 python-setuptools                                 noarch               0.9.8-7.el7                  base               397 k

Transaction Summary
==============================================================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 1.0 M
Installed size: 5.1 M
Is this ok [y/d/N]: y
Downloading packages:
python-backports-1.0-8.el7.x86 FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
python-backports-ssl_match_hos FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
python-meld3-0.6.10-1.el7.x86_ FAILED                                          
http://mirrors.cloud.aliyuncs.com/epel/7/x86_64/Packages/p/python-meld3-0.6.10-1.el7.x86_64.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
python-ipaddress-1.0.16-2.el7. FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
python-setuptools-0.9.8-7.el7. FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
supervisor-3.4.0-1.el7.noarch. FAILED                                          
http://mirrors.cloud.aliyuncs.com/epel/7/x86_64/Packages/s/supervisor-3.4.0-1.el7.noarch.rpm: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.


Error downloading packages:
  python-backports-1.0-8.el7.x86_64: [Errno 256] No more mirrors to try.
  python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch: [Errno 256] No more mirrors to try.
  python-setuptools-0.9.8-7.el7.noarch: [Errno 256] No more mirrors to try.
  supervisor-3.4.0-1.el7.noarch: [Errno 256] No more mirrors to try.
  python-ipaddress-1.0.16-2.el7.noarch: [Errno 256] No more mirrors to try.
  python-meld3-0.6.10-1.el7.x86_64: [Errno 256] No more mirrors to try.




28、缘由应该是 yum 源已经过期了,重新配置阿里云的 CentOS 7 yum 源,参考网址:https://oneinstack.com/faq/yum-apt/ 。如图23
缘由应该是 yum 源已经过期了,重新配置阿里云的 CentOS 7 yum 源,参考网址:https://oneinstack.com/faq/yum-apt/

图23



[root@iZ23wv7v5ggZ ~]# cd /etc/yum.repos.d
[root@iZ23wv7v5ggZ yum.repos.d]# ls
CentOS-Base.repo  epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]# rm -rf /etc/yum.repos.d/*.repo
[root@iZ23wv7v5ggZ yum.repos.d]# ls
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   4059      0 --:--:-- --:--:-- --:--:--  4056
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0    639      0  0:00:01  0:00:01 --:--:--   640
[root@iZ23wv7v5ggZ yum.repos.d]# ls
CentOS-Base.repo  epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
base                                                            | 3.6 kB  00:00:00     
epel                                                            | 4.7 kB  00:00:00     
extras                                                          | 2.9 kB  00:00:00     
updates                                                         | 2.9 kB  00:00:00     
(1/13): epel/x86_64/updateinfo                                  | 1.0 MB  00:00:00     
(2/13): epel/x86_64/prestodelta                                 |  450 B  00:00:00     
(3/13): base/7/x86_64/filelists_db                              | 7.2 MB  00:00:01     
(4/13): epel/x86_64/filelists_db                                |  12 MB  00:00:01     
(5/13): epel/x86_64/primary_db                                  | 7.0 MB  00:00:00     
(6/13): extras/7/x86_64/primary_db                              | 243 kB  00:00:00     
(7/13): extras/7/x86_64/filelists_db                            | 259 kB  00:00:00     
(8/13): epel/x86_64/other_db                                    | 3.4 MB  00:00:00     
(9/13): extras/7/x86_64/other_db                                | 145 kB  00:00:00     
(10/13): updates/7/x86_64/filelists_db                          | 7.4 MB  00:00:01     
(11/13): updates/7/x86_64/other_db                              | 955 kB  00:00:00     
(12/13): updates/7/x86_64/primary_db                            |  13 MB  00:00:02     
base/7/x86_64/other_db         FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(13/13): base/7/x86_64/other_db                                 | 2.6 MB  00:00:00     
Metadata Cache Created
[root@iZ23wv7v5ggZ yum.repos.d]# ^C
[root@iZ23wv7v5ggZ yum.repos.d]# 



29、参考 Supervisor 配置:https://learnku.com/docs/laravel/8.5/queues/10395#e45763 ,再次安装 Supervisor。安装成功。


[root@iZ23wv7v5ggZ yum.repos.d]# yum install supervisor
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
Resolving Dependencies
--> Running transaction check
---> Package supervisor.noarch 0:3.4.0-1.el7 will be installed
--> Processing Dependency: python-meld3 >= 0.6.5 for package: supervisor-3.4.0-1.el7.noarch
--> Processing Dependency: python-setuptools for package: supervisor-3.4.0-1.el7.noarch
--> Running transaction check
---> Package python-meld3.x86_64 0:0.6.10-1.el7 will be installed
---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
--> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
--> Running transaction check
---> Package python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 will be installed
--> Processing Dependency: python-ipaddress for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
--> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
--> Running transaction check
---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
---> Package python-ipaddress.noarch 0:1.0.16-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================
 Package                                 Arch       Version             Repository
                                                                                  Size
=======================================================================================
Installing:
 supervisor                              noarch     3.4.0-1.el7         epel     498 k
Installing for dependencies:
 python-backports                        x86_64     1.0-8.el7           base     5.8 k
 python-backports-ssl_match_hostname     noarch     3.5.0.1-1.el7       base      13 k
 python-ipaddress                        noarch     1.0.16-2.el7        base      34 k
 python-meld3                            x86_64     0.6.10-1.el7        epel      73 k
 python-setuptools                       noarch     0.9.8-7.el7         base     397 k

Transaction Summary
=======================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 1.0 M
Installed size: 5.1 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
(1/6): python-backports-1.0-8.el7.x86_64.rpm                    | 5.8 kB  00:00:00     
(2/6): python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch |  13 kB  00:00:00     
(3/6): python-ipaddress-1.0.16-2.el7.noarch.rpm                 |  34 kB  00:00:00     
(4/6): python-meld3-0.6.10-1.el7.x86_64.rpm                     |  73 kB  00:00:00     
(5/6): python-setuptools-0.9.8-7.el7.noarch.rpm                 | 397 kB  00:00:00     
(6/6): supervisor-3.4.0-1.el7.noarch.rpm                        | 498 kB  00:00:00     
---------------------------------------------------------------------------------------
Total                                                     726 kB/s | 1.0 MB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python-meld3-0.6.10-1.el7.x86_64                                    1/6 
  Installing : python-ipaddress-1.0.16-2.el7.noarch                                2/6 
  Installing : python-backports-1.0-8.el7.x86_64                                   3/6 
  Installing : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch            4/6 
  Installing : python-setuptools-0.9.8-7.el7.noarch                                5/6 
  Installing : supervisor-3.4.0-1.el7.noarch                                       6/6 
  Verifying  : supervisor-3.4.0-1.el7.noarch                                       1/6 
  Verifying  : python-backports-1.0-8.el7.x86_64                                   2/6 
  Verifying  : python-ipaddress-1.0.16-2.el7.noarch                                3/6 
  Verifying  : python-meld3-0.6.10-1.el7.x86_64                                    4/6 
  Verifying  : python-setuptools-0.9.8-7.el7.noarch                                5/6 
  Verifying  : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch            6/6 

Installed:
  supervisor.noarch 0:3.4.0-1.el7                                                      

Dependency Installed:
  python-backports.x86_64 0:1.0-8.el7                                                  
  python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7                           
  python-ipaddress.noarch 0:1.0.16-2.el7                                               
  python-meld3.x86_64 0:0.6.10-1.el7                                                   
  python-setuptools.noarch 0:0.9.8-7.el7                                               

Complete!
[root@iZ23wv7v5ggZ yum.repos.d]# 



30、创建一个 /etc/supervisord.d/app-wangqiang-larabbs-worker.ini 文件,启动并监视 queue:work 进程。指示 Supervisor 运行 2 个 queue:work 进程并监视所有进程。如图24
创建一个 /etc/supervisord.d/app-wangqiang-larabbs-worker.ini 文件,启动并监视 queue:work 进程。指示 Supervisor 运行 2 个 queue:work 进程并监视所有进程

图24



[root@iZ23wv7v5ggZ supervisord.d]# cat app-wangqiang-larabbs-worker.ini 
[program:app-wangqiang-larabbs-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan queue:work sqs --sleep=3 --tries=3 --max-time=600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www
numprocs=2
redirect_stderr=true
stdout_logfile=/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/worker.log
stopwaitsecs=600
[root@iZ23wv7v5ggZ supervisord.d]# 



31、创建配置文件后,你可以更新 Supervisor 配置并使用以下命令启动进程。报错:unix:///var/run/supervisor/supervisor.sock no such file
<pre class="wp-block-syntaxhighlighter-code">

[root@iZ23wv7v5ggZ supervisord.d]# cd ~
[root@iZ23wv7v5ggZ ~]# supervisorctl reread
error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib64/python2.7/socket.py line: 224
[root@iZ23wv7v5ggZ ~]# supervisorctl status
unix:///var/run/supervisor/supervisor.sock no such file


</pre>
32、重启 ECS 实例后,执行命令:easy_install supervisor。查看 supervisord 运行状态:supervisorctl status,报错:can’t find command ‘php’。如图25
重启 ECS 实例后,执行命令:easy_install supervisor。查看 supervisord 运行状态:supervisorctl status,报错:can't find command 'php'

图25



[root@iZ23wv7v5ggZ ~]# easy_install supervisor
Searching for supervisor
Best match: supervisor 3.4.0
Adding supervisor 3.4.0 to easy-install.pth file
Installing echo_supervisord_conf script to /usr/bin
Installing pidproxy script to /usr/bin
Installing supervisorctl script to /usr/bin
Installing supervisord script to /usr/bin

Using /usr/lib/python2.7/site-packages
Processing dependencies for supervisor
Finished processing dependencies for supervisor
[root@iZ23wv7v5ggZ ~]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@iZ23wv7v5ggZ ~]# systemctl restart supervisord
[root@iZ23wv7v5ggZ ~]# supervisorctl status
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_00   FATAL     can't find command 'php'
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_01   FATAL     can't find command 'php'
[root@iZ23wv7v5ggZ ~]# 


33、查看 php 的运行目录 which php,ini 配置文件的 command 的 php 加上绝对路径。如图26
查看 php 的运行目录 which php,ini 配置文件的 command 的 php 加上绝对路径

图26



[root@iZ23wv7v5ggZ ~]# which php
/usr/local/php/bin/php
[root@iZ23wv7v5ggZ ~]# vim /etc/supervisord.d/app-wangqiang-larabbs-worker.ini
[root@iZ23wv7v5ggZ ~]# cat /etc/supervisord.d/app-wangqiang-larabbs-worker.ini
[program:app-wangqiang-larabbs-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan queue:work sqs --sleep=3 --tries=3 --max-time=600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www
numprocs=2
redirect_stderr=true
stdout_logfile=/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/worker.log
stopwaitsecs=600
[root@iZ23wv7v5ggZ ~]# 



34、重启 supervisord 后,查看状态,运行成功,但是提示:退出太快(进程日志可能有详细信息)。如图27
重启 supervisord 后,查看状态,运行成功,但是提示:退出太快(进程日志可能有详细信息)

图27



[root@iZ23wv7v5ggZ ~]# service supervisord restart
Redirecting to /bin/systemctl restart supervisord.service
[root@iZ23wv7v5ggZ ~]# supervisorctl status
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_00   BACKOFF   Exited too quickly (process log may have details)
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_01   STARTING  
[root@iZ23wv7v5ggZ ~]# 


35、查看 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/worker.log,提示:Class ‘Aws\Sqs\SqsClient’ not found。如图29
查看 /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/worker.log,提示:Class 'Aws\Sqs\SqsClient' not found

图29



[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# cat worker.log 

   Error 

  Class 'Aws\Sqs\SqsClient' not found

  at /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/vendor/laravel/framework/src/Illuminate/Queue/Connectors/SqsConnector.php:26
     22▕             $config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
     23▕         }
     24▕ 
     25▕         return new SqsQueue(
  ➜  26▕             new SqsClient($config),
     27▕             $config['queue'],
     28▕             $config['prefix'] ?? '',
     29▕             $config['suffix'] ?? '',
     30▕             $config['after_commit'] ?? null

      +18 vendor frames 
  19  /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

      +18 vendor frames 
  19  /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()



36、ini 配置文件的 command 的 php ,删除掉 sqs,然后重启后,查看状态,一直处于运行中。如图30
ini 配置文件的 command 的 php ,删除掉 sqs,然后重启后,查看状态,一直处于运行中

图30



[root@iZ23wv7v5ggZ ~]# vim /etc/supervisord.d/app-wangqiang-larabbs-worker.ini
[root@iZ23wv7v5ggZ ~]# cat /etc/supervisord.d/app-wangqiang-larabbs-worker.ini
[program:app-wangqiang-larabbs-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan queue:work --sleep=3 --tries=3 --max-time=600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www
numprocs=2
redirect_stderr=true
stdout_logfile=/data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/worker.log
stopwaitsecs=600
[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# service supervisord restart
Redirecting to /bin/systemctl restart supervisord.service
[root@iZ23wv7v5ggZ app-wangqiang-larabbs.shuijingwanwq.com]# supervisorctl status
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_00   RUNNING   pid 2277, uptime 0:00:07
app-wangqiang-larabbs-worker:app-wangqiang-larabbs-worker_01   RUNNING   pid 2276, uptime 0:00:07




37、测试队列是否生效,重启 ECS 后,新建一个话题,其详情页面的网址为:https://app-wangqiang-larabbs.shuijingwanwq.com/topics/105 。刷新一下,其会 301 跳转至:https://app-wangqiang-larabbs.shuijingwanwq.com/topics/105/a-german 。表明队列生效中。如图31
测试队列是否生效,重启 ECS 后,新建一个话题,其详情页面的网址为:https://app-wangqiang-larabbs.shuijingwanwq.com/topics/105 。刷新一下,其会 301 跳转至:https://app-wangqiang-larabbs.shuijingwanwq.com/topics/105/a-german 。表明队列生效中

图31

38、计划任务的实现,使用调度器时,我们需要修改系统的 Cron 计划任务配置信息,运行以下命令,添加新的调度任务。部署完毕。如图32
计划任务的实现,使用调度器时,我们需要修改系统的 Cron 计划任务配置信息,运行以下命令,添加新的调度任务。部署完毕

图32



[root@iZ23wv7v5ggZ ~]# export EDITOR=vi && crontab -e
crontab: installing new crontab

* * * * * /usr/local/php/bin/php /data/wwwroot/app-wangqiang-larabbs.shuijingwanwq.com/artisan schedule:run >> /dev/null 2>&1


]]>
https://www.shuijingwanwq.com/2022/01/28/5867/feed/ 0
在 Laravel Framework 6.20.40、nuwave/lighthouse v5.33.1 中,报错:Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 39 https://www.shuijingwanwq.com/2022/01/26/5827/ https://www.shuijingwanwq.com/2022/01/26/5827/#respond Wed, 26 Jan 2022 01:28:02 +0000 =4.10.1]]> https://www.shuijingwanwq.com/?p=5827 浏览量: 291

1、执行请求:”query”: “query{ onlineStoreTheme(themeId: “vogue”){ id editable createdAt publishAt } }”, 时,响应 Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 39。如图1

执行请求:"query": "query{ onlineStoreTheme(themeId: "vogue"){ id editable createdAt publishAt } }", 时,响应 Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 39。

图1


{
  "message": "Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 39",
  "exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
  "file": "E:\\wwwroot\\object\\app\\Exceptions\\Handler.php",
  "line": 40,
  "trace": [
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php",
      "line": 39,
      "function": "report",
      "class": "App\\Exceptions\\Handler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 153,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Execution\\ReportingErrorHandler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ExtensionErrorHandler.php",
      "line": 37,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 153,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Execution\\ExtensionErrorHandler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ValidationErrorHandler.php",
      "line": 34,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 153,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Execution\\ValidationErrorHandler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\AuthorizationErrorHandler.php",
      "line": 34,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 153,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Execution\\AuthorizationErrorHandler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\AuthenticationErrorHandler.php",
      "line": 34,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 153,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Execution\\AuthenticationErrorHandler",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 105,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 295,
      "function": "then",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "function": "Nuwave\\Lighthouse\\{closure}",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Collection.php",
      "line": 638,
      "function": "array_map"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 296,
      "function": "map",
      "class": "Illuminate\\Support\\Collection",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ExecutionResult.php",
      "line": 147,
      "function": "Nuwave\\Lighthouse\\{closure}",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 264,
      "function": "toArray",
      "class": "GraphQL\\Executor\\ExecutionResult",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 168,
      "function": "serializable",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 119,
      "function": "executeOperation",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Utils.php",
      "line": 99,
      "function": "Nuwave\\Lighthouse\\{closure}",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
      "line": 118,
      "function": "applyEach",
      "class": "Nuwave\\Lighthouse\\Support\\Utils",
      "type": "::"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Controllers\\GraphQLController.php",
      "line": 32,
      "function": "executeOperationOrOperations",
      "class": "Nuwave\\Lighthouse\\GraphQL",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php",
      "line": 48,
      "function": "__invoke",
      "class": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
      "line": 219,
      "function": "dispatch",
      "class": "Illuminate\\Routing\\ControllerDispatcher",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
      "line": 176,
      "function": "runController",
      "class": "Illuminate\\Routing\\Route",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 681,
      "function": "run",
      "class": "Illuminate\\Routing\\Route",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 130,
      "function": "Illuminate\\Routing\\{closure}",
      "class": "Illuminate\\Routing\\Router",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Middleware\\AttemptAuthentication.php",
      "line": 34,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AttemptAuthentication",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Middleware\\AcceptJson.php",
      "line": 27,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AcceptJson",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 105,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 683,
      "function": "then",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 658,
      "function": "runRouteWithinStack",
      "class": "Illuminate\\Routing\\Router",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 624,
      "function": "runRoute",
      "class": "Illuminate\\Routing\\Router",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 613,
      "function": "dispatchToRoute",
      "class": "Illuminate\\Routing\\Router",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
      "line": 170,
      "function": "dispatch",
      "class": "Illuminate\\Routing\\Router",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 130,
      "function": "Illuminate\\Foundation\\Http\\{closure}",
      "class": "Illuminate\\Foundation\\Http\\Kernel",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\barryvdh\\laravel-debugbar\\src\\Middleware\\InjectDebugbar.php",
      "line": 67,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
      "line": 21,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
      "line": 21,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php",
      "line": 27,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php",
      "line": 63,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\fideloper\\proxy\\src\\TrustProxies.php",
      "line": 57,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Fideloper\\Proxy\\TrustProxies",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php",
      "line": 111,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 171,
      "function": "handle",
      "class": "Dingo\\Api\\Http\\Middleware\\Request",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
      "line": 105,
      "function": "Illuminate\\Pipeline\\{closure}",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
      "line": 145,
      "function": "then",
      "class": "Illuminate\\Pipeline\\Pipeline",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
      "line": 110,
      "function": "sendRequestThroughRouter",
      "class": "Illuminate\\Foundation\\Http\\Kernel",
      "type": "->"
    },
    {
      "file": "E:\\wwwroot\\object\\public\\index.php",
      "line": 57,
      "function": "handle",
      "class": "Illuminate\\Foundation\\Http\\Kernel",
      "type": "->"
    }
  ]
}


2、查看代码:\app\Exceptions\Handler.php:40 。如图2

查看代码:\app\Exceptions\Handler.php:40

图2


    /**
     * Report or log an exception.
     *
     * @param \Exception $exception
     * @return void
     * @throws Exception
     */
    public function report(Exception $exception)
    {
        // 1/10的概率上报到sentry,防止sentry增长过快
        if (app()->environment() === "production"
            && app()->bound('sentry')
            && $this->shouldReport($exception)
            && mt_rand(0, 100) < 10
        ) {
            \Sentry\withScope(function (\Sentry\State\Scope $scope) use ($exception): void {
                $scope->setTag('app.name', config('app.name'));
                \Sentry\captureException($exception);
            });
        }

        if (($exception instanceof BusinessException)) {
            BusinessException::notify($exception);
        }
        parent::report($exception);
    }


3、查看代码:/vendor/nuwave/lighthouse/src/Execution/ReportingErrorHandler.php:39 。在 38 行有注释: @phpstan-ignore-next-line Laravel 7 之前的版本仅限于接受 \Exception。如图3

查看代码:/vendor/nuwave/lighthouse/src/Execution/ReportingErrorHandler.php:39 。在 38 行有注释: @phpstan-ignore-next-line Laravel 7 之前的版本仅限于接受 \Exception

图3


    public function __invoke(?Error $error, Closure $next): ?array
    {
        if (null === $error) {
            return $next(null);
        }

        // Client-safe errors are assumed to be something that a client can handle
        // or is expected to happen, e.g. wrong syntax, authentication or validation
        if ($error->isClientSafe()) {
            return $next($error);
        }

        $previous = $error->getPrevious();
        if (null !== $previous) {
            // @phpstan-ignore-next-line Laravel versions prior to 7 are limited to accepting \Exception
            $this->exceptionHandler->report($previous);
        }

        return $next($error);
    }


4、当前程序的 Laravel 框架的版本:Laravel Framework 6.20.40。 nuwave/lighthouse 的版本:v5.33.1。


PS E:\wwwroot\object> php artisan
Laravel Framework 6.20.40

Usage:
  command [options] [arguments]



PS E:\wwwroot\object> composer show nuwave/lighthouse -i
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
name     : nuwave/lighthouse
descrip. : A framework for serving GraphQL from Laravel
keywords : graphql, laravel, laravel-graphql
versions : * v5.33.1
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://lighthouse-php.com
source   : [git] https://github.com/nuwave/lighthouse.git 4ff54df1a6e87fd4e753f4633cc9949f4664ae7d
dist     : [zip] https://api.github.com/repos/nuwave/lighthouse/zipball/4ff54df1a6e87fd4e753f4633cc9949f4664ae7d 4ff54df1a6e87fd4e753f4633cc9949f4664ae7d
path     : E:\wwwroot\object\vendor\nuwave\lighthouse
names    : nuwave/lighthouse



5、打开网址:https://github.com/nuwave/lighthouse/blob/v5.1.0/src/Execution/ReportingErrorHandler.php ,可以确定此问题从版本:v5.1.0 开始不再支持 Laravel 6 的。决定回退至此版本的上一版本:v5.0.2。如图4

打开网址:https://github.com/nuwave/lighthouse/blob/v5.1.0/src/Execution/ReportingErrorHandler.php ,可以确定此问题从版本:v5.1.0 开始不再支持 Laravel 6 的。决定回退至此版本的上一版本:v5.0.2

图4


    public function __invoke(?Error $error, Closure $next): ?array
    {
        if ($error === null) {
            return $next(null);
        }

        // Client-safe errors are assumed to be something that a client can handle
        // or is expected to happen, e.g. wrong syntax, authentication or validation
        if ($error->isClientSafe()) {
            return $next($error);
        }

        $this->exceptionHandler->report(
            // @phpstan-ignore-next-line TODO remove when supporting Laravel 7 and upwards
            $error->getPrevious()
        );

        return $next($error);
    }


6、执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse。如图5

执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse

图5


PS E:\wwwroot\object> composer remove nuwave/lighthouse
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
./composer.json has been updated
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
Running composer update nuwave/lighthouse
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 6 removals
  - Removing haydenpierce/class-finder (0.4.3)
  - Removing laragraph/utils (v1.1.1)
  - Removing mll-lab/laravel-graphql-playground (v2.5.0)
  - Removing nuwave/lighthouse (v5.33.1)
  - Removing thecodingmachine/safe (v1.3.3)
  - Removing webonyx/graphql-php (v14.11.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 6 removals
  - Removing webonyx/graphql-php (v14.11.3)
  - Removing thecodingmachine/safe (v1.3.3)
  - Removing nuwave/lighthouse (v5.33.1)
  - Removing mll-lab/laravel-graphql-playground (v2.5.0)
  - Removing laragraph/utils (v1.1.1)
  - Removing haydenpierce/class-finder (0.4.3)
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Google\Task\Composer::cleanup
Class Tests\Feature\LoginApiPostCartPaymentTest located in E:/wwwroot/object/tests\Feature\ApiCartPaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginApiPostCartTest located in E:/wwwroot/object/tests\Feature\ApiCartTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginGetPaymentTest located in E:/wwwroot/object/tests\Feature\PaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Sofa\Eloquence\Searchable\Searchable located in E:/wwwroot/object/vendor/sofa/eloquence-base/src\Contracts\Searchable\Searchable.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\RecommendedProduct\Database\Seeders\LastSaleDatabaseSeeder located in E:/wwwroot/object/Modules\LastSale\Database\Seeders\LastSaleDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\CheckoutPageImage\Database\Seeders\PixelConversionDatabaseSeeder located in E:/wwwroot/object/Modules\PixelConversion\Database\Seeders\PixelConversionDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\ThemeStore\Tests\FactoryTest located in E:/wwwroot/object/Modules\ThemeStore\Tests\Unit\FactoryTest.php does not comply with psr-4 autoloading standard. Skipping.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: arubacao/asset-cdn
Discovered Package: axlon/laravel-postal-code-validation
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: beyondcode/laravel-er-diagram-generator
Discovered Package: boaideas/laravel-cli-create-user
Discovered Package: cviebrock/eloquent-sluggable
Discovered Package: dingo/api
Discovered Package: fideloper/proxy
Discovered Package: genealabs/laravel-model-caching
Discovered Package: igaster/laravel-theme
Discovered Package: ignited/laravel-omnipay
Discovered Package: intervention/image
Discovered Package: jenssegers/agent
Discovered Package: jgrossi/corcel
Discovered Package: laravel/passport
Discovered Package: laravel/scout
Discovered Package: laravel/socialite
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: maatwebsite/excel
Discovered Package: mpociot/laravel-apidoc-generator
Discovered Package: nesbot/carbon
Discovered Package: neobject/facebook-conversions-api
Discovered Package: nunomaduro/collision
Discovered Package: nwidart/laravel-modules
Discovered Package: orangehill/iseed
Discovered Package: overtrue/laravel-pinyin
Discovered Package: overtrue/laravel-wechat
Discovered Package: s-ichikawa/laravel-sendgrid-driver
Discovered Package: sentry/sentry-laravel
Discovered Package: socialiteproviders/manager
Discovered Package: sofa/eloquence-base
Discovered Package: sofa/eloquence-mutable
Discovered Package: spatie/laravel-activitylog
Discovered Package: spatie/laravel-permission
Discovered Package: spatie/laravel-query-builder
Discovered Package: spatie/laravel-sitemap
Discovered Package: tamayo/laravel-scout-elastic
Discovered Package: torann/geoip
Package manifest generated successfully.
114 packages you are using are looking for funding.
Use the `composer fund` command to find out more!


7、执行 composer require nuwave/lighthouse:5.0.2 命令,安装 nuwave/lighthouse。指定包的确切版本。如图6

执行 composer require nuwave/lighthouse:5.0.2 命令,安装 nuwave/lighthouse。指定包的确切版本

图6


PS E:\wwwroot\object> composer require nuwave/lighthouse:5.0.2
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d

./composer.json has been updated
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
Running composer update nuwave/lighthouse
Loading composer repositories with package information
Updating dependencies
Lock file operations: 5 installs, 0 updates, 0 removals
  - Locking haydenpierce/class-finder (0.4.3)
  - Locking laragraph/utils (v1.3.0)
  - Locking nuwave/lighthouse (v5.0.2)
  - Locking thecodingmachine/safe (v1.3.3)
  - Locking webonyx/graphql-php (v14.11.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
  - Downloading laragraph/utils (v1.3.0)
  - Downloading nuwave/lighthouse (v5.0.2)
  - Installing webonyx/graphql-php (v14.11.3): Extracting archive
  - Installing thecodingmachine/safe (v1.3.3): Extracting archive
  - Installing laragraph/utils (v1.3.0): Extracting archive
  - Installing haydenpierce/class-finder (0.4.3): Extracting archive
  - Installing nuwave/lighthouse (v5.0.2): Extracting archive
3 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Google\Task\Composer::cleanup
Class Tests\Feature\LoginApiPostCartPaymentTest located in E:/wwwroot/object/tests\Feature\ApiCartPaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginApiPostCartTest located in E:/wwwroot/object/tests\Feature\ApiCartTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginGetPaymentTest located in E:/wwwroot/object/tests\Feature\PaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Sofa\Eloquence\Searchable\Searchable located in E:/wwwroot/object/vendor/sofa/eloquence-base/src\Contracts\Searchable\Searchable.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\RecommendedProduct\Database\Seeders\LastSaleDatabaseSeeder located in E:/wwwroot/object/Modules\LastSale\Database\Seeders\LastSaleDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\CheckoutPageImage\Database\Seeders\PixelConversionDatabaseSeeder located in E:/wwwroot/object/Modules\PixelConversion\Database\Seeders\PixelConversionDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\ThemeStore\Tests\FactoryTest located in E:/wwwroot/object/Modules\ThemeStore\Tests\Unit\FactoryTest.php does not comply with psr-4 autoloading standard. Skipping.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: arubacao/asset-cdn
Discovered Package: axlon/laravel-postal-code-validation
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: beyondcode/laravel-er-diagram-generator
Discovered Package: boaideas/laravel-cli-create-user
Discovered Package: cviebrock/eloquent-sluggable
Discovered Package: dingo/api
Discovered Package: fideloper/proxy
Discovered Package: genealabs/laravel-model-caching
Discovered Package: igaster/laravel-theme
Discovered Package: ignited/laravel-omnipay
Discovered Package: intervention/image
Discovered Package: jenssegers/agent
Discovered Package: jgrossi/corcel
Discovered Package: laravel/passport
Discovered Package: laravel/scout
Discovered Package: laravel/socialite
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: maatwebsite/excel
Discovered Package: mpociot/laravel-apidoc-generator
Discovered Package: nesbot/carbon
Discovered Package: neobject/facebook-conversions-api
Discovered Package: nunomaduro/collision
Discovered Package: nuwave/lighthouse
Discovered Package: nwidart/laravel-modules
Discovered Package: orangehill/iseed
Discovered Package: overtrue/laravel-pinyin
Discovered Package: overtrue/laravel-wechat
Discovered Package: s-ichikawa/laravel-sendgrid-driver
Discovered Package: sentry/sentry-laravel
Discovered Package: socialiteproviders/manager
Discovered Package: sofa/eloquence-base
Discovered Package: sofa/eloquence-mutable
Discovered Package: spatie/laravel-activitylog
Discovered Package: spatie/laravel-permission
Discovered Package: spatie/laravel-query-builder
Discovered Package: spatie/laravel-sitemap
Discovered Package: tamayo/laravel-scout-elastic
Discovered Package: torann/geoip
Package manifest generated successfully.
116 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PS E:\wwwroot\object> composer show nuwave/lighthouse -i
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
name     : nuwave/lighthouse
descrip. : A framework for serving GraphQL from Laravel
keywords : graphql, laravel, laravel-graphql
versions : * v5.0.2
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://lighthouse-php.com
source   : [git] https://github.com/nuwave/lighthouse.git d3921f093ccf608b52a92879dd24915317cefa65
dist     : [zip] https://api.github.com/repos/nuwave/lighthouse/zipball/d3921f093ccf608b52a92879dd24915317cefa65 d3921f093ccf608b52a92879dd24915317cefa65
path     : E:\wwwroot\object\vendor\nuwave\lighthouse
names    : nuwave/lighthouse

support
issues : https://github.com/nuwave/lighthouse/issues
source : https://github.com/nuwave/lighthouse

autoload
psr-4
Nuwave\Lighthouse\ => src/

requires
ext-json *
haydenpierce/class-finder ^0.4
illuminate/auth 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/bus 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/contracts 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/http 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/pagination 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/queue 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/routing 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/support 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
illuminate/validation 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
laragraph/utils ^1
php >= 7.2
thecodingmachine/safe ^1
webonyx/graphql-php ^14.2

requires (dev)
bensampo/laravel-enum ^1.28.3 || ^2 || ^3
ergebnis/composer-normalize ^2.2.2
laravel/framework 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
laravel/legacy-factories ^1.0
laravel/lumen-framework 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8
laravel/scout ^7 || ^8
mll-lab/graphql-php-scalars ^4
mockery/mockery ^1.0
nunomaduro/larastan ^0.6
orchestra/testbench 3.6.* || 3.7.* || 3.8.* || 3.9.* || ^4 || ^5 || ^6
phpbench/phpbench ^0.17
phpstan/phpstan-mockery ^0.12.5
phpunit/phpunit ^7.5 || ^8.4
predis/predis ^1.1
pusher/pusher-php-server ^3.2
rector/rector ^0.7.64
thecodingmachine/phpstan-safe-rule ^1.0

suggests
bensampo/laravel-enum Convenient enum definitions that can easily be registered in your Schema
laravel/scout Required for the @search directive
mll-lab/graphql-php-scalars Useful scalar types, required for @whereConditions
mll-lab/laravel-graphql-playground GraphQL IDE for better development workflow - integrated with Laravel
PS E:\wwwroot\object>



8、执行请求:”query”: “query{ onlineStoreTheme(themeId: “vogue”){ id editable createdAt publishAt } }”, 时,响应 Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 38。

9、执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse。执行 composer require nuwave/lighthouse:4.18.0 命令,安装 nuwave/lighthouse。指定包的确切版本。仍然报错:Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of TypeError given, called in E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Execution\\ReportingErrorHandler.php on line 25 。

<?php
 
namespace Nuwave\Lighthouse\Execution;
 
use Closure;
use GraphQL\Error\Error;
use Illuminate\Contracts\Debug\ExceptionHandler;
 
/**
 * Report errors through the default exception handler configured in Laravel.
 */
class ReportingErrorHandler implements ErrorHandler
{
    public static function handle(Error $error, Closure $next): array
    {
        // Client-safe errors are assumed to be something that a client can handle
        // or is expected to happen, e.g. wrong syntax, authentication or validation
        if ($error->isClientSafe()) {
            return $next($error);
        }
 
        // TODO inject through constructor once handle is non-static
        /** @var \Illuminate\Contracts\Debug\ExceptionHandler $reporter */
        $reporter = app(ExceptionHandler::class);
        $reporter->report($error->getPrevious()); // @phpstan-ignore-line TODO remove when supporting Laravel 7 and upwards
 
        return $next($error);
    }
}
 

10、执行 composer remove nuwave/lighthouse 命令,卸载 nuwave/lighthouse。执行 composer require nuwave/lighthouse:~4.10.1 命令,安装 nuwave/lighthouse。波浪号运算符 ~4.10.1 相当于 >=4.10.1,<4.11。4.10.1 版本已经不存在文件:\vendor\nuwave\lighthouse\src\Execution\ReportingErrorHandler.php 。再次请求,响应 200。提示:Return value of Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileRawSectionSchemaLoader::load() must be of the type array, bool returned 。符合预期。至少在程序出现异常的时候,能够明确定位到具体的异常情况。如图7

提示:Return value of Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileRawSectionSchemaLoader::load() must be of the type array, bool returned 。符合预期。至少在程序出现异常的时候,能够明确定位到具体的异常情况。

图7


{
  "errors": [
    {
      "debugMessage": "Return value of Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileRawSectionSchemaLoader::load() must be of the type array, bool returned",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "onlineStoreTheme"
      ],
      "trace": [
        {
          "file": "E:\\wwwroot\\object\\Modules\\ThemeSetting\\Schema\\Builder\\ThemeBuilder.php",
          "line": 86,
          "call": "Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileRawSectionSchemaLoader::load('header')"
        },
        {
          "file": "E:\\wwwroot\\object\\Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileThemeSchemaLoader.php",
          "line": 43,
          "call": "Modules\\ThemeSetting\\Schema\\Builder\\ThemeBuilder::build(array(1), instance of Modules\\ThemeSetting\\Schema\\Dto\\Theme)"
        },
        {
          "file": "E:\\wwwroot\\object\\Modules\\ThemeStore\\Resolver\\OnlineStoreThemeResolver.php",
          "line": 39,
          "call": "Modules\\ThemeSetting\\Bridge\\IgasterLaravelTheme\\FileThemeSchemaLoader::loadSchema()"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Schema\\Directives\\FieldDirective.php",
          "line": 58,
          "call": "Modules\\ThemeStore\\Resolver\\OnlineStoreThemeResolver::__invoke(null, array(2), instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Schema\\Factories\\FieldFactory.php",
          "line": 174,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\FieldDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}(null, array(1), instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ReferenceExecutor.php",
          "line": 632,
          "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::Nuwave\\Lighthouse\\Schema\\Factories\\{closure}(null, array(1), instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ReferenceExecutor.php",
          "line": 555,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, instance of Closure, null, instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ReferenceExecutor.php",
          "line": 1247,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Query, null, instance of ArrayObject(1), array(1))"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ReferenceExecutor.php",
          "line": 257,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: Query, null, array(0), instance of ArrayObject(1))"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\ReferenceExecutor.php",
          "line": 208,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Executor\\Executor.php",
          "line": 155,
          "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\GraphQL.php",
          "line": 158,
          "call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\GraphQL.php",
          "line": 90,
          "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, 'query{\n  onlineStoreTheme(themeId: \"vogue\"){\n    id\n    editable\n    createdAt\n    publishAt\n  }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
          "line": 171,
          "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, 'query{\n  onlineStoreTheme(themeId: \"vogue\"){\n    id\n    editable\n    createdAt\n    publishAt\n  }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
          "line": 110,
          "call": "Nuwave\\Lighthouse\\GraphQL::executeQuery('query{\n  onlineStoreTheme(themeId: \"vogue\"){\n    id\n    editable\n    createdAt\n    publishAt\n  }\n}', instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Controllers\\GraphQLController.php",
          "line": 70,
          "call": "Nuwave\\Lighthouse\\GraphQL::executeRequest(instance of Nuwave\\Lighthouse\\Execution\\LighthouseRequest)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php",
          "line": 54,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController::query(instance of Nuwave\\Lighthouse\\Execution\\LighthouseRequest)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php",
          "line": 45,
          "call": "Illuminate\\Routing\\Controller::callAction('query', array(1))"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
          "line": 219,
          "call": "Illuminate\\Routing\\ControllerDispatcher::dispatch(instance of Illuminate\\Routing\\Route, instance of Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController, 'query')"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
          "line": 176,
          "call": "Illuminate\\Routing\\Route::runController()"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
          "line": 681,
          "call": "Illuminate\\Routing\\Route::run()"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 130,
          "call": "Illuminate\\Routing\\Router::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Middleware\\AcceptJson.php",
          "line": 30,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AcceptJson::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 105,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
          "line": 683,
          "call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
          "line": 658,
          "call": "Illuminate\\Routing\\Router::runRouteWithinStack(instance of Illuminate\\Routing\\Route, instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
          "line": 624,
          "call": "Illuminate\\Routing\\Router::runRoute(instance of Illuminate\\Http\\Request, instance of Illuminate\\Routing\\Route)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
          "line": 613,
          "call": "Illuminate\\Routing\\Router::dispatchToRoute(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
          "line": 170,
          "call": "Illuminate\\Routing\\Router::dispatch(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 130,
          "call": "Illuminate\\Foundation\\Http\\Kernel::Illuminate\\Foundation\\Http\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\barryvdh\\laravel-debugbar\\src\\Middleware\\InjectDebugbar.php",
          "line": 67,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
          "line": 21,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
          "line": 21,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php",
          "line": 27,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php",
          "line": 63,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\fideloper\\proxy\\src\\TrustProxies.php",
          "line": 57,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Fideloper\\Proxy\\TrustProxies::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php",
          "line": 111,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 171,
          "call": "Dingo\\Api\\Http\\Middleware\\Request::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
          "line": 105,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
          "line": 145,
          "call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)"
        },
        {
          "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
          "line": 110,
          "call": "Illuminate\\Foundation\\Http\\Kernel::sendRequestThroughRouter(instance of Illuminate\\Http\\Request)"
        },
        {
          "file": "E:\\wwwroot\\object\\public\\index.php",
          "line": 57,
          "call": "Illuminate\\Foundation\\Http\\Kernel::handle(instance of Illuminate\\Http\\Request)"
        }
      ]
    }
  ],
  "data": {
    "onlineStoreTheme": null
  }
}


11、nuwave/lighthouse 的版本:4.10.2。如图8

nuwave/lighthouse 的版本:4.10.2

图8


PS E:\wwwroot\object> composer require nuwave/lighthouse:~4.10.1
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
                                                                                                   ./composer.json has been updated
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
Running composer update nuwave/lighthouse
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking nuwave/lighthouse (4.10.2)
  - Locking webonyx/graphql-php (v0.13.9)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Downloading nuwave/lighthouse (4.10.2)
  - Installing webonyx/graphql-php (v0.13.9): Extracting archive
  - Installing nuwave/lighthouse (4.10.2): Extracting archive
4 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Google\Task\Composer::cleanup
Class Tests\Feature\LoginApiPostCartPaymentTest located in E:/wwwroot/object/tests\Feature\ApiCartPaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginApiPostCartTest located in E:/wwwroot/object/tests\Feature\ApiCartTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Tests\Feature\LoginGetPaymentTest located in E:/wwwroot/object/tests\Feature\PaymentTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Sofa\Eloquence\Searchable\Searchable located in E:/wwwroot/object/vendor/sofa/eloquence-base/src\Contracts\Searchable\Searchable.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\RecommendedProduct\Database\Seeders\LastSaleDatabaseSeeder located in E:/wwwroot/object/Modules\LastSale\Database\Seeders\LastSaleDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\CheckoutPageImage\Database\Seeders\PixelConversionDatabaseSeeder located in E:/wwwroot/object/Modules\PixelConversion\Database\Seeders\PixelConversionDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Modules\ThemeStore\Tests\FactoryTest located in E:/wwwroot/object/Modules\ThemeStore\Tests\Unit\FactoryTest.php does not comply with psr-4 autoloading standard. Skipping.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: arubacao/asset-cdn
Discovered Package: axlon/laravel-postal-code-validation
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: beyondcode/laravel-er-diagram-generator
Discovered Package: boaideas/laravel-cli-create-user
Discovered Package: cviebrock/eloquent-sluggable
Discovered Package: dingo/api
Discovered Package: fideloper/proxy
Discovered Package: genealabs/laravel-model-caching
Discovered Package: igaster/laravel-theme
Discovered Package: ignited/laravel-omnipay
Discovered Package: intervention/image
Discovered Package: jenssegers/agent
Discovered Package: jgrossi/corcel
Discovered Package: laravel/passport
Discovered Package: laravel/scout
Discovered Package: laravel/socialite
Discovered Package: laravel/tinker
Discovered Package: maatwebsite/excel
Discovered Package: mpociot/laravel-apidoc-generator
Discovered Package: nesbot/carbon
Discovered Package: neobject/facebook-conversions-api
Discovered Package: nunomaduro/collision
Discovered Package: nuwave/lighthouse
Discovered Package: nwidart/laravel-modules
Discovered Package: orangehill/iseed
Discovered Package: overtrue/laravel-pinyin
Discovered Package: overtrue/laravel-wechat
Discovered Package: s-ichikawa/laravel-sendgrid-driver
Discovered Package: sentry/sentry-laravel
Discovered Package: socialiteproviders/manager
Discovered Package: sofa/eloquence-base
Discovered Package: sofa/eloquence-mutable
Discovered Package: spatie/laravel-activitylog
Discovered Package: spatie/laravel-permission
Discovered Package: spatie/laravel-query-builder
Discovered Package: spatie/laravel-sitemap
Discovered Package: tamayo/laravel-scout-elastic
Discovered Package: torann/geoip
Package manifest generated successfully.
116 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PS E:\wwwroot\object> composer show nuwave/lighthouse -i
easywechat-composer/easywechat-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "easywechat-composer/easywechat-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] d
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
name     : nuwave/lighthouse
descrip. : Lighthouse is a schema first GraphQL package for Laravel applications.
keywords : api, graphql, laravel, laravel-graphql
versions : * 4.10.2
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://lighthouse-php.com
source   : [git] https://github.com/nuwave/lighthouse.git e9d6c29e38b2dfee1e4c3c9b1eabff4d19029d48
dist     : [zip] https://api.github.com/repos/nuwave/lighthouse/zipball/e9d6c29e38b2dfee1e4c3c9b1eabff4d19029d48 e9d6c29e38b2dfee1e4c3c9b1eabff4d19029d48
path     : E:\wwwroot\object\vendor\nuwave\lighthouse
names    : nuwave/lighthouse

support
issues : https://github.com/nuwave/lighthouse/issues
source : https://github.com/nuwave/lighthouse

autoload
psr-4
Nuwave\Lighthouse\ => src/

requires
ext-json *
illuminate/contracts 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
illuminate/http 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
illuminate/pagination 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
illuminate/routing 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
illuminate/support 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
illuminate/validation 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
php >= 7.1
webonyx/graphql-php ^0.13.2

requires (dev)
bensampo/laravel-enum ^1.28.3
composer/composer 1.10.0-RC as 1.9.3
ergebnis/composer-normalize ^2.2.2
haydenpierce/class-finder ^0.4.0
laravel/framework 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0
laravel/lumen-framework 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || dev-master
laravel/scout ^4.0 || ^5.0 || ^6.0 || ^7.0
mll-lab/graphql-php-scalars ^2.1
mockery/mockery ^1.0
nunomaduro/larastan ^0.4.3 || ^0.5.2
orchestra/database 3.5.* || 3.6.* || 3.7.* || 3.8.* || 3.9.* || ^4.0 || 5.x-dev
orchestra/testbench 3.5.* || 3.6.* || 3.7.* || 3.8.* || 3.9.* || ^4.0 || 5.x-dev
phpbench/phpbench @dev
phpunit/phpunit ^6.5 || ^7.5 || ^8.4
pusher/pusher-php-server ^3.2

suggests
bensampo/laravel-enum Convenient enum definitions that can easily be registered in your Schema
haydenpierce/class-finder Required for the artisan command lighthouse:validate-schema
laravel/scout Required for the @search directive
mll-lab/graphql-php-scalars Useful scalar types, required for @whereConditions
mll-lab/laravel-graphql-playground GraphQL IDE for better development workflow - integrated with Laravel
PS E:\wwwroot\object>


12、在 GitHub 上搜索 Tag:1.10,存在 v4.10.1、4.10.2,后续 4.10 可能会继续增加 Tag,以修复 Bug。如图9

在 GitHub 上搜索 Tag:1.10,存在 v4.10.1、4.10.2,后续 4.10 可能会继续增加 Tag,以修复 Bug

图9

]]>
https://www.shuijingwanwq.com/2022/01/26/5827/feed/ 0
在 Laravel 8 中的模块化示例实现 https://www.shuijingwanwq.com/2022/01/25/5821/ https://www.shuijingwanwq.com/2022/01/25/5821/#respond Tue, 25 Jan 2022 01:40:39 +0000 https://www.shuijingwanwq.com/?p=5821 浏览量: 227 1、在 GitHub 中搜索:laravel module,选择第一个结果:nWidart / laravel-modules。其支持 Laravel 中的模块管理。 2、参考网址:https://nicolaswidart.com/blog/writing-modular-applications-with-laravel-modules 。为什么要使用这个包,使用 laravel-modules 编写模块化应用程序。当涉及到编写更复杂、更大的应用程序时,发现 laravel 的默认结构很麻烦而且不理想。 3、要通过 Composer 安装,请运行以下命令。如图1
要通过 Composer 安装,请运行以下命令

图1



PS E:\wwwroot\laravel-modules-demo> composer require nwidart/laravel-modules
Using version ^8.2 for nwidart/laravel-modules
./composer.json has been updated
Running composer update nwidart/laravel-modules
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking nwidart/laravel-modules (8.2.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading nwidart/laravel-modules (8.2.0)
  - Installing nwidart/laravel-modules (8.2.0): Extracting archive
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: nwidart/laravel-modules
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.


4、运行以下命令发布包的配置文件


PS E:\wwwroot\laravel-modules-demo> php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Copied File [\vendor\nwidart\laravel-modules\config\config.php] To [\config\modules.php]
Publishing complete.


5、默认情况下,模块类不会自动加载。您可以使用 psr-4 自动加载模块。编辑 composer.json,然后运行:composer dump-autoload。如图2
默认情况下,模块类不会自动加载。您可以使用 psr-4 自动加载模块。编辑 composer.json,然后运行:composer dump-autoload

图2



    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "Modules/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },




PS E:\wwwroot\laravel-modules-demo> composer dump-autoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: nwidart/laravel-modules
Package manifest generated successfully.
Generated optimized autoload files containing 5106 classes
PS E:\wwwroot\laravel-modules-demo>


6、参考文档:https://nwidart.com/laravel-modules/v6/introduction ,快速开启一个示例,使用 php artisan module:make Blog 生成你的第一个模块。 将生成以下结构。由于文档的版本是针对 v6 的,而现在程序的最新版本是 v8,因此,目录结构有所出入。如图3
使用 php artisan module:make Blog 生成你的第一个模块。 将生成以下结构。由于文档的版本是针对 v6 的,而现在程序的最新版本是 v8,因此,目录结构有所出入

图3



PS E:\wwwroot\laravel-modules-demo> php artisan module:make Blog
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/module.json
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Routes/web.php
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Routes/api.php
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Resources/views/index.blade.php
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Resources/views/layouts/master.blade.php
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Config/config.php
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/composer.json
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Resources/assets/js/app.js
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/Resources/assets/sass/app.scss
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/webpack.mix.js
Created : E:\wwwroot\laravel-modules-demo\Modules/Blog/package.json
Created : E:/wwwroot/laravel-modules-demo/Modules/Blog/Database/Seeders/BlogDatabaseSeeder.php
Created : E:/wwwroot/laravel-modules-demo/Modules/Blog/Providers/BlogServiceProvider.php
Created : E:/wwwroot/laravel-modules-demo/Modules/Blog/Providers/RouteServiceProvider.php
Created : E:/wwwroot/laravel-modules-demo/Modules/Blog/Http/Controllers/BlogController.php
Module [Blog] created successfully.


7、默认情况下,当您创建新模块时,该命令会自动添加一些资源,例如控制器、种子类、服务提供者等。如果你不想要这些,你可以添加 –plain 标志,生成一个普通的模块。将生成以下结构。如图4
默认情况下,当您创建新模块时,该命令会自动添加一些资源,例如控制器、种子类、服务提供者等。如果你不想要这些,你可以添加 --plain 标志,生成一个普通的模块。将生成以下结构

图4



PS E:\wwwroot\laravel-modules-demo> php artisan module:make Auth -p
Created : E:\wwwroot\laravel-modules-demo\Modules/Auth/module.json
Module [Auth] created successfully.


]]>
https://www.shuijingwanwq.com/2022/01/25/5821/feed/ 0
在 Laravel 8 中参考 igaster / laravel-theme 示例实现 https://www.shuijingwanwq.com/2022/01/25/5811/ https://www.shuijingwanwq.com/2022/01/25/5811/#respond Tue, 25 Jan 2022 01:25:18 +0000 https://www.shuijingwanwq.com/?p=5811 浏览量: 69

1、在本地使用 Composer 来创建一个新的 Laravel 项目:laravel-theme-demo。


PS E:\wwwroot> composer create-project laravel/laravel laravel-theme-demo
Creating a "laravel/laravel" project at "./laravel-theme-demo"
Installing laravel/laravel (v8.6.10)
  - Installing laravel/laravel (v8.6.10): Extracting archive
Created project in E:\wwwroot\laravel-theme-demo
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 110 installs, 0 updates, 0 removals


2、igaster / laravel-theme 是一个 Laravel 包,增加了对管理主题的基本支持。它允许您在单独的文件夹中构建视图和资产,并支持主题扩展。执行命令:composer require “igaster/laravel-theme”,以安装 igaster/laravel-theme。


PS E:\wwwroot\laravel-theme-demo> composer require "igaster/laravel-theme"
Using version ^2.0 for igaster/laravel-theme
./composer.json has been updated
Running composer update igaster/laravel-theme
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking igaster/laravel-theme (v2.0.17)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing igaster/laravel-theme (v2.0.17): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: igaster/laravel-theme
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
PS E:\wwwroot\laravel-theme-demo>


3、安装 Laravel Mix,执行:yarn install,运行所有的 Mix 任务,执行:npm run dev。


PS E:\wwwroot\laravel-theme-demo> yarn install
yarn install v1.22.15
info No lockfile found.
[1/4] Resolving packages...
warning laravel-mix > node-libs-browser > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "win32" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/core@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-proposal-object-rest-spread@^7.15.6".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-syntax-dynamic-import@^7.8.3".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-transform-runtime@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/preset-env@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "webpack@^5.60.0".
warning " > laravel-mix@6.0.39" has unmet peer dependency "webpack-cli@^4.9.1".
[4/4] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.22.17", while you're on "1.22.15".
Done in 87.72s.
PS E:\wwwroot\laravel-theme-demo> npm run dev

> dev
> npm run development


> development
> mix


● Mix █████████████████████████ emitting (98%)
 after emit




● Mix █████████████████████████ done (99%) plugins
 WebpackBar:done
















✔ Mix
  Compiled successfully in 3.82s


































   Laravel Mix v6.0.39


✔ Compiled Successfully in 3717ms
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┐
│                                                                                                       File │ Size    │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│                                                                                                 /js/app.js │ 606 KiB │
│                                                                                                css/app.css │ 1 bytes │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┘

● Mix █████████████████████████ done (99%)
 plugins

webpack compiled successfully
PS E:\wwwroot\laravel-theme-demo>


4、将配置文件发布到您的应用程序


PS E:\wwwroot\laravel-theme-demo> php artisan vendor:publish --provider="Igaster\LaravelTheme\themeServiceProvider"
Copied File [\vendor\igaster\laravel-theme\src\Config\themes.php] To [\config\themes.php]
Publishing complete.


5、创建主题,执行命令:theme:create。生成目录结构,如法炮制,生成主题 t2。如图1

创建主题,执行命令:theme:create。生成目录结构,如法炮制,生成主题 t2

图1


PS E:\wwwroot\laravel-theme-demo> php artisan theme:create

 Give theme name::
 > t1

 Where will views be located? [t1]:
 >

 Where will assets be located? [t1]:
 >

 Extends an other theme? (yes/no) [no]:
 >

Summary:
- Theme name: t1
- Views Path: E:\wwwroot\laravel-theme-demo\resources\views/t1
- Asset Path: E:\wwwroot\laravel-theme-demo\public\t1
- Extends Theme: No

 Create Theme? (yes/no) [yes]:
 > yes
PS E:\wwwroot\laravel-theme-demo> php artisan theme:create

 Give theme name::
 > t2

 Where will views be located? [t2]:
 >

 Where will assets be located? [t2]:
 >

 Extends an other theme? (yes/no) [no]:
 >

Summary:
- Theme name: t2
- Views Path: E:\wwwroot\laravel-theme-demo\resources\views/t2
- Asset Path: E:\wwwroot\laravel-theme-demo\public\t2
- Extends Theme: No

 Create Theme? (yes/no) [yes]:
 > yes



6、打开首页:http://laravel-theme-demo.local/ ,默认的界面。如图2

打开首页:http://laravel-theme-demo.local/ ,默认的界面

图2

7、使用中间件设置主题,执行命令:php artisan make:middleware SetTheme


PS E:\wwwroot\laravel-theme-demo> php artisan make:middleware SetTheme
Middleware created successfully.


8、在 app\Http\Kernel.php 文件中注册你的中间件。 例如,如果您想将主题应用于所有路由,则应将其添加到 web 数组中。


    /**
     * The application's route middleware groups.
     *
     * @var array>
     */
    protected $middlewareGroups = [
        'web' => [
            // ...
            \App\Http\Middleware\SetTheme::class,
        ],
    ];


9、添加文件:public/images/test.gif、public/t1/images/test.gif、public/t2/images/test.gif,编辑主题文件:resources/views/welcome.blade.php、resources/views/welcome.blade.php、resources/views/welcome.blade.php,其内容完全一样

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <title>Laravel</title>
 
    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
 
    <!-- Styles -->
    <style>
        /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}a{background-color:transparent}[hidden]{display:none}html{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}*,:after,:before{box-sizing:border-box;border:0 solid #e2e8f0}a{color:inherit;text-decoration:inherit}svg,video{display:block;vertical-align:middle}video{max-width:100%;height:auto}.bg-white{--bg-opacity:1;background-color:#fff;background-color:rgba(255,255,255,var(--bg-opacity))}.bg-gray-100{--bg-opacity:1;background-color:#f7fafc;background-color:rgba(247,250,252,var(--bg-opacity))}.border-gray-200{--border-opacity:1;border-color:#edf2f7;border-color:rgba(237,242,247,var(--border-opacity))}.border-t{border-top-width:1px}.flex{display:flex}.grid{display:grid}.hidden{display:none}.items-center{align-items:center}.justify-center{justify-content:center}.font-semibold{font-weight:600}.h-5{height:1.25rem}.h-8{height:2rem}.h-16{height:4rem}.text-sm{font-size:.875rem}.text-lg{font-size:1.125rem}.leading-7{line-height:1.75rem}.mx-auto{margin-left:auto;margin-right:auto}.ml-1{margin-left:.25rem}.mt-2{margin-top:.5rem}.mr-2{margin-right:.5rem}.ml-2{margin-left:.5rem}.mt-4{margin-top:1rem}.ml-4{margin-left:1rem}.mt-8{margin-top:2rem}.ml-12{margin-left:3rem}.-mt-px{margin-top:-1px}.max-w-6xl{max-width:72rem}.min-h-screen{min-height:100vh}.overflow-hidden{overflow:hidden}.p-6{padding:1.5rem}.py-4{padding-top:1rem;padding-bottom:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.pt-8{padding-top:2rem}.fixed{position:fixed}.relative{position:relative}.top-0{top:0}.right-0{right:0}.shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}.text-center{text-align:center}.text-gray-200{--text-opacity:1;color:#edf2f7;color:rgba(237,242,247,var(--text-opacity))}.text-gray-300{--text-opacity:1;color:#e2e8f0;color:rgba(226,232,240,var(--text-opacity))}.text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}.text-gray-500{--text-opacity:1;color:#a0aec0;color:rgba(160,174,192,var(--text-opacity))}.text-gray-600{--text-opacity:1;color:#718096;color:rgba(113,128,150,var(--text-opacity))}.text-gray-700{--text-opacity:1;color:#4a5568;color:rgba(74,85,104,var(--text-opacity))}.text-gray-900{--text-opacity:1;color:#1a202c;color:rgba(26,32,44,var(--text-opacity))}.underline{text-decoration:underline}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.w-5{width:1.25rem}.w-8{width:2rem}.w-auto{width:auto}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}@media (min-width:640px){.sm\:rounded-lg{border-radius:.5rem}.sm\:block{display:block}.sm\:items-center{align-items:center}.sm\:justify-start{justify-content:flex-start}.sm\:justify-between{justify-content:space-between}.sm\:h-20{height:5rem}.sm\:ml-0{margin-left:0}.sm\:px-6{padding-left:1.5rem;padding-right:1.5rem}.sm\:pt-0{padding-top:0}.sm\:text-left{text-align:left}.sm\:text-right{text-align:right}}@media (min-width:768px){.md\:border-t-0{border-top-width:0}.md\:border-l{border-left-width:1px}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){.lg\:px-8{padding-left:2rem;padding-right:2rem}}@media (prefers-color-scheme:dark){.dark\:bg-gray-800{--bg-opacity:1;background-color:#2d3748;background-color:rgba(45,55,72,var(--bg-opacity))}.dark\:bg-gray-900{--bg-opacity:1;background-color:#1a202c;background-color:rgba(26,32,44,var(--bg-opacity))}.dark\:border-gray-700{--border-opacity:1;border-color:#4a5568;border-color:rgba(74,85,104,var(--border-opacity))}.dark\:text-white{--text-opacity:1;color:#fff;color:rgba(255,255,255,var(--text-opacity))}.dark\:text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}.dark\:text-gray-500{--tw-text-opacity:1;color:#6b7280;color:rgba(107,114,128,var(--tw-text-opacity))}}
    </style>
 
    <style>
        body {
            font-family: 'Nunito', sans-serif;
        }
    </style>
</head>
<body class="antialiased">
<div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">
    @if (Route::has('login'))
        <div class="hidden fixed top-0 right-0 px-6 py-4 sm:block">
            @auth
                <a href="{{ url('/home') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Home</a>
            @else
                <a href="{{ route('login') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Log in</a>
 
                @if (Route::has('register'))
                    <a href="{{ route('register') }}" class="ml-4 text-sm text-gray-700 dark:text-gray-500 underline">Register</a>
                @endif
            @endauth
        </div>
    @endif
 
    <div class="max-w-6xl mx-auto sm:px-6 lg:px-8">
        <div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
            This is the "{{Theme::get()}}" theme.
        </div>
        <div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
            <img src={{Theme::url('images/test.gif')}}>
        </div>
 
    </div>
</div>
</body>
</html>
 
 

10、打开首页,主题名为空。如图3

打开首页,主题名为空

图3

11、编辑 app/Http/Middleware/SetTheme.php,设置主题为 t1,打开首页,主题名为 t1。如图4

编辑 app/Http/Middleware/SetTheme.php,设置主题为 t1,打开首页,主题名为 t1

图4

<?php
 
namespace App\Http\Middleware;
 
use Closure;
use Illuminate\Http\Request;
 
class SetTheme
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $themeName = "t1";
        if(\Theme::exists($themeName)){
            \Theme::set($themeName);
        }
 
        return $next($request);
    }
}

12、编辑 app/Http/Middleware/SetTheme.php,设置主题为 t2,打开首页,主题名为 t2。如图5

编辑 app/Http/Middleware/SetTheme.php,设置主题为 t2,打开首页,主题名为 t2

图5

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class SetTheme
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $themeName = "t2";
        if(\Theme::exists($themeName)){
            \Theme::set($themeName);
        }

        return $next($request);
    }
}
]]>
https://www.shuijingwanwq.com/2022/01/25/5811/feed/ 0
使用 Lighthouse 构建 GraphQL 服务器的入门,从零开始为一个简单博客创建 GraphQL API https://www.shuijingwanwq.com/2022/01/24/5802/ https://www.shuijingwanwq.com/2022/01/24/5802/#respond Mon, 24 Jan 2022 10:29:25 +0000 https://www.shuijingwanwq.com/?p=5802 浏览量: 170

1、使用 Lighthouse 构建 GraphQL 服务器的入门。参考网址:https://lighthouse-php.cn/tutorial/

2、从零开始为一个简单博客创建 GraphQL API。通过 Composer 创建一个新的 Laravel 项目:lighthouse-tutorial


PS E:\wwwroot> composer create-project laravel/laravel lighthouse-tutorial
Creating a "laravel/laravel" project at "./lighthouse-tutorial"
Installing laravel/laravel (v8.6.10)
  - Installing laravel/laravel (v8.6.10): Extracting archive
Created project in E:\wwwroot\lighthouse-tutorial
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 110 installs, 0 updates, 0 removals
  - Locking asm89/stack-cors (v2.0.5)
  - Locking brick/math (0.9.3)
  - Locking dflydev/dot-access-data (v3.0.1)
  - Locking doctrine/inflector (2.0.4)
  - Locking doctrine/instantiator (1.4.0)
  - Locking doctrine/lexer (1.2.1)
  - Locking dragonmantank/cron-expression (v3.2.3)
  - Locking egulias/email-validator (2.1.25)
  - Locking facade/flare-client-php (1.9.1)
  - Locking facade/ignition (2.17.4)
  - Locking facade/ignition-contracts (1.0.2)
  - Locking fakerphp/faker (v1.17.0)
  - Locking filp/whoops (2.14.5)
  - Locking fruitcake/laravel-cors (v2.0.5)
  - Locking graham-campbell/result-type (v1.0.4)
  - Locking guzzlehttp/guzzle (7.4.1)
  - Locking guzzlehttp/promises (1.5.1)
  - Locking guzzlehttp/psr7 (2.1.0)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking laravel/framework (v8.78.1)
  - Locking laravel/sail (v1.12.12)
  - Locking laravel/sanctum (v2.13.0)
  - Locking laravel/serializable-closure (v1.0.5)
  - Locking laravel/tinker (v2.6.3)
  - Locking league/commonmark (2.1.1)
  - Locking league/config (v1.1.1)
  - Locking league/flysystem (1.1.9)
  - Locking league/mime-type-detection (1.9.0)
  - Locking mockery/mockery (1.4.4)
  - Locking monolog/monolog (2.3.5)
  - Locking myclabs/deep-copy (1.10.2)
  - Locking nesbot/carbon (2.55.2)
  - Locking nette/schema (v1.2.2)
  - Locking nette/utils (v3.2.6)
  - Locking nikic/php-parser (v4.13.2)
  - Locking nunomaduro/collision (v5.11.0)
  - Locking opis/closure (3.6.2)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.1.0)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.3.0)
  - Locking phpdocumentor/type-resolver (1.6.0)
  - Locking phpoption/phpoption (1.8.1)
  - Locking phpspec/prophecy (v1.15.0)
  - Locking phpunit/php-code-coverage (9.2.10)
  - Locking phpunit/php-file-iterator (3.0.6)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.5.11)
  - Locking psr/container (1.1.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (1.1.4)
  - Locking psr/simple-cache (1.0.1)
  - Locking psy/psysh (v0.10.12)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking ramsey/collection (1.2.2)
  - Locking ramsey/uuid (4.2.3)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.6)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.4)
  - Locking sebastian/environment (5.1.3)
  - Locking sebastian/exporter (4.0.4)
  - Locking sebastian/global-state (5.0.3)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.4)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (2.3.4)
  - Locking sebastian/version (3.0.2)
  - Locking swiftmailer/swiftmailer (v6.3.0)
  - Locking symfony/console (v5.4.2)
  - Locking symfony/css-selector (v5.4.2)
  - Locking symfony/deprecation-contracts (v2.5.0)
  - Locking symfony/error-handler (v5.4.2)
  - Locking symfony/event-dispatcher (v5.4.0)
  - Locking symfony/event-dispatcher-contracts (v2.5.0)
  - Locking symfony/finder (v5.4.2)
  - Locking symfony/http-foundation (v5.4.2)
  - Locking symfony/http-kernel (v5.4.2)
  - Locking symfony/mime (v5.4.2)
  - Locking symfony/polyfill-ctype (v1.24.0)
  - Locking symfony/polyfill-iconv (v1.24.0)
  - Locking symfony/polyfill-intl-grapheme (v1.24.0)
  - Locking symfony/polyfill-intl-idn (v1.24.0)
  - Locking symfony/polyfill-intl-normalizer (v1.24.0)
  - Locking symfony/polyfill-mbstring (v1.24.0)
  - Locking symfony/polyfill-php72 (v1.24.0)
  - Locking symfony/polyfill-php73 (v1.24.0)
  - Locking symfony/polyfill-php80 (v1.24.0)
  - Locking symfony/polyfill-php81 (v1.24.0)
  - Locking symfony/process (v5.4.2)
  - Locking symfony/routing (v5.4.0)
  - Locking symfony/service-contracts (v2.5.0)
  - Locking symfony/string (v5.4.2)
  - Locking symfony/translation (v5.4.2)
  - Locking symfony/translation-contracts (v2.5.0)
  - Locking symfony/var-dumper (v5.4.2)
  - Locking theseer/tokenizer (1.2.1)
  - Locking tijsverkoyen/css-to-inline-styles (2.2.4)
  - Locking vlucas/phpdotenv (v5.4.1)
  - Locking voku/portable-ascii (1.5.6)
  - Locking webmozart/assert (1.10.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 110 installs, 0 updates, 0 removals
  - Downloading nunomaduro/collision (v5.11.0)
  - Installing doctrine/inflector (2.0.4): Extracting archive
  - Installing doctrine/lexer (1.2.1): Extracting archive
  - Installing symfony/polyfill-ctype (v1.24.0): Extracting archive
  - Installing webmozart/assert (1.10.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.2.3): Extracting archive
  - Installing symfony/polyfill-php80 (v1.24.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.24.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.2): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.24.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.24.0): Extracting archive
  - Installing symfony/string (v5.4.2): Extracting archive
  - Installing symfony/deprecation-contracts (v2.5.0): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.0): Extracting archive
  - Installing symfony/polyfill-php73 (v1.24.0): Extracting archive
  - Installing symfony/console (v5.4.2): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing monolog/monolog (2.3.5): Extracting archive
  - Installing voku/portable-ascii (1.5.6): Extracting archive
  - Installing phpoption/phpoption (1.8.1): Extracting archive
  - Installing graham-campbell/result-type (v1.0.4): Extracting archive
  - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
  - Installing symfony/css-selector (v5.4.2): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
  - Installing symfony/routing (v5.4.0): Extracting archive
  - Installing symfony/process (v5.4.2): Extracting archive
  - Installing symfony/polyfill-php72 (v1.24.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.24.0): Extracting archive
  - Installing symfony/mime (v5.4.2): Extracting archive
  - Installing symfony/http-foundation (v5.4.2): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v2.5.0): Extracting archive
  - Installing symfony/event-dispatcher (v5.4.0): Extracting archive
  - Installing symfony/error-handler (v5.4.2): Extracting archive
  - Installing symfony/http-kernel (v5.4.2): Extracting archive
  - Installing symfony/finder (v5.4.2): Extracting archive
  - Installing symfony/polyfill-iconv (v1.24.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
  - Installing symfony/polyfill-php81 (v1.24.0): Extracting archive
  - Installing ramsey/collection (1.2.2): Extracting archive
  - Installing brick/math (0.9.3): Extracting archive
  - Installing ramsey/uuid (4.2.3): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.2): Extracting archive
  - Installing symfony/translation-contracts (v2.5.0): Extracting archive
  - Installing symfony/translation (v5.4.2): Extracting archive
  - Installing nesbot/carbon (2.55.2): Extracting archive
  - Installing league/mime-type-detection (1.9.0): Extracting archive
  - Installing league/flysystem (1.1.9): Extracting archive
  - Installing nette/utils (v3.2.6): Extracting archive
  - Installing nette/schema (v1.2.2): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
  - Installing league/config (v1.1.1): Extracting archive
  - Installing league/commonmark (2.1.1): Extracting archive
  - Installing laravel/serializable-closure (v1.0.5): Extracting archive
  - Installing laravel/framework (v8.78.1): Extracting archive
  - Installing facade/ignition-contracts (1.0.2): Extracting archive
  - Installing facade/flare-client-php (1.9.1): Extracting archive
  - Installing facade/ignition (2.17.4): Extracting archive
  - Installing fakerphp/faker (v1.17.0): Extracting archive
  - Installing asm89/stack-cors (v2.0.5): Extracting archive
  - Installing fruitcake/laravel-cors (v2.0.5): Extracting archive
  - Installing psr/http-message (1.0.1): Extracting archive
  - Installing psr/http-client (1.0.1): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-factory (1.0.1): Extracting archive
  - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
  - Installing guzzlehttp/promises (1.5.1): Extracting archive
  - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
  - Installing laravel/sail (v1.12.12): Extracting archive
  - Installing laravel/sanctum (v2.13.0): Extracting archive
  - Installing nikic/php-parser (v4.13.2): Extracting archive
  - Installing psy/psysh (v0.10.12): Extracting archive
  - Installing laravel/tinker (v2.6.3): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.4.4): Extracting archive
  - Installing filp/whoops (2.14.5): Extracting archive
  - Installing nunomaduro/collision (v5.11.0): Extracting archive
  - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
  - Installing phpdocumentor/type-resolver (1.6.0): Extracting archive
  - Installing phpdocumentor/reflection-docblock (5.3.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (2.3.4): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.4): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.3): Extracting archive
  - Installing sebastian/exporter (4.0.4): Extracting archive
  - Installing sebastian/environment (5.1.3): Extracting archive
  - Installing sebastian/diff (4.0.4): Extracting archive
  - Installing sebastian/comparator (4.0.6): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.10): Extracting archive
  - Installing doctrine/instantiator (1.4.0): Extracting archive
  - Installing phpspec/prophecy (v1.15.0): Extracting archive
  - Installing phar-io/version (3.1.0): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.10.2): Extracting archive
  - Installing phpunit/phpunit (9.5.11): Extracting archive
70 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
> @php artisan key:generate --ansi
Application key set successfully.


3、创建数据库:lighthouse_tutorial,配置 .env 中的数据库连接。运行数据库迁移以创建 users 表


PS E:\wwwroot\lighthouse-tutorial> php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (42.37ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (36.39ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (40.11ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (53.85ms)


4、在数据库中植入一些假的用户数据。factory(‘App\User’, 10)->create(); 在 Laravel 8 已经不可用。需要使用 User::factory()->count(10)->create();。如图1

在数据库中植入一些假的用户数据。factory('App\User', 10)->create(); 在 Laravel 8 已经不可用。需要使用 User::factory()->count(10)->create();

图1


PS E:\wwwroot\lighthouse-tutorial> php artisan tinker
Psy Shell v0.10.12 (PHP 7.4.27 — cli) by Justin Hileman
>>> factory('App\User', 10)->create();
PHP Fatal error:  Call to undefined function factory() in Psy Shell code on line 1
>>> App\Factory('App\User', 10)->create();
PHP Fatal error:  Call to undefined function App\Factory() in Psy Shell code on line 1
>>> User::factory()->count(50)->create();
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#3581
     all: [
       App\Models\User {#3585
         name: "Ashton Tremblay",
         email: "letha42@example.net",
         email_verified_at: "2022-01-12 05:51:41",
         #password: "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
         #remember_token: "k1o1mrmP7o",
         updated_at: "2022-01-12 05:51:41",
         created_at: "2022-01-12 05:51:41",
         id: 1,
       },
       App\Models\User {#3592
         name: "Rene Powlowski",
         email: "hkovacek@example.org",
         email_verified_at: "2022-01-12 05:51:41",
         #password: "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
         #remember_token: "64Cl19QXs3",
         updated_at: "2022-01-12 05:51:41",
         created_at: "2022-01-12 05:51:41",
         id: 2,
       },
	   ...
     ],
   }
>>>                                                                                                                     


5、安装 Lighthouse,将使用 Lighthouse 作为 GraphQL 服务器。


PS E:\wwwroot\lighthouse-tutorial> composer require nuwave/lighthouse
Using version ^5.35 for nuwave/lighthouse
./composer.json has been updated
Running composer update nuwave/lighthouse
Loading composer repositories with package information
Updating dependencies
Lock file operations: 5 installs, 0 updates, 0 removals
  - Locking haydenpierce/class-finder (0.4.3)
  - Locking laragraph/utils (v1.1.1)
  - Locking nuwave/lighthouse (v5.35.0)
  - Locking thecodingmachine/safe (v1.3.3)
  - Locking webonyx/graphql-php (v14.11.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
  - Downloading nuwave/lighthouse (v5.35.0)
  - Installing webonyx/graphql-php (v14.11.3): Extracting archive
  - Installing thecodingmachine/safe (v1.3.3): Extracting archive
  - Installing laragraph/utils (v1.1.1): Extracting archive
  - Installing haydenpierce/class-finder (0.4.3): Extracting archive
  - Installing nuwave/lighthouse (v5.35.0): Extracting archive
6 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: nuwave/lighthouse
Package manifest generated successfully.
79 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
PS E:\wwwroot\lighthouse-tutorial>


6、使用 Altair GraphQL Client 作为 GraphQL 查询的 IDE (在线调试工具)。它就好像 GraphQL 专用的 Postman,拥有很多神奇的功能。在 Chrome 浏览器的网上应用商店中搜索:GraphQL,排名第一的就是。如图2

使用 Altair GraphQL Client 作为 GraphQL 查询的 IDE (在线调试工具)。它就好像 GraphQL 专用的 Postman,拥有很多神奇的功能。在 Chrome 浏览器的网上应用商店中搜索:GraphQL,排名第一的就是。

图2

7、将默认模式发布到 graphql/schema.graphql。报错:No publishable resources for tag [schema].


PS E:\wwwroot\lighthouse-tutorial> php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=schema
No publishable resources for tag [schema].
Publishing complete.
PS E:\wwwroot\lighthouse-tutorial>


8、建议参考英文的最新文档:https://lighthouse-php.com/tutorial 。将默认模式发布到 graphql/schema.graphql。发布完成。


PS E:\wwwroot\lighthouse-tutorial> php artisan vendor:publish --tag=lighthouse-schema
Copied File [\vendor\nuwave\lighthouse\src\default-schema.graphql] To [\graphql\schema.graphql]
Publishing complete.
PS E:\wwwroot\lighthouse-tutorial>


9、在 Nginx 中配置虚拟主机:lighthouse-tutorial.local 。在 Altair GraphQL Client 中打开网址:http://lighthouse-tutorial.local/graplql 。如图3

在 Nginx 中配置虚拟主机:lighthouse-tutorial.local 。在 Altair GraphQL Client 中打开网址:http://lighthouse-tutorial.local/graplql

图3


server {
    listen 80;
    server_name lighthouse-tutorial.local;
    root E:/wwwroot/lighthouse-tutorial/public;

	access_log  logs/lighthouse-tutorial.local.access.log;
    error_log   logs/lighthouse-tutorial.local.error.log;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
		fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}


请求:



query{
  user(id: 1){
    id
    name
    email
    created_at
    updated_at
  }
}


响应:


{
  "data": {
    "user": {
      "id": "1",
      "name": "Ashton Tremblay",
      "email": "letha42@example.net",
      "created_at": "2022-01-12 05:51:41",
      "updated_at": "2022-01-12 05:51:41"
    }
  }
}


10、为我们的 posts 和 comments 定义模型和迁移。运行迁移。将 posts 模型添加到 app/User.php。

11、The Schema,修改 graphql/schema.graphql 并根据我们创建的有说服力的模型来定义我们的 posts 的模式。我们添加了两个用于查询文章到 Query 类型的最后面。 @all 返回所有内容的列表 Post 模型 。 @find 和 @eq 是通过其 ID 组合检索单个 Post。我们还可以通过添加额外的类型定义,明确定义我们的数据模型。如图4

我们还可以通过添加额外的类型定义,明确定义我们的数据模型。

图4


"A date string with format `Y-m-d`, e.g. `2011-05-23`."
scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")

"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")

type Query {
    users: [User!]! @paginate(defaultCount: 10)
    user(id: ID @eq): User @find
    posts: [Post!]! @all
    post(id: Int! @eq): Post @find
}

type User {
    id: ID!
    name: String!
    email: String!
    created_at: DateTime!
    updated_at: DateTime!
    posts: [Post!]! @hasMany
}

type Post {
    id: ID!
    title: String!
    content: String!
    author: User! @belongsTo
    comments: [Comment!]! @hasMany
}

type Comment {
    id: ID!
    reply: String!
    post: Post! @belongsTo
}



12、最终测试,在你的数据库中插入一些假数据,你可以使用 Laravel seeders 来完成。编辑模型工厂文件:database/factories/PostFactory.php、database/factories/CommentFactory.php。
database/factories/PostFactory.php

<?php
 
namespace Database\Factories;
 
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Post;
 
class PostFactory extends Factory
{
    protected $model = Post::class;
 
    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $sentence = $this->faker->sentence();
 
        return [
            'author_id' => rand(1, 100),
            'title' => $sentence,
            'content' => $this->faker->text(),
        ];
    }
}

database/factories/CommentFactory.php

<?php
 
namespace Database\Factories;
 
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Comment;
 
class CommentFactory extends Factory
{
    protected $model = Comment::class;
 
    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'post_id' => rand(1, 100),
            'reply' => $this->faker->sentence(),
        ];
    }
}

13、完成数据工厂的定制后,接下来我们开始书写填充部分。编辑数据填充文件:database/seeders/UsersTableSeeder.php、database/seeders/PostsTableSeeder.php、database/seeders/CommentsTableSeeder.php。
database/seeders/UsersTableSeeder.php

<?php
 
namespace Database\Seeders;
 
use Illuminate\Database\Seeder;
use App\Models\User;
 
class UsersTableSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        User::factory()->count(100)->create();
    }
}

database/seeders/PostsTableSeeder.php

<?php
 
namespace Database\Seeders;
 
use Illuminate\Database\Seeder;
use App\Models\Post;
 
class PostsTableSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        Post::factory()->count(100)->create();
    }
}

database/seeders/CommentsTableSeeder.php

<?php
 
namespace Database\Seeders;
 
use Illuminate\Database\Seeder;
use App\Models\Comment;
 
class CommentsTableSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        Comment::factory()->count(100)->create();
    }
}

14、注册数据填充。编辑 database/seeders/DatabaseSeeder.php

<?php
 
namespace Database\Seeders;
 
use Illuminate\Database\Seeder;
 
class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UsersTableSeeder::class);
        $this->call(PostsTableSeeder::class);
        $this->call(CommentsTableSeeder::class);
    }
}
 

15、执行数据填充命令:php artisan migrate:refresh –seed,报错:Call to undefined method App\Models\Post::factory()。如图5

执行数据填充命令:php artisan migrate:refresh --seed,报错:Call to undefined method App\Models\Post::factory()

图5


PS E:\wwwroot\lighthouse-tutorial> php artisan migrate:refresh --seed
Rolling back: 2022_01_12_062416_create_comments_table
Rolled back:  2022_01_12_062416_create_comments_table (16.76ms)
Rolling back: 2022_01_12_062104_create_posts_table
Rolled back:  2022_01_12_062104_create_posts_table (8.20ms)
Rolling back: 2019_12_14_000001_create_personal_access_tokens_table
Rolled back:  2019_12_14_000001_create_personal_access_tokens_table (9.17ms)
Rolling back: 2019_08_19_000000_create_failed_jobs_table
Rolled back:  2019_08_19_000000_create_failed_jobs_table (8.87ms)
Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back:  2014_10_12_100000_create_password_resets_table (9.72ms)
Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table (7.01ms)
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (28.61ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (31.30ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (31.69ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (39.67ms)
Migrating: 2022_01_12_062104_create_posts_table
Migrated:  2022_01_12_062104_create_posts_table (17.16ms)
Migrating: 2022_01_12_062416_create_comments_table
Migrated:  2022_01_12_062416_create_comments_table (20.25ms)
Seeding: Database\Seeders\UsersTableSeeder
Seeded:  Database\Seeders\UsersTableSeeder (1,839.80ms)
Seeding: Database\Seeders\PostsTableSeeder

   BadMethodCallException

  Call to undefined method App\Models\Post::factory()

  at E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:71
     67▕      * @throws \BadMethodCallException
     68▕      */
     69▕     protected static function throwBadMethodCallException($method)
     70▕     {
  ➜  71▕         throw new BadMethodCallException(sprintf(
     72▕             'Call to undefined method %s::%s()', static::class, $method
     73▕         ));
     74▕     }
     75▕ }

  • Bad Method Call: Did you mean App\Models\Post::author() ?

  1   E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:36
      Illuminate\Database\Eloquent\Model::throwBadMethodCallException("factory")

  2   E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:2132
      Illuminate\Database\Eloquent\Model::forwardCallTo(Object(Illuminate\Database\Eloquent\Builder), "factory", [])
PS E:\wwwroot\lighthouse-tutorial>


16、编辑数据模型文件,app/Models/Post.php、app/Models/Comment.php,引入 HasFactory。
app/Models/Post.php

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
class Post extends Model
{
    use HasFactory;
 
    public function author(): BelongsTo
    {
        return $this->belongsTo(User::class, 'author_id');
    }
 
    public function comments(): HasMany
    {
        return $this->hasMany(Comment::class);
    }
}

app/Models/Comment.php

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
class Comment extends Model
{
    use HasFactory;
 
    public function post(): BelongsTo
    {
        return $this->belongsTo(Post::class);
    }
}

17、执行数据填充成功后,访问 /graphql 并尝试以下的查询。获取到数据库中所有 posts 的列表,以及全部 comments 和 user 的 name。符合预期。如图6

执行数据填充成功后,访问 /graphql 并尝试以下的查询。获取到数据库中所有 posts 的列表,以及全部 comments 和 user 的 name。符合预期

图6


请求:


query {
  posts {
    id
    title
    author {
      name
    }
    comments {
      id
      reply
    }
  }
}


响应:


{
  "data": {
    "posts": [
      {
        "id": "1",
        "title": "Optio earum deserunt fuga qui quia hic.",
        "author": {
          "name": "Mrs. Lottie Kuhlman IV"
        },
        "comments": []
      },
      {
        "id": "2",
        "title": "Soluta eius quisquam consequatur accusantium distinctio minima.",
        "author": {
          "name": "Otilia Marvin"
        },
        "comments": []
      },
      {
        "id": "3",
        "title": "Unde harum commodi rerum nam dolores vel eligendi.",
        "author": {
          "name": "Alfreda Crooks"
        },
        "comments": [
          {
            "id": "14",
            "reply": "Laborum exercitationem odit voluptas cumque adipisci."
          }
        ]
      },
      {
        "id": "4",
        "title": "Praesentium iste nisi aut reprehenderit aliquam.",
        "author": {
          "name": "Hassan Goyette MD"
        },
        "comments": []
      },
      {
        "id": "5",
        "title": "Atque illo consequatur eveniet.",
        "author": {
          "name": "Estevan Mann"
        },
        "comments": []
      },
      {
        "id": "6",
        "title": "Praesentium et eaque soluta.",
        "author": {
          "name": "Prof. Rosalia Cartwright Sr."
        },
        "comments": [
          {
            "id": "5",
            "reply": "Omnis doloremque tempore ut laboriosam nihil."
          }
        ]
      },
      {
        "id": "7",
        "title": "Assumenda consequatur quo perspiciatis reiciendis.",
        "author": {
          "name": "Nestor Bauch"
        },
        "comments": [
          {
            "id": "70",
            "reply": "Error quia natus inventore aliquid praesentium et."
          }
        ]
      },
      {
        "id": "8",
        "title": "Nesciunt eos enim minus ipsa non sed minus.",
        "author": {
          "name": "Reggie Batz"
        },
        "comments": [
          {
            "id": "22",
            "reply": "Magnam et cum reiciendis et."
          }
        ]
      },
      {
        "id": "9",
        "title": "In et quasi dolorem aliquam nemo sequi.",
        "author": {
          "name": "Carroll Cartwright"
        },
        "comments": [
          {
            "id": "73",
            "reply": "Cumque harum id officiis eum cumque."
          }
        ]
      },
      {
        "id": "10",
        "title": "Consequatur modi enim fugit ut eos.",
        "author": {
          "name": "Kiley Connelly"
        },
        "comments": [
          {
            "id": "71",
            "reply": "Aut harum fuga quos veniam quia perspiciatis."
          },
          {
            "id": "90",
            "reply": "Harum unde debitis sunt sint tenetur temporibus voluptates."
          }
        ]
      },
	  ...
    ]
  }
}


18、随机选择 posts 的 id 等于 10 的数据验证,响应与数据库中一致。如图7

随机选择 posts 的 id 等于 10 的数据验证,响应与数据库中一致。

图7

]]>
https://www.shuijingwanwq.com/2022/01/24/5802/feed/ 0