部署 Shopify PHP 主题应用扩展至生产环境的应用中(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7)
1、参考:部署 Shopify PHP 应用至生产环境(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7)
2、当在应用: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
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
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/web$ composer install
10、启用开发商店预览后,执行 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
12、重新运行开发(重新配置)命令。在执行过程中,存在: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
14、创建主题应用扩展的版本并发布:1.0.0。如图8
15、打开店铺:shuijingwanwq-development3 的任一主题的编辑器,可通过添加应用块的方式,使用主题应用扩展。如图9
16、查看首页,主题应用扩展已经显示。如图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
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
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












近期评论