Laravel Sail – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Fri, 15 May 2026 14:28:59 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 执行命令:sail artisan migrate 时,报错:In Filesystem.php line 207: chmod(): Operation not permitted https://www.shuijingwanwq.com/2022/01/04/5671/ https://www.shuijingwanwq.com/2022/01/04/5671/#respond Tue, 04 Jan 2022 01:50:50 +0000 https://www.shuijingwanwq.com/?p=5671 浏览量: 126 1、执行命令:sail artisan migrate 时,报错:chmod(): Operation not permitted。如图1
执行命令:sail artisan migrate 时,报错:chmod(): Operation not permitted。

图1



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail artisan migrate

In Filesystem.php line 207:

  chmod(): Operation not permitted


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


2、运行以下命令进行重新加载文件:sail composer dump-autoload,报错:In Filesystem.php line 207: chmod(): Operation not permitted。Script @php artisan package:discover –ansi handling the post-autoload-dump event returned with error code 1。如图2
运行以下命令进行重新加载文件:sail composer dump-autoload,报错:In Filesystem.php line 207:  chmod(): Operation not permitted。Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1。

图2



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail composer dump-autoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In Filesystem.php line 207:

  chmod(): Operation not permitted


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


3、通过 sail up -d 重新启动 Sail。如图3
通过 sail up -d 重新启动 Sail。

图3



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail up
[+] Running 6/6
 ⠿ Container weibo_meilisearch_1   Running                                                                         0.0s
 ⠿ Container weibo_redis_1         Running                                                                         0.0s
 ⠿ Container weibo_mailhog_1       Running                                                                         0.0s
 ⠿ Container weibo_selenium_1      Running                                                                         0.0s
 ⠿ Container weibo_mysql_1         Running                                                                         0.0s
 ⠿ Container weibo_laravel.test_1  Recreated                                                                      10.8s
Attaching to laravel.test_1, mailhog_1, meilisearch_1, mysql_1, redis_1, selenium_1
laravel.test_1  | 2021-12-27 01:47:52,236 INFO Set uid to user 0 succeeded
laravel.test_1  | 2021-12-27 01:47:52,240 INFO supervisord started with pid 17
laravel.test_1  | 2021-12-27 01:47:53,246 INFO spawned: 'php' with pid 18
laravel.test_1  | 2021-12-27 01:47:54,250 INFO success: php entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
laravel.test_1  | Starting Laravel development server: http://0.0.0.0:80
laravel.test_1  | [Mon Dec 27 01:47:57 2021] PHP 8.1.0 Development Server (http://0.0.0.0:80) started
meilisearch_1   | [2021-12-27T01:48:07Z INFO  actix_web::middleware::logger] 127.0.0.1:34400 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000048
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:48:37Z INFO  actix_web::middleware::logger] 127.0.0.1:34404 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000344
meilisearch_1   | [2021-12-27T01:49:08Z INFO  actix_web::middleware::logger] 127.0.0.1:34408 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000050
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:49:38Z INFO  actix_web::middleware::logger] 127.0.0.1:34412 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000054
meilisearch_1   | [2021-12-27T01:50:08Z INFO  actix_web::middleware::logger] 127.0.0.1:34418 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000053
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:50:38Z INFO  actix_web::middleware::logger] 127.0.0.1:34422 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000048
meilisearch_1   | [2021-12-27T01:51:08Z INFO  actix_web::middleware::logger] 127.0.0.1:34424 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000050
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:51:39Z INFO  actix_web::middleware::logger] 127.0.0.1:34428 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000063
meilisearch_1   | [2021-12-27T01:52:09Z INFO  actix_web::middleware::logger] 127.0.0.1:34434 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000052
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:52:39Z INFO  actix_web::middleware::logger] 127.0.0.1:34438 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000119
meilisearch_1   | [2021-12-27T01:53:09Z INFO  actix_web::middleware::logger] 127.0.0.1:34442 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000048
mailhog_1       | [APIv1] KEEPALIVE /api/v1/events
meilisearch_1   | [2021-12-27T01:53:39Z INFO  actix_web::middleware::logger] 127.0.0.1:34446 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000054
^CGracefully stopping... (press Ctrl+C again to force)
[+] Running 6/6
 ⠿ Container weibo_laravel.test_1  Stopped                                                                        10.7s
 ⠿ Container weibo_mailhog_1       Stopped                                                                         0.8s
 ⠿ Container weibo_redis_1         Stopped                                                                         0.8s
 ⠿ Container weibo_selenium_1      Stopped                                                                         4.7s
 ⠿ Container weibo_mysql_1         Stopped                                                                         1.4s
 ⠿ Container weibo_meilisearch_1   Stopped                                                                         0.7s
canceled
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail up -d
[+] Running 6/6
 ⠿ Container weibo_mysql_1         Started                                                                         4.3s
 ⠿ Container weibo_selenium_1      Started                                                                         3.3s
 ⠿ Container weibo_meilisearch_1   Started                                                                         3.8s
 ⠿ Container weibo_redis_1         Started                                                                         2.9s
 ⠿ Container weibo_laravel.test_1  Started                                                                         6.5s
 ⠿ Container weibo_mailhog_1       Started                                                                         3.6s
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


4、再次执行命令:sail artisan migrate 时,不再报错。如图4
再次执行命令:sail artisan migrate 时,不再报错。

图4



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail artisan migrate
Migrating: 2021_12_27_013012_create_statuses_table
Migrated:  2021_12_27_013012_create_statuses_table (199.83ms)
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


]]>
https://www.shuijingwanwq.com/2022/01/04/5671/feed/ 0
Laravel 8.x 部署至 Heroku,执行数据库数据填充时,报错:Class “Faker\Factory” not found https://www.shuijingwanwq.com/2021/12/31/5665/ https://www.shuijingwanwq.com/2021/12/31/5665/#respond Fri, 31 Dec 2021 07:27:42 +0000 https://www.shuijingwanwq.com/?p=5665 浏览量: 97 1、Laravel 8.x 部署至 Heroku,执行数据库数据填充时,报错:Class “Faker\Factory” not found。如图1
Laravel 8.x 部署至 Heroku,执行数据库数据填充时,报错:Class "Faker\Factory" not found。

图1



PS E:\wwwroot\weibo> heroku run php artisan migrate:refresh --seed
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate:refresh --seed on ⬢ app-wangqiang-weibo... up, run.5843 (Free)
**************************************
*     Application In Production!     *
**************************************

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

Rolling back: 2021_12_24_062642_add_is_admin_to_users_table
Rolled back:  2021_12_24_062642_add_is_admin_to_users_table (18.92ms)
Rolling back: 2019_12_14_000001_create_personal_access_tokens_table
Rolling back: 2019_08_19_000000_create_failed_jobs_table
Rolled back:  2019_08_19_000000_create_failed_jobs_table (25.62ms)
Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back:  2014_10_12_100000_create_password_resets_table (10.26ms)
Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table (26.54ms)
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (46.62ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (17.96ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (29.18ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (28.13ms)
Migrating: 2021_12_24_062642_add_is_admin_to_users_table
Migrated:  2021_12_24_062642_add_is_admin_to_users_table (7.20ms)
Seeding: Database\Seeders\UsersTableSeeder

In DatabaseServiceProvider.php line 91:

  Class "Faker\Factory" not found




2、编辑 composer.json ,将 “require-dev” 中的 “fakerphp/faker” 复制到 “require” 里面。如图2
编辑  composer.json ,将 "require-dev" 中的 "fakerphp/faker" 复制到 "require" 里面。

图2



    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.65",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5",
        "overtrue/laravel-lang": "~4.0",
        "fakerphp/faker": "^1.9.1"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "laravel/ui": "^3.0",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },


3、如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令:sail composer update。如图3
如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令:sail composer update。

图3



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 3 updates, 0 removals
  - Upgrading facade/ignition (2.17.2 => 2.17.3)
  - Upgrading laravel/framework (v8.76.2 => v8.77.1)
  - Upgrading laravel/ui (v3.4.0 => v3.4.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 3 updates, 0 removals
  - Downloading laravel/framework (v8.77.1)
  - Downloading facade/ignition (2.17.3)
  - Downloading laravel/ui (v3.4.1)
  - Upgrading laravel/framework (v8.76.2 => v8.77.1): Extracting archive
  - Upgrading facade/ignition (2.17.2 => 2.17.3): Extracting archive
  - Upgrading laravel/ui (v3.4.0 => v3.4.1): 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: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
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.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail 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: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Package manifest generated successfully.
Generated optimized autoload files containing 5031 classes
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


4、再次推送至 Heroku,执行填充,不再报错。如图4
再次推送至 Heroku,执行填充,不再报错。

图4



PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 735 bytes | 735.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 73 installs, 0 updates, 0 removals
remote:          - Downloading fakerphp/faker (v1.17.0)
remote:          - Downloading laravel/framework (v8.77.1)
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing fakerphp/faker (v1.17.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.77.1): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:          - Installing laravel-lang/lang (5.0.0): Extracting archive
remote:          - Installing overtrue/laravel-lang (4.2.2): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Discovered Package: overtrue/laravel-lang
remote:        Package manifest generated successfully.
remote:        50 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 23.2M
remote: -----> Launching...
remote:        Released v20
remote:        https://app-wangqiang-weibo.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/app-wangqiang-weibo.git
   626a3e3..f5fb1ef  main -> main
PS E:\wwwroot\weibo> heroku run php artisan migrate:refresh --seed
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate:refresh --seed on ⬢ app-wangqiang-weibo... up, run.2437 (Free)
**************************************
*     Application In Production!     *
**************************************

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

Rolling back: 2021_12_24_062642_add_is_admin_to_users_table
Rolled back:  2021_12_24_062642_add_is_admin_to_users_table (10.82ms)
Rolling back: 2019_12_14_000001_create_personal_access_tokens_table
Rolled back:  2019_12_14_000001_create_personal_access_tokens_table (15.24ms)
Rolling back: 2019_08_19_000000_create_failed_jobs_table
Rolled back:  2019_08_19_000000_create_failed_jobs_table (11.88ms)
Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back:  2014_10_12_100000_create_password_resets_table (10.93ms)
Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table (12.13ms)
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (32.83ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (16.75ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (23.02ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (24.03ms)
Migrating: 2021_12_24_062642_add_is_admin_to_users_table
Migrated:  2021_12_24_062642_add_is_admin_to_users_table (6.28ms)
Seeding: Database\Seeders\UsersTableSeeder
Seeded:  Database\Seeders\UsersTableSeeder (827.06ms)
Database seeding completed successfully.
PS E:\wwwroot\weibo>


 ]]>
https://www.shuijingwanwq.com/2021/12/31/5665/feed/ 0
Laravel 8.x 部署至 Heroku,基于 PostgreSQL 实现 https://www.shuijingwanwq.com/2021/12/29/5622/ https://www.shuijingwanwq.com/2021/12/29/5622/#respond Wed, 29 Dec 2021 11:20:55 +0000 https://www.shuijingwanwq.com/?p=5622 浏览量: 114 1、在本地开发环境中,基于 Laravel Sail 已经部署完毕。打开网址:http://weibo.test/ ,响应 200。如图1
在本地开发环境中,基于 Laravel Sail 已经部署完毕。打开网址:http://weibo.test/ ,响应 200。

图1

2、注册一个 Heroku 账号,使用 @163.com ,发现不被允许,最后使用 @gmail.com,才注册成功。如图2
注册一个 Heroku 账号,使用 @163.com ,发现不被允许,最后使用 @gmail.com,才注册成功。

图2

3、在邮箱 @gmail.com 中点击链接以激活帐户。如图3
在邮箱 @gmail.com 中点击链接以激活帐户。

图3

4、参考网址:https://devcenter.heroku.com/articles/heroku-cli 。Heroku 命令行界面 (CLI) 使直接从终端创建和管理 Heroku 应用程序变得容易。 这是使用 Heroku 的重要组成部分。 5、在 WSL2 中的 Ubuntu 系统中,从终端运行以下命令。报错:error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory。如图4
在 WSL2 中的 Ubuntu 系统中,从终端运行以下命令。报错:error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory。

图4



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sudo snap install --classic heroku
error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory


6、最终决定使用 Windows 下的软件。为您的 Windows 安装下载合适的安装程序。如图5
最终决定使用 Windows 下的软件。为您的 Windows 安装下载合适的安装程序。

图5

7、安装过程中报错:Error opening file for writing。如图6
安装过程中报错:Error opening file for writing。

图6



Error opening file for writing:

D:\Program Files\heroku\client\bin\node.exe

Click Abort to stop the installation,
Retry to try again, or
Ignore to skip this file.


8、重新安装,以管理员身份运行,不再报错。 9、验证您的安装,要验证您的 CLI 安装,请使用 heroku –version 命令。已经成功安装。如图7
验证您的安装,要验证您的 CLI 安装,请使用 heroku --version 命令。已经成功安装。

图7



PS C:\Users\Lenovo> heroku --version
 »   Warning: Our terms of service have changed: https://dashboard.heroku.com/terms-of-service
heroku/7.53.0 win32-x64 node-v12.21.0
PS C:\Users\Lenovo>


10、安装 CLI 后,运行 heroku login 命令。 系统会提示您输入任意键以转到 Web 浏览器以完成登录。 然后 CLI 会自动让您登录。如图8
安装 CLI 后,运行 heroku login 命令。 系统会提示您输入任意键以转到 Web 浏览器以完成登录。 然后 CLI 会自动让您登录。

图8



PS C:\Users\Lenovo> heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/056bdba3-dbeb-43ee-9ffc-9556ce91ee23?requestor=SFMyNTY.g2gDbQAAAA42Ni4xNzUuMjE2LjIzOW4GAMhVMuV9AWIAAVGA.7UEaCXMegvnax1AIZ5H_XignHykfVPEHFYcOP0NL2uI
Logging in... done
Logged in as shuijingwanwq@gmail.com
PS C:\Users\Lenovo>


11、参考网址:https://devcenter.heroku.com/articles/getting-started-with-php 。因为文档假设 PHP 与 Composer 安装在本地。由于本地环境的 PHP 版本与 Laravel Sail 环境中的版本不一致,决定先将本地环境的 PHP 版本升级至 PHP 8.1。如图9、图10
因为文档假设 PHP 与 Composer 安装在本地。

图9

 
由于本地环境的 PHP 版本与 Laravel Sail 环境中的版本不一致,决定先将本地环境的 PHP 版本升级至 PHP 8.1。

图10

本地环境的版本号:


PS C:\Users\Lenovo> php -v
PHP 7.4.27 (cli) (built: Dec 14 2021 19:52:13) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
PS C:\Users\Lenovo> composer -V
Composer version 2.1.14 2021-11-30 10:51:43
PS C:\Users\Lenovo>


Laravel Sail 环境的版本号:


# php -v
PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
# composer -V
Composer version 2.1.14 2021-11-30 10:51:43
#


12、升级后的本地环境的 PHP 版本,PHP 8.1.1。


PS C:\Users\Lenovo> php -v
PHP 8.1.1 (cli) (built: Dec 15 2021 10:31:43) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
PS C:\Users\Lenovo>


13、进入程序根目录,使用 heroku create 命令在 Heroku 上创建一个新应用。secret-stream-72395 是 Heroku 随机为应用生成的默认名称,每个人生成的名称都不相同。而 https://secret-stream-72395.herokuapp.com/ 则是应用的线上地址。如图11
进入程序根目录,使用 heroku create 命令在 Heroku 上创建一个新应用。secret-stream-72395 是 Heroku 随机为应用生成的默认名称,每个人生成的名称都不相同。而 https://secret-stream-72395.herokuapp.com/ 则是应用的线上地址。

图11



PS E:\wwwroot> cd .\weibo\
PS E:\wwwroot\weibo> heroku create
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Creating app... done, ⬢ secret-stream-72395
https://secret-stream-72395.herokuapp.com/ | https://git.heroku.com/secret-stream-72395.git
PS E:\wwwroot\weibo>


14、Heroku 平台支持多种语言,在进行应用部署时,Heroku 会自动检查应用的代码是用什么语言写的,然后再接着执行一系列针对该语言的操作来准备好程序运行环境。Laravel 应用默认会包含 package.json 文件,但当 Heroku 检查到该文件时,它会认为此应用是用 Node.js 写的,因此我们需要对应用的 buildpack 进行声明,告诉 Heroku 说我们的应用是用 PHP 写的。如图12
对应用的 buildpack 进行声明,告诉 Heroku 说我们的应用是用 PHP 写的

图12



PS E:\wwwroot\weibo> heroku buildpacks:set heroku/php
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Buildpack set. Next release on secret-stream-72395 will use heroku/php.
Run git push heroku main to create a new release using this buildpack.
PS E:\wwwroot\weibo>


15、将代码推送和部署到 Heroku 上。如图13
将代码推送和部署到 Heroku 上

图13

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

PS E:\wwwroot\weibo> git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   docker-compose.yml

PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 195, done.
Counting objects: 100% (195/195), done.
Delta compression using up to 4 threads
Compressing objects: 100% (169/169), done.
Writing objects: 100% (195/195), 651.34 KiB | 1.41 MiB/s, done.
Total 195 (delta 47), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Downloading doctrine/inflector (2.0.4)
remote:          - Downloading doctrine/lexer (1.2.1)
remote:          - Downloading symfony/polyfill-ctype (v1.23.0)
remote:          - Downloading webmozart/assert (1.10.0)
remote:          - Downloading dragonmantank/cron-expression (v3.1.0)
remote:          - Downloading symfony/polyfill-php80 (v1.23.1)
remote:          - Downloading symfony/polyfill-php73 (v1.23.0)
remote:          - Downloading symfony/polyfill-mbstring (v1.23.1)
remote:          - Downloading symfony/deprecation-contracts (v3.0.0)
remote:          - Downloading symfony/http-foundation (v5.4.1)
remote:          - Downloading psr/event-dispatcher (1.0.0)
remote:          - Downloading symfony/event-dispatcher-contracts (v3.0.0)
remote:          - Downloading symfony/event-dispatcher (v6.0.1)
remote:          - Downloading symfony/var-dumper (v5.4.1)
remote:          - Downloading psr/log (2.0.0)
remote:          - Downloading symfony/error-handler (v5.4.1)
remote:          - Downloading symfony/http-kernel (v5.4.1)
remote:          - Downloading voku/portable-ascii (1.5.6)
remote:          - Downloading phpoption/phpoption (1.8.1)
remote:          - Downloading graham-campbell/result-type (v1.0.4)
remote:          - Downloading vlucas/phpdotenv (v5.4.1)
remote:          - Downloading symfony/css-selector (v6.0.1)
remote:          - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
remote:          - Downloading symfony/routing (v5.4.0)
remote:          - Downloading symfony/process (v5.4.0)
remote:          - Downloading symfony/polyfill-php72 (v1.23.0)
remote:          - Downloading symfony/polyfill-intl-normalizer (v1.23.0)
remote:          - Downloading symfony/polyfill-intl-idn (v1.23.0)
remote:          - Downloading symfony/mime (v5.4.0)
remote:          - Downloading symfony/finder (v5.4.0)
remote:          - Downloading symfony/polyfill-intl-grapheme (v1.23.1)
remote:          - Downloading symfony/string (v6.0.1)
remote:          - Downloading psr/container (1.1.2)
remote:          - Downloading symfony/service-contracts (v2.4.1)
remote:          - Downloading symfony/console (v5.4.1)
remote:          - Downloading symfony/polyfill-iconv (v1.23.0)
remote:          - Downloading egulias/email-validator (2.1.25)
remote:          - Downloading swiftmailer/swiftmailer (v6.3.0)
remote:          - Downloading symfony/polyfill-php81 (v1.23.0)
remote:          - Downloading ramsey/collection (1.2.2)
remote:          - Downloading brick/math (0.9.3)
remote:          - Downloading ramsey/uuid (4.2.3)
remote:          - Downloading psr/simple-cache (1.0.1)
remote:          - Downloading opis/closure (3.6.2)
remote:          - Downloading symfony/translation-contracts (v3.0.0)
remote:          - Downloading symfony/translation (v6.0.1)
remote:          - Downloading nesbot/carbon (2.55.2)
remote:          - Downloading monolog/monolog (2.3.5)
remote:          - Downloading league/mime-type-detection (1.9.0)
remote:          - Downloading league/flysystem (1.1.9)
remote:          - Downloading nette/utils (v3.2.6)
remote:          - Downloading nette/schema (v1.2.2)
remote:          - Downloading dflydev/dot-access-data (v3.0.1)
remote:          - Downloading league/config (v1.1.1)
remote:          - Downloading league/commonmark (2.1.0)
remote:          - Downloading laravel/serializable-closure (v1.0.5)
remote:          - Downloading laravel/framework (v8.76.2)
remote:          - Downloading asm89/stack-cors (v2.0.3)
remote:          - Downloading fruitcake/laravel-cors (v2.0.4)
remote:          - Downloading psr/http-message (1.0.1)
remote:          - Downloading psr/http-client (1.0.1)
remote:          - Downloading ralouphie/getallheaders (3.0.3)
remote:          - Downloading psr/http-factory (1.0.1)
remote:          - Downloading guzzlehttp/psr7 (2.1.0)
remote:          - Downloading guzzlehttp/promises (1.5.1)
remote:          - Downloading guzzlehttp/guzzle (7.4.1)
remote:          - Downloading laravel/sanctum (v2.13.0)
remote:          - Downloading nikic/php-parser (v4.13.2)
remote:          - Downloading psy/psysh (v0.10.12)
remote:          - Downloading laravel/tinker (v2.6.3)
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote:        NOTICE: No Procfile, using 'web: heroku-php-apache2'.
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.8M
remote: -----> Launching...
remote:        Released v3
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
 * [new branch]      main -> main
PS E:\wwwroot\weibo>

</pre>
16、应用程序现已部署。 确保至少有一个应用实例正在运行,现在通过应用程序名称生成的 URL 访问该应用程序。 作为一个方便的快捷方式,您可以按如下方式打开网站。如图14
应用程序现已部署。 确保至少有一个应用实例正在运行,现在通过应用程序名称生成的 URL 访问该应用程序。 作为一个方便的快捷方式,您可以按如下方式打开网站。

图14



PS E:\wwwroot\weibo> heroku ps:scale web=1
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Scaling dynos... done, now running web at 1:Free
PS E:\wwwroot\weibo> heroku open
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
PS E:\wwwroot\weibo>


17、但是,在浏览器中自动打开网站:https://secret-stream-72395.herokuapp.com/ ,响应 403。如图15
但是,在浏览器中自动打开网站:https://secret-stream-72395.herokuapp.com/ ,响应 403。

图15



Forbidden
You don't have permission to access this resource.


18、在步骤 15 中提示:No Procfile, using ‘web: heroku-php-apache2’。Laravel 项目下新建一个 Procfile 文件,通过配置该文件来告诉 Heroku 应当使用什么命令来启动 Web 服务器。接着还需要将该文件纳入到 Git 版本控制中。报错:Push failed: cannot parse Procfile.。如图16
报错:Push failed: cannot parse Procfile.

图16



PS E:\wwwroot\weibo> echo web: vendor/bin/heroku-php-apache2 public/ > Procfile
PS E:\wwwroot\weibo> git add -A
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main 64256ed] Procfile for Heroku
 2 files changed, 6 insertions(+), 6 deletions(-)
 create mode 100644 Procfile
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 496 bytes | 496.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:
remote:  !     Push failed: cannot parse Procfile.
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see https://help.heroku.com/ and provide Request ID f09b381f-8217-327d-d121-119f1e8d0c31.
remote:
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to secret-stream-72395.
remote:
To https://git.heroku.com/secret-stream-72395.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/secret-stream-72395.git'
PS E:\wwwroot\weibo>


19、查看文件 Procfile 的内容,如图17
查看文件 Procfile 的内容

图17



web:
vendor/bin/heroku-php-apache2
public/



20、参考 Getting Started with Laravel on Heroku:https://devcenter.heroku.com/articles/getting-started-with-laravel 。查看文件 Procfile 的内容,如图18
参考 Getting Started with Laravel on Heroku:https://devcenter.heroku.com/articles/getting-started-with-laravel 。查看文件 Procfile 的内容

图18



PS E:\wwwroot\weibo> echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
PS E:\wwwroot\weibo> git add .
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main a30f3dd] Procfile for Heroku
 1 file changed, 0 insertions(+), 0 deletions(-)


21、设置 Laravel 加密密钥,使用 Laravel 自带的 artisan 命令来生成 App Key。如图19
设置 Laravel 加密密钥,使用 Laravel 自带的 artisan 命令来生成 App Key。

图19



PS E:\wwwroot\weibo> php artisan key:generate --show
base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
PS E:\wwwroot\weibo>


22、基于生成的 App Key ,运行该命令行来完成配置。如图20
基于生成的 App Key ,运行该命令行来完成配置。

图20



PS E:\wwwroot\weibo> heroku config:set APP_KEY=base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Setting APP_KEY and restarting ⬢ secret-stream-72395... done, v4
APP_KEY: base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
PS E:\wwwroot\weibo>


23、推送时,仍然报错:Push failed: cannot parse Procfile.
<pre class="wp-block-syntaxhighlighter-code">

PS E:\wwwroot\weibo> git push heroku main:main
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (17/17), 1.59 KiB | 542.00 KiB/s, done.
Total 17 (delta 8), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:
remote:  !     Push failed: cannot parse Procfile.
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see https://help.heroku.com/ and provide Request ID 691561db-a116-53f5-a4e5-0100a3777ce9.
remote:
remote:
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: a30f3dde79d674408b2fb440cda5f9dbeb2204fe
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version a30f3dde79d674408b2fb440cda5f9dbeb2204fe
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to secret-stream-72395.
remote:
To https://git.heroku.com/secret-stream-72395.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/secret-stream-72395.git'
PS E:\wwwroot\weibo>

</pre>
24、将文件编码另存为 UTF-8 。如图21
将文件编码另存为 UTF-8 。

图21

25、推送成功,且打开网址:https://secret-stream-72395.herokuapp.com/ ,响应 200。如图22
推送成功,且打开网址:https://secret-stream-72395.herokuapp.com/ ,响应 200。

图22



PS E:\wwwroot\weibo> git add .
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main 362c878] Procfile for Heroku
 1 file changed, 0 insertions(+), 0 deletions(-)
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 4 threads
Compressing objects: 100% (19/19), done.
Writing objects: 100% (20/20), 1.84 KiB | 470.00 KiB/s, done.
Total 20 (delta 9), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.8M
remote: -----> Launching...
remote:        Released v6
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
   e72b466..362c878  main -> main
PS E:\wwwroot\weibo> heroku open
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
PS E:\wwwroot\weibo>


26、但是,在提交表单,写入数据至 MySQL 时,响应 500 服务器错误,原因在于数据库还不存在。如图23
在提交表单,写入数据至 MySQL 时,响应 500 服务器错误,原因在于数据库还不存在。

图23

27、在 Heroku 上使用 PostgreSQL 来作为我们应用的数据库。安装 PostgreSQL 扩展。Heroku 将为我们生成一个唯一的数据库 URL – DATABASE_URL,我们可以通过命令:heroku config 查看 Heroku 的所有配置信息。如图24
在 Heroku 上使用 PostgreSQL 来作为我们应用的数据库。安装 PostgreSQL 扩展。Heroku 将为我们生成一个唯一的数据库 URL - DATABASE_URL,我们可以通过命令:heroku config 查看 Heroku 的所有配置信息。

图24



PS E:\wwwroot\weibo> heroku addons:add heroku-postgresql:hobby-dev
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Creating heroku-postgresql:hobby-dev on ⬢ secret-stream-72395... free
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Created postgresql-parallel-13694 as DATABASE_URL
Use heroku addons:docs heroku-postgresql to view documentation
PS E:\wwwroot\weibo> heroku config
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
=== secret-stream-72395 Config Vars
APP_KEY:      base64:TXoum9anbYcE/VGilCjxrSQQ5E4cR5UVb+55SjIsbg0=
DATABASE_URL: postgres://eayusxxdstiniz:31d9e092c4c8d1740380641299d36711b04e72b98e2f92b9be4253153087bbea@ec2-52-200-28-255.compute-1.amazonaws.com:5432/d9nb3l2ot2cutp
PS E:\wwwroot\weibo>


28、在本地开发中,我们使用了 MySQL 来作为数据库储存,但在 Heroku 环境上我们要改为使用 PostgreSQL 来作为数据库储存。因此在进行数据库设置时,我们需要对当前环境进行判断。如果环境为本地环境,则使用 MySQL 数据库,若为 Heroku 环境,则使用 PostgreSQL 数据库。我们可以通过为 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。一般来说,应用的数据库都在 config/database.php 中进行配置,因此我们需要针对该配置文件,来为不同环境的数据库连接方式定义一个帮助方法,以便根据应用不同的运行环境来指定数据库配置信息,我们需要新建一个 helpers.php 文件并写入以下内容:
<pre class="wp-block-syntaxhighlighter-code">

<?php

function get_db_config()
{
    if (getenv('IS_IN_HEROKU')) {
        $url = parse_url(getenv("DATABASE_URL"));

        return $db_config = [
            'connection' => 'pgsql',
            'host' => $url["host"],
            'database'  => substr($url["path"], 1),
            'username'  => $url["user"],
            'password'  => $url["pass"],
        ];
    } else {
        return $db_config = [
            'connection' => env('DB_CONNECTION', 'mysql'),
            'host' => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
        ];
    }
}

</pre>
29、新增 helpers.php 文件之后,还需要在项目根目录下 composer.json 文件中的 autoload 选项里 files 字段加入该文件。如图25
新增 helpers.php 文件之后,还需要在项目根目录下 composer.json 文件中的 autoload 选项里 files 字段加入该文件。

图25



    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/helpers.php"
        ]
    },


30、修改保存后运行以下命令进行重新加载文件即可,如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令。如图26
修改保存后运行以下命令进行重新加载文件即可,如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令。

图26



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail 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: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Package manifest generated successfully.
Generated optimized autoload files containing 5027 classes
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


31、现在,让我们使用刚刚定义好的 get_db_config 方法对数据库进行配置。调整数据库配置文件,总计就 2 处改动。如图28
现在,让我们使用刚刚定义好的 get_db_config 方法对数据库进行配置。调整数据库配置文件,总计就 2 处改动。

图28

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

<?php

use Illuminate\Support\Str;

$db_config = get_db_config();

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => $db_config['connection'],

</pre>
32、改动的代码进行提交,并推送到 GitHub 和 Heroku 上。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git push
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 936 bytes | 58.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
To https://github.com/shuijingwan/weibo.git
   876eb29..173fc8d  sign-up -> sign-up
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git merge sign-up
Merge made by the 'recursive' strategy.
 app/helpers.php     | 24 ++++++++++++++++++++++++
 composer.json       |  5 ++++-
 config/database.php |  4 +++-
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 app/helpers.php
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 300 bytes | 33.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/shuijingwan/weibo.git
   cd4e270..1e23962  main -> main
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$




PS E:\wwwroot\weibo> git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 19, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 1.13 KiB | 576.00 KiB/s, done.
Total 9 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 72 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:          - Installing laravel-lang/lang (5.0.0): Extracting archive
remote:          - Installing overtrue/laravel-lang (4.2.2): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Discovered Package: overtrue/laravel-lang
remote:        Package manifest generated successfully.
remote:        50 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.9M
remote: -----> Launching...
remote:        Released v10
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
   cd4e270..1e23962  main -> main
PS E:\wwwroot\weibo>


33、我们可以使用 heroku run 在 Heroku 运行 Laravel 的指定命令。现在我们需要在 Heroku 上执行迁移,生成用户表,可通过下面命令来完成,报错:SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter “client_encoding”: “utf8mb4” 。如图28
我们可以使用 heroku run 在 Heroku 运行 Laravel 的指定命令。现在我们需要在 Heroku 上执行迁移,生成用户表,可通过下面命令来完成,报错:SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter "client_encoding": "utf8mb4" 。

图28

 


PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.1841 (Free)
**************************************
*     Application In Production!     *
**************************************

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


In Connection.php line 703:

  SQLSTATE[22023]: Invalid parameter value: 7 ERROR:  invalid value for parameter "client_encoding": "utf8mb4" (SQL:
  select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'B
  ASE TABLE')


In PostgresConnector.php line 68:

  SQLSTATE[22023]: Invalid parameter value: 7 ERROR:  invalid value for parameter "client_encoding": "utf8mb4"


PS E:\wwwroot\weibo>


34、再次调整数据库配置文件,之前 pgsql 相关的配置未修改到。


        'pgsql' => [
            'driver' => 'pgsql',
            'host' => $db_config['host'],
            'port' => env('DB_PORT', '5432'),
            'database' => $db_config['database'],
            'username' => $db_config['username'],
            'password' => $db_config['password'],
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],


35、执行命令:heroku config:add DB_CONNECTION=pgsql 。再次执行迁移时报错已经不一样了:


 »   Warning: heroku update available from 7.53.0 to 7.59.2.
DB_CONNECTION: pgsql
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.7170 (Free)
**************************************
*     Application In Production!     *
**************************************

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


In Connection.php line 703:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections? (SQL: select * from information_schema.tables
   where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?


PS E:\wwwroot\weibo> git push heroku main
Everything up-to-date
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.6564 (Free)
**************************************
*     Application In Production!     *
**************************************

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


In Connection.php line 703:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections? (SQL: select * from information_schema.tables
   where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?


PS E:\wwwroot\weibo>


36、最后找到根源在于漏掉了在 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。迁移成功。如图29
最后找到根源在于漏掉了在 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。迁移成功。

图29



PS E:\wwwroot\weibo> heroku config:set IS_IN_HEROKU=true
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Setting IS_IN_HEROKU and restarting ⬢ secret-stream-72395... done, v16
IS_IN_HEROKU: true
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.3491 (Free)
**************************************
*     Application In Production!     *
**************************************

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

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (850.26ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (466.16ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (902.11ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (1,079.00ms)
PS E:\wwwroot\weibo>


37、再次提交表单数据,提交成功。如图30
再次提交表单数据,提交成功。

图30

38、使用 heroku rename 来对应用名称进行更改,但要保证更改的名称未被其它人占用。如图31
使用 heroku rename 来对应用名称进行更改,但要保证更改的名称未被其它人占用。

图31



PS E:\wwwroot\weibo> heroku rename app-wangqiang-weibo
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Renaming secret-stream-72395 to app-wangqiang-weibo... done
https://app-wangqiang-weibo.herokuapp.com/ | https://git.heroku.com/app-wangqiang-weibo.git
 !    Don't forget to update git remotes for all other local checkouts of the app.
Git remote heroku updated
PS E:\wwwroot\weibo>


39、打开:https://app-wangqiang-weibo.herokuapp.com/ ,响应 200。符合预期。如图32
打开:https://app-wangqiang-weibo.herokuapp.com/ ,响应 200。符合预期。

图32

40、打开:https://secret-stream-72395.herokuapp.com/ ,响应 404。There’s nothing here, yet。符合预期。如图33
打开:https://secret-stream-72395.herokuapp.com/ ,响应 404。There's nothing here, yet。符合预期。

图33

]]>
https://www.shuijingwanwq.com/2021/12/29/5622/feed/ 0
在 Windows 10 专业版中,使用多个 Laravel Sail 环境并设定自己想要的域名 https://www.shuijingwanwq.com/2021/12/28/5605/ https://www.shuijingwanwq.com/2021/12/28/5605/#respond Tue, 28 Dec 2021 11:07:13 +0000 https://www.shuijingwanwq.com/?p=5605 浏览量: 250 1、安装 Nginx Proxy Manager ,打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。如图1
安装 Nginx Proxy Manager ,打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。

图1

2、进入用户根目录,新建目录:proxy-manager,进入 目录:proxy-manager,创建文件:docker-compose.yml。如图2
进入用户根目录,新建目录:proxy-manager,进入 目录:proxy-manager,创建文件:docker-compose.yml。

图2



wangqiang@DESKTOP-QLPK8QM:/mnt/c/Users/Lenovo$ cd ~
wangqiang@DESKTOP-QLPK8QM:~$ mkdir proxy-manager
wangqiang@DESKTOP-QLPK8QM:~$ ls
proxy-manager
wangqiang@DESKTOP-QLPK8QM:~$ cd proxy-manager/
wangqiang@DESKTOP-QLPK8QM:~/proxy-manager$ nano docker-compose.yml


3、编辑文件:docker-compose.yml,Nano 的保存并退出,按下 Ctrl+O,再按下 Enter。再按下 Ctrl+X。HTTP & HTTPS 都是使用预设值。Post 81 用于 Admin 页面,让我们能设置 Laravel Ssil 的 Proxy。假如你的项目数量不多的话,使用 SQLite 已经足够了的。开发环境一般我都禁用 IPv6。保存接着就能启动容器了。如图3
编辑文件:docker-compose.yml,Nano 的保存并退出,按下 Ctrl+O,再按下 Enter。再按下 Ctrl+X。HTTP & HTTPS 都是使用预设值。Post 81 用于 Admin 页面,让我们能设置 Laravel Ssil 的 Proxy。假如你的项目数量不多的话,使用 SQLite 已经足够了的。开发环境一般我都禁用 IPv6。保存接着就能启动容器了。

图3



version: '3'
services:
    app:
        image: 'jc21/nginx-proxy-manager:latest'
        restart: always
        ports:
            # Public HTTP Port:
            - '80:80'
            # Public HTTPS Port:
            - '443:443'
            # Admin Web Port:
            - '81:81'
        environment:
            # These are the settings to access your db
            DB_SQLITE_FILE: '/data/database.sqlite'
            # Uncomment this if IPv6 is not enabled on your host
            DISABLE_IPV6: 'true'
        volumes:
            - './data:/data'
            - './letsencrypt:/etc/letsencrypt'


4、运行命令:docker-compose up -d ,报错:ERROR: yaml.scanner.ScannerError。最终决定还是使用 vi 重新编辑再保存。如图4
运行命令:docker-compose up -d ,报错:ERROR: yaml.scanner.ScannerError。最终决定还是使用 vi 重新编辑再保存。

图4



wangqiang@DESKTOP-QLPK8QM:~/proxy-manager$ docker-compose up -d
ERROR: yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
  in "./docker-compose.yml", line 5, column 1
wangqiang@DESKTOP-QLPK8QM:~/proxy-manager$ vi docker-compose.yml
wangqiang@DESKTOP-QLPK8QM:~/proxy-manager$ docker-compose up -d
Creating network "proxy-manager_default" with the default driver
Pulling app (jc21/nginx-proxy-manager:latest)...
latest: Pulling from jc21/nginx-proxy-manager
72a69066d2fe: Pull complete
6aacc5ddb486: Pull complete
e7c90551cea0: Pull complete
f3fbe2c2c4ff: Pull complete
4437e5607361: Pull complete
ac0af67384ba: Pull complete
70e9cf3ce040: Pull complete
20ca9bfa0d5d: Pull complete
3d5ed869606f: Pull complete
3d8d02d01e35: Pull complete
eb6a6398e23f: Pull complete
44ce8be92956: Pull complete
df1a765de003: Pull complete
a59ede055db9: Pull complete
536e2fa9b52d: Pull complete
a83af78253da: Pull complete
75e669cb8e7a: Pull complete
1dcb53004e40: Pull complete
d96b3a386f37: Pull complete
59e305e29011: Pull complete
3bbeaee21d7f: Pull complete
b65ab8da1424: Pull complete
fac215856462: Pull complete
6aaf9d409d6a: Pull complete
09b699c9559f: Pull complete
0d0f50cd276a: Pull complete
Digest: sha256:09316a7c425270f62600552d3d3115a2a98ea55397e26b43bdfd4b138f9a2ac2
Status: Downloaded newer image for jc21/nginx-proxy-manager:latest
Creating proxy-manager_app_1 ... done
wangqiang@DESKTOP-QLPK8QM:~/proxy-manager$


5、看到最后提示为绿色,表示容器创建成功。现在打开网址:http://localhost:81 。邮箱:admin@example.com 密码:changeme 。登录成功,如图5
看到最后提示为绿色,表示容器创建成功。现在打开网址:http://localhost:81 。邮箱:admin@example.com 密码:changeme 。登录成功

图5

6、创建 Laravel Sail 项目一,执行命令:curl -s https://laravel.build/sail-project-1 | bash


wangqiang@DESKTOP-QLPK8QM:/mnt$ cd e
wangqiang@DESKTOP-QLPK8QM:/mnt/e$ cd wwwroot/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$ curl -s https://laravel.build/sail-project-1 | bash

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

Warning: TTY mode requires /dev/tty to be read/writable.
    Creating a "laravel/laravel" project at "./sail-project-1"
    Installing laravel/laravel (v8.6.9)
      - Downloading laravel/laravel (v8.6.9)
      - Installing laravel/laravel (v8.6.9): Extracting archive
    Created project in /opt/sail-project-1
    > @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.3)
      - 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.1.0)
      - Locking egulias/email-validator (2.1.25)
      - Locking facade/flare-client-php (1.9.1)
      - Locking facade/ignition (2.17.2)
      - Locking facade/ignition-contracts (1.0.2)
      - Locking fakerphp/faker (v1.17.0)
      - Locking filp/whoops (2.14.4)
      - Locking fruitcake/laravel-cors (v2.0.4)
      - 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.77.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.0)
  - 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.10.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.5.1)
  - 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.10)
      - 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 (2.0.0)
  - 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.1)
      - Locking symfony/css-selector (v6.0.1)
  - Locking symfony/deprecation-contracts (v3.0.0)
      - Locking symfony/error-handler (v5.4.1)
      - Locking symfony/event-dispatcher (v6.0.1)
  - Locking symfony/event-dispatcher-contracts (v3.0.0)
      - Locking symfony/finder (v5.4.0)
  - Locking symfony/http-foundation (v5.4.1)
      - Locking symfony/http-kernel (v5.4.1)
  - Locking symfony/mime (v5.4.0)
      - Locking symfony/polyfill-ctype (v1.23.0)
  - Locking symfony/polyfill-iconv (v1.23.0)
      - Locking symfony/polyfill-intl-grapheme (v1.23.1)
  - Locking symfony/polyfill-intl-idn (v1.23.0)
  - Locking symfony/polyfill-intl-normalizer (v1.23.0)
  - Locking symfony/polyfill-mbstring (v1.23.1)
  - Locking symfony/polyfill-php72 (v1.23.0)
      - Locking symfony/polyfill-php73 (v1.23.0)
  - Locking symfony/polyfill-php80 (v1.23.1)
      - Locking symfony/polyfill-php81 (v1.23.0)
      - Locking symfony/process (v5.4.0)
      - Locking symfony/routing (v5.4.0)
      - Locking symfony/service-contracts (v2.4.1)
      - Locking symfony/string (v6.0.1)
      - Locking symfony/translation (v6.0.1)
  - Locking symfony/translation-contracts (v3.0.0)
  - Locking symfony/var-dumper (v5.4.1)
  - 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 doctrine/inflector (2.0.4)
      - Downloading doctrine/lexer (1.2.1)
      - Downloading dragonmantank/cron-expression (v3.1.0)
      - Downloading symfony/var-dumper (v5.4.1)
      - Downloading symfony/string (v6.0.1)
      - Downloading psr/container (1.1.2)
      - Downloading symfony/service-contracts (v2.4.1)
      - Downloading symfony/console (v5.4.1)
      - Downloading psr/log (2.0.0)
      - Downloading monolog/monolog (2.3.5)
      - Downloading voku/portable-ascii (1.5.6)
      - Downloading phpoption/phpoption (1.8.1)
      - Downloading graham-campbell/result-type (v1.0.4)
      - Downloading vlucas/phpdotenv (v5.4.1)
      - Downloading symfony/css-selector (v6.0.1)
      - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
      - Downloading symfony/routing (v5.4.0)
      - Downloading symfony/polyfill-php72 (v1.23.0)
      - Downloading symfony/polyfill-intl-idn (v1.23.0)
      - Downloading symfony/mime (v5.4.0)
      - Downloading symfony/http-foundation (v5.4.1)
      - Downloading psr/event-dispatcher (1.0.0)
      - Downloading symfony/event-dispatcher-contracts (v3.0.0)
      - Downloading symfony/event-dispatcher (v6.0.1)
      - Downloading symfony/error-handler (v5.4.1)
      - Downloading symfony/http-kernel (v5.4.1)
      - Downloading symfony/finder (v5.4.0)
      - Downloading symfony/polyfill-iconv (v1.23.0)
      - Downloading egulias/email-validator (2.1.25)
      - Downloading swiftmailer/swiftmailer (v6.3.0)
      - Downloading symfony/polyfill-php81 (v1.23.0)
      - Downloading ramsey/collection (1.2.2)
      - Downloading brick/math (0.9.3)
      - Downloading ramsey/uuid (4.2.3)
      - Downloading psr/simple-cache (1.0.1)
      - Downloading opis/closure (3.6.2)
      - Downloading symfony/translation-contracts (v3.0.0)
      - Downloading symfony/translation (v6.0.1)
      - Downloading nesbot/carbon (2.55.2)
      - Downloading league/mime-type-detection (1.9.0)
      - Downloading league/flysystem (1.1.9)
      - Downloading nette/utils (v3.2.6)
      - Downloading nette/schema (v1.2.2)
      - Downloading dflydev/dot-access-data (v3.0.1)
      - Downloading league/config (v1.1.1)
      - Downloading league/commonmark (2.1.0)
      - Downloading laravel/serializable-closure (v1.0.5)
      - Downloading laravel/framework (v8.77.1)
      - Downloading facade/ignition-contracts (1.0.2)
      - Downloading facade/flare-client-php (1.9.1)
      - Downloading facade/ignition (2.17.2)
      - Downloading fakerphp/faker (v1.17.0)
      - Downloading asm89/stack-cors (v2.0.3)
      - Downloading fruitcake/laravel-cors (v2.0.4)
      - Downloading psr/http-message (1.0.1)
      - Downloading psr/http-client (1.0.1)
      - Downloading ralouphie/getallheaders (3.0.3)
      - Downloading psr/http-factory (1.0.1)
      - Downloading guzzlehttp/psr7 (2.1.0)
      - Downloading guzzlehttp/promises (1.5.1)
      - Downloading guzzlehttp/guzzle (7.4.1)
      - Downloading laravel/sail (v1.12.12)
      - Downloading laravel/sanctum (v2.13.0)
      - Downloading nikic/php-parser (v4.13.2)
      - Downloading psy/psysh (v0.10.12)
      - Downloading laravel/tinker (v2.6.3)
      - Downloading hamcrest/hamcrest-php (v2.0.1)
      - Downloading mockery/mockery (1.4.4)
      - Downloading filp/whoops (2.14.4)
      - Downloading nunomaduro/collision (v5.10.0)
      - Downloading phpunit/php-file-iterator (3.0.6)
      - Downloading phpunit/php-code-coverage (9.2.10)
      - Downloading phpspec/prophecy (v1.15.0)
      - Installing doctrine/inflector (2.0.4): Extracting archive
      - Installing doctrine/lexer (1.2.1): Extracting archive
      - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
      - Installing webmozart/assert (1.10.0): Extracting archive
      - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
      - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
      - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
      - Installing symfony/var-dumper (v5.4.1): Extracting archive
      - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
      - Installing symfony/string (v6.0.1): Extracting archive
      - Installing psr/container (1.1.2): Extracting archive
      - Installing symfony/service-contracts (v2.4.1): Extracting archive
      - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
      - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
      - Installing symfony/console (v5.4.1): Extracting archive
      - Installing psr/log (2.0.0): 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 (v6.0.1): 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.0): Extracting archive
      - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
      - Installing symfony/mime (v5.4.0): Extracting archive
      - Installing symfony/http-foundation (v5.4.1): Extracting archive
      - Installing psr/event-dispatcher (1.0.0): Extracting archive
      - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
      - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
      - Installing symfony/error-handler (v5.4.1): Extracting archive
      - Installing symfony/http-kernel (v5.4.1): Extracting archive
      - Installing symfony/finder (v5.4.0): Extracting archive
      - Installing symfony/polyfill-iconv (v1.23.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.23.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 (v3.0.0): Extracting archive
      - Installing symfony/translation (v6.0.1): 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.0): Extracting archive
      - Installing laravel/serializable-closure (v1.0.5): Extracting archive
      - Installing laravel/framework (v8.77.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.2): Extracting archive
      - Installing fakerphp/faker (v1.17.0): Extracting archive
      - Installing asm89/stack-cors (v2.0.3): Extracting archive
      - Installing fruitcake/laravel-cors (v2.0.4): 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.4): Extracting archive
      - Installing nunomaduro/collision (v5.10.0): Extracting archive
      - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
      - Installing phpdocumentor/type-resolver (1.5.1): 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/complexity (2.0.2): 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.10): Extracting archive
    76 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.

Application ready! Build something amazing.
Sail scaffolding installed successfully.

Please provide your password so we can make some final adjustments to your application's permissions.

[sudo] password for wangqiang:

Thank you! We hope you build something incredible. Dive in with: cd sail-project-1 && ./vendor/bin/sail up
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$


7、打开编辑器,编辑 .env 文件,将以下配置项加入。这些皆是 Sail 的预设服务,其端口不能够重复,且与其他容器也不能够重复。一般来说端口 49152 到 65535 都是闲置的能够使用。如图6
打开编辑器,编辑 .env 文件,将以下配置项加入。这些皆是 Sail 的预设服务,其端口不能够重复,且与其他容器也不能够重复。一般来说端口 49152 到 65535 都是闲置的能够使用。

图6



APP_PORT=48080
FORWARD_DB_PORT=43306
FORWARD_REDIS_PORT=46379
FORWARD_MEILISEARCH_PORT=47700
FORWARD_MAILHOG_PORT=41025
FORWARD_MAILHOG_DASHBOARD_PORT=48025


8、进入目录:sail-project-1 ,执行命令:sail up -d。如图7
进入目录:sail-project-1 ,执行命令:sail up -d。

图7



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$ cd sail-project-1/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$ ls
README.md  bootstrap      config              package.json  resources   storage  webpack.mix.js
app        composer.json  database            phpunit.xml   routes      tests
artisan    composer.lock  docker-compose.yml  public        server.php  vendor
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$ alias sail='bash vendor/bin/sail'
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$ sail up -d
Creating network "sail-project-1_sail" with driver "bridge"
Creating volume "sail-project-1_sailmysql" with local driver
Creating volume "sail-project-1_sailredis" with local driver
Creating volume "sail-project-1_sailmeilisearch" with local driver
Creating sail-project-1_meilisearch_1 ... done
Creating sail-project-1_selenium_1    ... done
Creating sail-project-1_mysql_1       ... done
Creating sail-project-1_mailhog_1     ... done
Creating sail-project-1_redis_1       ... done
Creating sail-project-1_laravel.test_1 ... done
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-1$


9、第一个 Sail 项目启动完成。如图8
第一个 Sail 项目启动完成。

图8

10、接着开始第二个 Sail 项目,执行命令:curl -s https://laravel.build/sail-project-2 | bash。步骤是一样的,只不过 .env 文件的内容有所差异。所有端口号全部加1,未报端口冲突错误。如图9
接着开始第二个 Sail 项目,执行命令:curl -s https://laravel.build/sail-project-2 | bash。步骤是一样的,只不过 .env 文件的内容有所差异。所有端口号全部加1,未报端口冲突错误。

图9



APP_PORT=48081
FORWARD_DB_PORT=43307
FORWARD_REDIS_PORT=46380
FORWARD_MEILISEARCH_PORT=47701
FORWARD_MAILHOG_PORT=41026
FORWARD_MAILHOG_DASHBOARD_PORT=48026




wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/sail-project-2$ sail up -d
Creating network "sail-project-2_sail" with driver "bridge"
Creating sail-project-2_redis_1       ... done
Creating sail-project-2_mailhog_1      ... done
Creating sail-project-2_meilisearch_1 ... done
Creating sail-project-2_selenium_1    ... done
Creating sail-project-2_mysql_1       ... done
Creating sail-project-2_laravel.test_1 ... done


11、在两个项目中,编辑视图文件,以未区分。http://localhost:48080/ 、http://localhost:48081/ 。如图10
在两个项目中,编辑视图文件,以未区分。http://localhost:48080/ 、http://localhost:48081/ 。

图10

12、现在分别设置两个项目的域名。编辑 C:/Windows/System32/Drivers/etc/hosts 文件,指定 IP 与域名之间的映射关系。


127.0.0.1 sail-project-1.test
127.0.0.1 sail-project-2.test


13、打开 Nginx Proxy Manager ,Hosts – Proxy Hosts – Add Proxy Host。如图11
打开 Nginx Proxy Manager ,Hosts - Proxy Hosts - Add Proxy Host。

图11

14、添加完毕 15、分别打开:http://sail-project-1.test 、http://sail-project-2.test ,如图12
分别打开:http://sail-project-1.test 、http://sail-project-2.test

图12

16、从本地宿主机连接到 MySQL 数据库,可以直接通过 127.0.0.1 和 43306 端口连接到 MySQL 数据库容器。如图13
从本地宿主机连接到 MySQL 数据库,可以直接通过 127.0.0.1 和 43306 端口连接到 MySQL 数据库容器。

图13

 ]]>
https://www.shuijingwanwq.com/2021/12/28/5605/feed/ 0
在 WSL2 中的 Ubuntu 系统中,执行命令:sudo apt install php7.4-cli,报错:E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-common_7.4.3-4ubuntu2.5_amd64.deb 404 Not Found [IP: 91.189.88.152 80] https://www.shuijingwanwq.com/2021/12/27/5597/ https://www.shuijingwanwq.com/2021/12/27/5597/#respond Mon, 27 Dec 2021 10:07:08 +0000 = 8.0.2]]> https://www.shuijingwanwq.com/?p=5597 浏览量: 111 1、在 WSL2 中的 Ubuntu 系统中,执行命令:sudo apt install php7.4-cli,报错:E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-common_7.4.3-4ubuntu2.5_amd64.deb 404 Not Found [IP: 91.189.88.152 80]。如图1
在 WSL2 中的 Ubuntu 系统中,执行命令:sudo apt install php7.4-cli,报错:E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-common_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]。

图1



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ php artisan make:controller StaticPagesController

Command 'php' not found, but can be installed with:

sudo apt install php7.4-cli
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sudo apt install php7.4-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  php-common php7.4-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 2643 kB of archives.
After this operation, 13.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 php-common all 2:75 [11.9 kB]
Ign:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-common amd64 7.4.3-4ubuntu2.5
Ign:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-json amd64 7.4.3-4ubuntu2.5
Ign:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-opcache amd64 7.4.3-4ubuntu2.5
Ign:5 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-readline amd64 7.4.3-4ubuntu2.5
Ign:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-cli amd64 7.4.3-4ubuntu2.5
Err:2 http://security.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-common amd64 7.4.3-4ubuntu2.5
  404  Not Found [IP: 91.189.88.152 80]
Err:3 http://security.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-json amd64 7.4.3-4ubuntu2.5
  404  Not Found [IP: 91.189.88.152 80]
Err:4 http://security.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-opcache amd64 7.4.3-4ubuntu2.5
  404  Not Found [IP: 91.189.88.152 80]
Err:5 http://security.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-readline amd64 7.4.3-4ubuntu2.5
  404  Not Found [IP: 91.189.88.152 80]
Err:6 http://security.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-cli amd64 7.4.3-4ubuntu2.5
  404  Not Found [IP: 91.189.88.152 80]
Fetched 11.9 kB in 5s (2475 B/s)
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-common_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-json_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-opcache_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-readline_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.4/php7.4-cli_7.4.3-4ubuntu2.5_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


2、基于提示信息,运行 apt-get update。如图2
基于提示信息,运行 apt-get update。

图2



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1069 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [197 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [9096 B]
Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [566 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [80.9 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [528 B]
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [668 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [112 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [13.0 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [21.9 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [4948 B]
Get:17 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Get:18 http://archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B]
Get:23 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1400 kB]
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [283 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.7 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [616 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [88.1 kB]
Get:28 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [528 B]
Get:29 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [884 kB]
Get:30 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [193 kB]
Get:31 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [19.9 kB]
Get:32 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [24.8 kB]
Get:33 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [6928 B]
Get:34 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [616 B]
Get:35 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [42.0 kB]
Get:36 http://archive.ubuntu.com/ubuntu focal-backports/main Translation-en [10.0 kB]
Get:37 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [864 B]
Get:38 http://archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]
Get:39 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [18.9 kB]
Get:40 http://archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [7492 B]
Get:41 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [636 B]
Get:42 http://archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 21.0 MB in 31s (675 kB/s)
Reading package lists... Done
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


3、再次执行命令:sudo apt install php7.4-cli,未再报错。如图3
再次执行命令:sudo apt install php7.4-cli,未再报错。

图3



Creating config file /etc/php/7.4/mods-available/shmop.ini with new version

Creating config file /etc/php/7.4/mods-available/sockets.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvmsg.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvsem.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvshm.ini with new version

Creating config file /etc/php/7.4/mods-available/tokenizer.ini with new version
Setting up php7.4-readline (7.4.3-4ubuntu2.8) ...

Creating config file /etc/php/7.4/mods-available/readline.ini with new version
Setting up php7.4-opcache (7.4.3-4ubuntu2.8) ...

Creating config file /etc/php/7.4/mods-available/opcache.ini with new version
Setting up php7.4-json (7.4.3-4ubuntu2.8) ...

Creating config file /etc/php/7.4/mods-available/json.ini with new version
Setting up php7.4-cli (7.4.3-4ubuntu2.8) ...
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.4/cli/php.ini with new version
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.8) ...


4、执行命令:php artisan make:controller StaticPagesController。报错:Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.3.。如图4
执行命令:php artisan make:controller StaticPagesController。报错:Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.3.。

图4



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ php artisan make:controller StaticPagesController
Composer detected issues in your platform:

Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.3.

PHP Fatal error:  Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.3. in /mnt/e/wwwroot/weibo/vendor/composer/platform_check.php on line 24
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


5、由于 Docker 容器是基于 Laravel Sail 实现的。调整执行命令:sail artisan make:controller StaticPagesController。 生成控制器成功。如图5
由于 Docker 容器是基于 Laravel Sail 实现的。调整执行命令:sail artisan make:controller StaticPagesController。 生成控制器成功。

图5



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail artisan make:controller StaticPagesController
Controller created successfully.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


]]>
https://www.shuijingwanwq.com/2021/12/27/5597/feed/ 0
在 Windows 10 专业版中创建 weibo 应用,基于 Laravel Sail 开发环境 https://www.shuijingwanwq.com/2021/12/24/5588/ https://www.shuijingwanwq.com/2021/12/24/5588/#respond Fri, 24 Dec 2021 01:25:36 +0000 https://www.shuijingwanwq.com/?p=5588 浏览量: 96 1、使用 Composer 创建一个名为 weibo 的应用。打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。如图1
使用 Composer 创建一个名为 weibo 的应用。打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。

图1

2、Ubuntu 作为 Windows 子系统,可以访问到主系统下的硬盘。为了方便管理代码,我在 E 盘下早已创建了 wwwroot 目录,进入此目录后,使用以下命令进行创建一个测试的 Laravel 项目,名称:weibo。如图2
Ubuntu 作为 Windows 子系统,可以访问到主系统下的硬盘。为了方便管理代码,我在 E 盘下早已创建了 wwwroot 目录,进入此目录后,使用以下命令进行创建一个测试的 Laravel 项目,名称:weibo。

图2



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$ curl -s https://laravel.build/weibo | bash

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

Warning: TTY mode requires /dev/tty to be read/writable.
    Creating a "laravel/laravel" project at "./weibo"
    Installing laravel/laravel (v8.6.9)
      - Downloading laravel/laravel (v8.6.9)
      - Installing laravel/laravel (v8.6.9): Extracting archive
    Created project in /opt/weibo
    > @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.3)
  - 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.1.0)
  - Locking egulias/email-validator (2.1.25)
      - Locking facade/flare-client-php (1.9.1)
      - Locking facade/ignition (2.17.2)
      - Locking facade/ignition-contracts (1.0.2)
  - Locking fakerphp/faker (v1.17.0)
  - Locking filp/whoops (2.14.4)
      - Locking fruitcake/laravel-cors (v2.0.4)
  - 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.76.2)
      - 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.0)
      - 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.10.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.5.1)
      - 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.10)
      - 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 (2.0.0)
      - 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.1)
      - Locking symfony/css-selector (v6.0.1)
  - Locking symfony/deprecation-contracts (v3.0.0)
      - Locking symfony/error-handler (v5.4.1)
      - Locking symfony/event-dispatcher (v6.0.1)
  - Locking symfony/event-dispatcher-contracts (v3.0.0)
      - Locking symfony/finder (v5.4.0)
      - Locking symfony/http-foundation (v5.4.1)
      - Locking symfony/http-kernel (v5.4.1)
      - Locking symfony/mime (v5.4.0)
      - Locking symfony/polyfill-ctype (v1.23.0)
      - Locking symfony/polyfill-iconv (v1.23.0)
      - Locking symfony/polyfill-intl-grapheme (v1.23.1)
      - Locking symfony/polyfill-intl-idn (v1.23.0)
      - Locking symfony/polyfill-intl-normalizer (v1.23.0)
      - Locking symfony/polyfill-mbstring (v1.23.1)
      - Locking symfony/polyfill-php72 (v1.23.0)
      - Locking symfony/polyfill-php73 (v1.23.0)
  - Locking symfony/polyfill-php80 (v1.23.1)
      - Locking symfony/polyfill-php81 (v1.23.0)
  - Locking symfony/process (v5.4.0)
      - Locking symfony/routing (v5.4.0)
      - Locking symfony/service-contracts (v2.4.1)
      - Locking symfony/string (v6.0.1)
      - Locking symfony/translation (v6.0.1)
      - Locking symfony/translation-contracts (v3.0.0)
      - Locking symfony/var-dumper (v5.4.1)
      - 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 doctrine/inflector (2.0.4)
      - Downloading doctrine/lexer (1.2.1)
      - Downloading dragonmantank/cron-expression (v3.1.0)
      - Downloading symfony/var-dumper (v5.4.1)
      - Downloading symfony/string (v6.0.1)
      - Downloading psr/container (1.1.2)
      - Downloading symfony/service-contracts (v2.4.1)
      - Downloading symfony/console (v5.4.1)
      - Downloading psr/log (2.0.0)
      - Downloading monolog/monolog (2.3.5)
      - Downloading voku/portable-ascii (1.5.6)
      - Downloading phpoption/phpoption (1.8.1)
      - Downloading graham-campbell/result-type (v1.0.4)
      - Downloading vlucas/phpdotenv (v5.4.1)
      - Downloading symfony/css-selector (v6.0.1)
      - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
      - Downloading symfony/routing (v5.4.0)
      - Downloading symfony/polyfill-php72 (v1.23.0)
      - Downloading symfony/polyfill-intl-idn (v1.23.0)
      - Downloading symfony/mime (v5.4.0)
      - Downloading symfony/http-foundation (v5.4.1)
      - Downloading psr/event-dispatcher (1.0.0)
      - Downloading symfony/event-dispatcher-contracts (v3.0.0)
      - Downloading symfony/event-dispatcher (v6.0.1)
      - Downloading symfony/error-handler (v5.4.1)
      - Downloading symfony/http-kernel (v5.4.1)
      - Downloading symfony/finder (v5.4.0)
      - Downloading symfony/polyfill-iconv (v1.23.0)
      - Downloading egulias/email-validator (2.1.25)
      - Downloading swiftmailer/swiftmailer (v6.3.0)
      - Downloading symfony/polyfill-php81 (v1.23.0)
      - Downloading ramsey/collection (1.2.2)
      - Downloading brick/math (0.9.3)
      - Downloading ramsey/uuid (4.2.3)
      - Downloading psr/simple-cache (1.0.1)
      - Downloading opis/closure (3.6.2)
      - Downloading symfony/translation-contracts (v3.0.0)
      - Downloading symfony/translation (v6.0.1)
      - Downloading nesbot/carbon (2.55.2)
      - Downloading league/mime-type-detection (1.9.0)
      - Downloading league/flysystem (1.1.9)
      - Downloading nette/utils (v3.2.6)
      - Downloading nette/schema (v1.2.2)
      - Downloading dflydev/dot-access-data (v3.0.1)
      - Downloading league/config (v1.1.1)
      - Downloading league/commonmark (2.1.0)
      - Downloading laravel/serializable-closure (v1.0.5)
      - Downloading laravel/framework (v8.76.2)
      - Downloading facade/ignition-contracts (1.0.2)
      - Downloading facade/flare-client-php (1.9.1)
      - Downloading facade/ignition (2.17.2)
      - Downloading fakerphp/faker (v1.17.0)
      - Downloading asm89/stack-cors (v2.0.3)
      - Downloading fruitcake/laravel-cors (v2.0.4)
      - Downloading psr/http-message (1.0.1)
      - Downloading psr/http-client (1.0.1)
      - Downloading ralouphie/getallheaders (3.0.3)
      - Downloading psr/http-factory (1.0.1)
      - Downloading guzzlehttp/psr7 (2.1.0)
      - Downloading guzzlehttp/promises (1.5.1)
      - Downloading guzzlehttp/guzzle (7.4.1)
      - Downloading laravel/sail (v1.12.12)
      - Downloading laravel/sanctum (v2.13.0)
      - Downloading nikic/php-parser (v4.13.2)
      - Downloading psy/psysh (v0.10.12)
      - Downloading laravel/tinker (v2.6.3)
      - Downloading hamcrest/hamcrest-php (v2.0.1)
      - Downloading mockery/mockery (1.4.4)
      - Downloading filp/whoops (2.14.4)
      - Downloading nunomaduro/collision (v5.10.0)
      - Downloading phpunit/php-file-iterator (3.0.6)
      - Downloading phpunit/php-code-coverage (9.2.10)
      - Downloading phpspec/prophecy (v1.15.0)
      - Installing doctrine/inflector (2.0.4): Extracting archive
      - Installing doctrine/lexer (1.2.1): Extracting archive
      - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
      - Installing webmozart/assert (1.10.0): Extracting archive
      - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
      - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
      - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
      - Installing symfony/var-dumper (v5.4.1): Extracting archive
      - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
      - Installing symfony/string (v6.0.1): Extracting archive
      - Installing psr/container (1.1.2): Extracting archive
      - Installing symfony/service-contracts (v2.4.1): Extracting archive
      - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
      - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
      - Installing symfony/console (v5.4.1): Extracting archive
      - Installing psr/log (2.0.0): 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 (v6.0.1): 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.0): Extracting archive
      - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
      - Installing symfony/mime (v5.4.0): Extracting archive
      - Installing symfony/http-foundation (v5.4.1): Extracting archive
      - Installing psr/event-dispatcher (1.0.0): Extracting archive
      - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
      - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
      - Installing symfony/error-handler (v5.4.1): Extracting archive
      - Installing symfony/http-kernel (v5.4.1): Extracting archive
      - Installing symfony/finder (v5.4.0): Extracting archive
      - Installing symfony/polyfill-iconv (v1.23.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.23.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 (v3.0.0): Extracting archive
      - Installing symfony/translation (v6.0.1): 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.0): Extracting archive
      - Installing laravel/serializable-closure (v1.0.5): Extracting archive
      - Installing laravel/framework (v8.76.2): 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.2): Extracting archive
      - Installing fakerphp/faker (v1.17.0): Extracting archive
      - Installing asm89/stack-cors (v2.0.3): Extracting archive
      - Installing fruitcake/laravel-cors (v2.0.4): 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.4): Extracting archive
      - Installing nunomaduro/collision (v5.10.0): Extracting archive
      - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
      - Installing phpdocumentor/type-resolver (1.5.1): 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/complexity (2.0.2): 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.10): Extracting archive
    76 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.

Application ready! Build something amazing.
Sail scaffolding installed successfully.

Please provide your password so we can make some final adjustments to your application's permissions.

[sudo] password for wangqiang:

Thank you! We hope you build something incredible. Dive in with: cd weibo && ./vendor/bin/sail up
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$


3、进入目录:weibo,运行命令:./vendor/bin/sail build。报错:FileNotFoundError: [Errno 2] No such file or directory。[7207] Failed to execute script docker-compose。如图3
进入目录:weibo,运行命令:./vendor/bin/sail build。报错:FileNotFoundError: [Errno 2] No such file or directory。[7207] Failed to execute script docker-compose。

图3

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

wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ ./vendor/bin/sail build
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 200, in perform_command
  File "compose/cli/command.py", line 70, in project_from_options
  File "compose/cli/command.py", line 146, in get_project
  File "compose/cli/command.py", line 206, in get_project_name
  File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[7185] Failed to execute script docker-compose
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 200, in perform_command
  File "compose/cli/command.py", line 70, in project_from_options
  File "compose/cli/command.py", line 146, in get_project
  File "compose/cli/command.py", line 206, in get_project_name
  File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[7197] Failed to execute script docker-compose
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 200, in perform_command
  File "compose/cli/command.py", line 70, in project_from_options
  File "compose/cli/command.py", line 146, in get_project
  File "compose/cli/command.py", line 206, in get_project_name
  File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[7207] Failed to execute script docker-compose
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$

</pre>
4、关闭 Docker Desktop,重新打开 Docker Desktop,删除容器 weibo。再次执行命令:./vendor/bin/sail build。运行命令:./vendor/bin/sail up -d。报错:ERROR: for weibo_laravel.test_1 Cannot start service laravel.test: driver failed programming external connectivity on endpoint weibo_laravel.test_1 (103c7d0eca8c6625d55c959f6b4a3fbe7921b8f12d29474519bcde62b876a555): Bind for 0.0.0.0:80 failed: port is already allocated。如图4
关闭 Docker Desktop,重新打开 Docker Desktop,删除容器 weibo。再次执行命令:./vendor/bin/sail build。运行命令:./vendor/bin/sail up -d。报错:ERROR: for weibo_laravel.test_1  Cannot start service laravel.test: driver failed programming external connectivity on endpoint weibo_laravel.test_1 (103c7d0eca8c6625d55c959f6b4a3fbe7921b8f12d29474519bcde62b876a555): Bind for 0.0.0.0:80 failed: port is already allocated。

图4



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ ./vendor/bin/sail build
weibo_laravel.test_1   start-container                  Exit 128

Shutting down old Sail processes...
mysql uses an image, skipping
redis uses an image, skipping
meilisearch uses an image, skipping
mailhog uses an image, skipping
selenium uses an image, skipping
Building laravel.test
[+] Building 6.3s (16/16) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.8s
 => => transferring dockerfile: 38B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  1.1s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/ubuntu:21.04                                                    4.7s
 => [ 1/11] FROM docker.io/library/ubuntu:21.04@sha256:93a94c12448f393522f44d8a1b34936b7f76890adea34b80b87a245524  0.0s
 => [internal] load build context                                                                                  0.2s
 => => transferring context: 99B                                                                                   0.0s
 => CACHED [ 2/11] WORKDIR /var/www/html                                                                           0.0s
 => CACHED [ 3/11] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone                  0.0s
 => CACHED [ 4/11] RUN apt-get update     && apt-get install -y gnupg gosu curl ca-certificates zip unzip git sup  0.0s
 => CACHED [ 5/11] RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1                                           0.0s
 => CACHED [ 6/11] RUN groupadd --force -g 1000 sail                                                               0.0s
 => CACHED [ 7/11] RUN useradd -ms /bin/bash --no-user-group -g 1000 -u 1337 sail                                  0.0s
 => CACHED [ 8/11] COPY start-container /usr/local/bin/start-container                                             0.0s
 => CACHED [ 9/11] COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf                                   0.0s
 => CACHED [10/11] COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini                                                0.0s
 => CACHED [11/11] RUN chmod +x /usr/local/bin/start-container                                                     0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:e61442fd4297b3cb8dcc44e9c4501ba75eae255b6a7940040df40f49b04481bf                       0.0s
 => => naming to sail-8.1/app                                                                                      0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ ./vendor/bin/sail up -d
Creating network "weibo_sail" with driver "bridge"
Creating weibo_mailhog_1     ... done
Creating weibo_meilisearch_1 ... done
Creating weibo_redis_1       ... done
Creating weibo_mysql_1       ... done
Creating weibo_selenium_1    ... done
Creating weibo_laravel.test_1 ...
Creating weibo_laravel.test_1 ... error

ERROR: for weibo_laravel.test_1  Cannot start service laravel.test: driver failed programming external connectivity on endpoint weibo_laravel.test_1 (103c7d0eca8c6625d55c959f6b4a3fbe7921b8f12d29474519bcde62b876a555): Bind for 0.0.0.0:80 failed: port is already allocated

ERROR: for laravel.test  Cannot start service laravel.test: driver failed programming external connectivity on endpoint weibo_laravel.test_1 (103c7d0eca8c6625d55c959f6b4a3fbe7921b8f12d29474519bcde62b876a555): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


5、打开 Docker Desktop,停止容器 example-app。以让出端口 80,以及其他有冲突的端口。后续计划支持多个 Laravel Sail 环境并设定自己想要的域名。如图5
打开 Docker Desktop,停止容器 example-app。以让出端口 80,以及其他有冲突的端口。后续计划支持多个 Laravel Sail 环境并设定自己想要的域名。

图5

6、运行命令:./vendor/bin/sail up -d。创建容器成功。如图6
运行命令:./vendor/bin/sail up -d。创建容器成功。

图6



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ ./vendor/bin/sail up -d
weibo_laravel.test_1   start-container                  Exit 128

Shutting down old Sail processes...
Creating network "weibo_sail" with driver "bridge"
Creating weibo_mailhog_1      ... done
Creating weibo_selenium_1    ... done
Creating weibo_mysql_1       ... done
Creating weibo_redis_1       ... done
Creating weibo_meilisearch_1 ... done
Creating weibo_laravel.test_1 ... done


7、编辑 C:/Windows/System32/Drivers/etc/hosts 文件,指定 IP 与域名之间的映射关系。


127.0.0.1 weibo.test


8、在浏览器中打开网址:http://weibo.test/ 。响应 200。如图7
在浏览器中打开网址:http://weibo.test/ 。响应 200。

图7

 ]]>
https://www.shuijingwanwq.com/2021/12/24/5588/feed/ 0
在 Windows 10 专业版中搭建 Laravel Sail 开发环境 https://www.shuijingwanwq.com/2021/12/23/5559/ https://www.shuijingwanwq.com/2021/12/23/5559/#respond Thu, 23 Dec 2021 01:45:36 +0000 https://www.shuijingwanwq.com/?p=5559 浏览量: 307 1、Laravel Sail 要求支持 WSL 2 的 Windows 10 系统。在 2020 年五月份发布的 2004 版本才支持 WSL 2 功能,所以我们的系统需更新到等于或大于 2004 版本。查看系统版本,可以使用 winver 命令,参考 Windows 10 release information ,版本的发布时间大于 1909 即可。系统版本符合要求。如图1
查看系统版本,可以使用 winver 命令,参考 Windows 10 release information ,版本的发布时间大于 1909 即可。

图1

2、先基于 360 升级至:最新的 21H1 的版本。如图2
先基于 360 升级至:最新的 21H1 的版本。

图2

3、查看系统版本,已经升级至:21H1 的版本。如图3
查看系统版本,已经升级至:21H1 的版本。

图3

4、搜索打开 Windows 功能管理 窗口,确保下图红框框住的两个地方都已开启:适用于 Linux 的 Windows 子系统、远程差分压缩 API 支持。如图4
搜索打开 Windows 功能管理 窗口,确保下图红框框住的两个地方都已开启:适用于 Linux 的 Windows 子系统、远程差分压缩 API 支持。

图4

5、为了更好地访问 Windows 的子系统,推荐使用 Windows Terminal 作为命令行工具。打开微软商店,搜索关键字 Windows Terminal ,在搜索结果中点击安装即可。如图5
为了更好地访问 Windows 的子系统,推荐使用 Windows Terminal 作为命令行工具。打开微软商店,搜索关键字 Windows Terminal ,在搜索结果中点击安装即可。

图5

6、下载和安装子系统:Ubuntu 。打开微软商店,搜索关键词 Ubuntu,第一和第二个都可以,选择第二个:Ubuntu 20.04 LTS。如图6
下载和安装子系统:Ubuntu 。打开微软商店,搜索关键词 Ubuntu,第一和第二个都可以,选择第二个:Ubuntu 20.04 LTS。

图6

7、提示创建一个 Ubuntu 系统的用户,入用户名,接下来输入密码即可完成 Ubuntu 子系统的安装。这个 Ubuntu 为当前 Windows 系统的子系统,接下来我们的 Docker 会基于此系统运行。如图7
提示创建一个 Ubuntu 系统的用户,输入用户名,接下来输入密码即可完成 Ubuntu 子系统的安装。这个 Ubuntu 为当前 Windows 系统的子系统,接下来我们的 Docker 会基于此系统运行。

图7

8、前往 Docker 官网下载 Docker Desktop:https://hub.docker.com/editions/community/docker-ce-desktop-windows ,下载完成后点击安装包安装,一直下一步即可。 9、提示:WSL 2 installation is incomplete. WSL 2 安装不完整。如图8
提示:WSL 2 installation is incomplete. WSL 2 安装不完整。

图8



WSL 2 installation is incomplete.
The WSL 2 Linux kernel is now installed using a separate MSI update package. Please click the link and follow the instructions to install the kernel update:https://aka.ms/wsl2kernel

Press restart after installing the Linux kernel


10、点击链接并按照说明安装内核更新:https://aka.ms/wsl2kernel 。下载并安装 Linux 内核更新包。如图9
点击链接并按照说明安装内核更新:https://aka.ms/wsl2kernel 。下载并安装 Linux 内核更新包。

图9

11、重启电脑,再次打开 Docker Desktop,报错:Docker failed to initialize。暂时不用理会。如图10
重启电脑,再次打开 Docker Desktop,报错:Docker failed to initialize。暂时不用理会。

图10

12、再次重启电脑后。打开 Docker Desktop,未再报错。进入配置页面 – General,默认已勾选 Use the WSL 2 based engine,开启 WSL2 模式。如图11
再次重启电脑后。打开 Docker Desktop,未再报错。进入配置页面 - General,默认已勾选 Use the WSL 2 based engine,开启 WSL2 模式。

图11

13、配置 – Resources – WSL Integration,选择我们上一步安装的 Ubuntu 系统,但是不存在 ubuntu 选项。如图12
配置 - Resources - WSL Integration,选择我们上一步安装的 Ubuntu 系统,但是不存在 ubuntu 选项。

图12

14、参考网址:https://learnku.com/articles/54890 。打开:Windows Terminal,转换为 WSL 2。如图13
参考网址:https://learnku.com/articles/54890 。打开:Windows Terminal,转换为 WSL 2。

图13



PS C:\Users\Lenovo> wsl --list --verbose
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         1
  docker-desktop-data    Running         2
  docker-desktop         Running         2
PS C:\Users\Lenovo> wsl --set-version Ubuntu-20.04 2
正在进行转换,这可能需要几分钟时间...
有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
转换完成。
PS C:\Users\Lenovo>


15、点击按钮 Refresh,选项 Ubuntu-20.04 已经出现,开启。如图14
点击按钮 Refresh,选项 Ubuntu-20.04 已经出现,开启。

图14

16、创建测试项目,打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。如图15
创建测试项目,打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。

图15

17、Ubuntu 作为 Windows 子系统,可以访问到主系统下的硬盘。为了方便管理代码,我在 E 盘下早已创建了 wwwroot 目录,进入此目录后,使用以下命令进行创建一个测试的 Laravel 项目。如图16
Ubuntu 作为 Windows 子系统,可以访问到主系统下的硬盘。为了方便管理代码,我在 E 盘下早已创建了 wwwroot 目录,进入此目录后,使用以下命令进行创建一个测试的 Laravel 项目。

图16



wangqiang@DESKTOP-QLPK8QM:/mnt/c/Users/Lenovo$ cd /mnt/e
wangqiang@DESKTOP-QLPK8QM:/mnt/e$ ls
'$RECYCLE.BIN'  'System Volume Information'   cms   pagefile.sys    phpuploadtmp
 Develop         c                            css   phpsessiontmp   wwwroot
wangqiang@DESKTOP-QLPK8QM:/mnt/e$ cd wwwroot/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$ curl -s https://laravel.build/example-app | bash
Unable to find image 'laravelsail/php81-composer:latest' locally
latest: Pulling from laravelsail/php81-composer
eff15d958d66: Pull complete
933427dc39f7: Pull complete
35bb08dc7ee2: Pull complete
58a3f26800d7: Pull complete
28803bfad74c: Pull complete
341a482d0bd3: Pull complete
03c4148389b1: Pull complete
fa3a9bfc7793: Pull complete
024907232600: Pull complete
df5987d70de6: Pull complete
e2a72a518bd8: Pull complete
b1ba689993c8: Pull complete
3bd142ab0b85: Pull complete
872fe34989f0: Pull complete
Digest: sha256:b27920b769ad8dc036a9ede3ae36f51a280d370ec7d125e77ca1924c9fa21dbb
Status: Downloaded newer image for laravelsail/php81-composer:latest

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

Warning: TTY mode requires /dev/tty to be read/writable.
    Creating a "laravel/laravel" project at "./example-app"
    Installing laravel/laravel (v8.6.9)
      - Downloading laravel/laravel (v8.6.9)
      - Installing laravel/laravel (v8.6.9): Extracting archive
    Created project in /opt/example-app
    > @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.3)
  - 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.1.0)
      - Locking egulias/email-validator (2.1.25)
      - Locking facade/flare-client-php (1.9.1)
      - Locking facade/ignition (2.17.2)
      - Locking facade/ignition-contracts (1.0.2)
      - Locking fakerphp/faker (v1.17.0)
      - Locking filp/whoops (2.14.4)
      - Locking fruitcake/laravel-cors (v2.0.4)
      - 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.76.2)
  - 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.0)
  - 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.10.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.5.1)
      - 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.10)
      - 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 (2.0.0)
  - 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.1)
      - Locking symfony/css-selector (v6.0.1)
  - Locking symfony/deprecation-contracts (v3.0.0)
      - Locking symfony/error-handler (v5.4.1)
      - Locking symfony/event-dispatcher (v6.0.1)
      - Locking symfony/event-dispatcher-contracts (v3.0.0)
      - Locking symfony/finder (v5.4.0)
  - Locking symfony/http-foundation (v5.4.1)
      - Locking symfony/http-kernel (v5.4.1)
  - Locking symfony/mime (v5.4.0)
      - Locking symfony/polyfill-ctype (v1.23.0)
      - Locking symfony/polyfill-iconv (v1.23.0)
      - Locking symfony/polyfill-intl-grapheme (v1.23.1)
  - Locking symfony/polyfill-intl-idn (v1.23.0)
      - Locking symfony/polyfill-intl-normalizer (v1.23.0)
      - Locking symfony/polyfill-mbstring (v1.23.1)
  - Locking symfony/polyfill-php72 (v1.23.0)
      - Locking symfony/polyfill-php73 (v1.23.0)
      - Locking symfony/polyfill-php80 (v1.23.1)
      - Locking symfony/polyfill-php81 (v1.23.0)
      - Locking symfony/process (v5.4.0)
      - Locking symfony/routing (v5.4.0)
      - Locking symfony/service-contracts (v2.4.1)
      - Locking symfony/string (v6.0.1)
  - Locking symfony/translation (v6.0.1)
      - Locking symfony/translation-contracts (v3.0.0)
      - Locking symfony/var-dumper (v5.4.1)
      - 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 doctrine/inflector (2.0.4)
      - Downloading doctrine/lexer (1.2.1)
      - Downloading dragonmantank/cron-expression (v3.1.0)
      - Downloading symfony/var-dumper (v5.4.1)
      - Downloading symfony/string (v6.0.1)
      - Downloading psr/container (1.1.2)
      - Downloading symfony/service-contracts (v2.4.1)
      - Downloading symfony/console (v5.4.1)
      - Downloading psr/log (2.0.0)
      - Downloading monolog/monolog (2.3.5)
      - Downloading voku/portable-ascii (1.5.6)
      - Downloading phpoption/phpoption (1.8.1)
      - Downloading graham-campbell/result-type (v1.0.4)
      - Downloading vlucas/phpdotenv (v5.4.1)
      - Downloading symfony/css-selector (v6.0.1)
      - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
      - Downloading symfony/routing (v5.4.0)
      - Downloading symfony/polyfill-php72 (v1.23.0)
      - Downloading symfony/polyfill-intl-idn (v1.23.0)
      - Downloading symfony/mime (v5.4.0)
      - Downloading symfony/http-foundation (v5.4.1)
      - Downloading psr/event-dispatcher (1.0.0)
      - Downloading symfony/event-dispatcher-contracts (v3.0.0)
      - Downloading symfony/event-dispatcher (v6.0.1)
      - Downloading symfony/error-handler (v5.4.1)
      - Downloading symfony/http-kernel (v5.4.1)
      - Downloading symfony/finder (v5.4.0)
      - Downloading symfony/polyfill-iconv (v1.23.0)
      - Downloading egulias/email-validator (2.1.25)
      - Downloading swiftmailer/swiftmailer (v6.3.0)
      - Downloading symfony/polyfill-php81 (v1.23.0)
      - Downloading ramsey/collection (1.2.2)
      - Downloading brick/math (0.9.3)
      - Downloading ramsey/uuid (4.2.3)
      - Downloading psr/simple-cache (1.0.1)
      - Downloading opis/closure (3.6.2)
      - Downloading symfony/translation-contracts (v3.0.0)
      - Downloading symfony/translation (v6.0.1)
      - Downloading nesbot/carbon (2.55.2)
      - Downloading league/mime-type-detection (1.9.0)
      - Downloading league/flysystem (1.1.9)
      - Downloading nette/utils (v3.2.6)
      - Downloading nette/schema (v1.2.2)
      - Downloading dflydev/dot-access-data (v3.0.1)
      - Downloading league/config (v1.1.1)
      - Downloading league/commonmark (2.1.0)
      - Downloading laravel/serializable-closure (v1.0.5)
      - Downloading laravel/framework (v8.76.2)
      - Downloading facade/ignition-contracts (1.0.2)
      - Downloading facade/flare-client-php (1.9.1)
      - Downloading facade/ignition (2.17.2)
      - Downloading fakerphp/faker (v1.17.0)
      - Downloading asm89/stack-cors (v2.0.3)
      - Downloading fruitcake/laravel-cors (v2.0.4)
      - Downloading psr/http-message (1.0.1)
      - Downloading psr/http-client (1.0.1)
      - Downloading ralouphie/getallheaders (3.0.3)
      - Downloading psr/http-factory (1.0.1)
      - Downloading guzzlehttp/psr7 (2.1.0)
      - Downloading guzzlehttp/promises (1.5.1)
      - Downloading guzzlehttp/guzzle (7.4.1)
      - Downloading laravel/sail (v1.12.12)
      - Downloading laravel/sanctum (v2.13.0)
      - Downloading nikic/php-parser (v4.13.2)
      - Downloading psy/psysh (v0.10.12)
      - Downloading laravel/tinker (v2.6.3)
      - Downloading hamcrest/hamcrest-php (v2.0.1)
      - Downloading mockery/mockery (1.4.4)
      - Downloading filp/whoops (2.14.4)
      - Downloading nunomaduro/collision (v5.10.0)
      - Downloading phpunit/php-file-iterator (3.0.6)
      - Downloading phpunit/php-code-coverage (9.2.10)
      - Downloading phpspec/prophecy (v1.15.0)
      - Installing doctrine/inflector (2.0.4): Extracting archive
      - Installing doctrine/lexer (1.2.1): Extracting archive
      - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
      - Installing webmozart/assert (1.10.0): Extracting archive
      - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
      - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
      - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
      - Installing symfony/var-dumper (v5.4.1): Extracting archive
      - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
      - Installing symfony/string (v6.0.1): Extracting archive
      - Installing psr/container (1.1.2): Extracting archive
      - Installing symfony/service-contracts (v2.4.1): Extracting archive
      - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
      - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
      - Installing symfony/console (v5.4.1): Extracting archive
      - Installing psr/log (2.0.0): 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 (v6.0.1): 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.0): Extracting archive
      - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
      - Installing symfony/mime (v5.4.0): Extracting archive
      - Installing symfony/http-foundation (v5.4.1): Extracting archive
      - Installing psr/event-dispatcher (1.0.0): Extracting archive
      - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
      - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
      - Installing symfony/error-handler (v5.4.1): Extracting archive
      - Installing symfony/http-kernel (v5.4.1): Extracting archive
      - Installing symfony/finder (v5.4.0): Extracting archive
      - Installing symfony/polyfill-iconv (v1.23.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.23.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 (v3.0.0): Extracting archive
      - Installing symfony/translation (v6.0.1): 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.0): Extracting archive
      - Installing laravel/serializable-closure (v1.0.5): Extracting archive
      - Installing laravel/framework (v8.76.2): 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.2): Extracting archive
      - Installing fakerphp/faker (v1.17.0): Extracting archive
      - Installing asm89/stack-cors (v2.0.3): Extracting archive
      - Installing fruitcake/laravel-cors (v2.0.4): 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.4): Extracting archive
      - Installing nunomaduro/collision (v5.10.0): Extracting archive
      - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
      - Installing phpdocumentor/type-resolver (1.5.1): 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/complexity (2.0.2): 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.10): Extracting archive
    76 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.

Application ready! Build something amazing.
Sail scaffolding installed successfully.

Please provide your password so we can make some final adjustments to your application's permissions.

[sudo] password for wangqiang:

Thank you! We hope you build something incredible. Dive in with: cd example-app && ./vendor/bin/sail up
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot$


18、最终创建成功的界面。如图17
最终创建成功的界面。

图17

19、打开 E:\wwwroot\example-app 目录。如图18
打开 E:\wwwroot\example-app 目录。

图18

20、查看 Dockerfile 文件,Laravel 8 默认用的是 vendor/laravel/sail/runtimes/8.0 目录下的 Dockerfile。如图19
查看 Dockerfile 文件,Laravel 8 默认用的是 vendor/laravel/sail/runtimes/8.0 目录下的 Dockerfile。

图19

21、运行容器,在项目的根目录下,执行以下命令:./vendor/bin/sail up。第一次运行的时候,会初始化容器。建议翻墙。我一般不倾向于使用国内的镜像。报错。如图20
运行容器,在项目的根目录下,执行以下命令:./vendor/bin/sail up。第一次运行的时候,会初始化容器。建议翻墙。我一般不倾向于使用国内的镜像。报错。

图20



ERROR: for mysql  Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
ERROR: Encountered errors while bringing up the project.


22、原因应该在于本地的 mysql 数据库已经使用了 3306 端口,决定先将本地 mysql 数据库的端口修改为 3307。打开目录 C:\ProgramData\MySQL\MySQL Server 5.7,编辑 my.ini 文件。


[client]

# pipe
# socket=0.0
port=3307


[mysqld]

# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking

# enable-named-pipe

# shared-memory

# shared-memory-base-name=MYSQL

# The Pipe the MySQL Server will use
# socket=MYSQL

# The TCP/IP Port the MySQL Server will listen on
port=3307


23、重启电脑后,基于端口 3307 连接本地 mysql 数据库成功。如图21
重启电脑后,基于端口 3307 连接本地 mysql 数据库成功。

图21

24、再次运行命令:./vendor/bin/sail up。会从 mysql 处开始运行,总计耗费时长:20分钟。sail up 命令运行成功后,会一直显示软件的实时日志界面。如图22
再次运行命令:./vendor/bin/sail up。会从 mysql 处开始运行,总计耗费时长:。sail up 命令运行成功后,会一直显示软件的实时日志界面。

图22

25、此时你可以 ctrl+c 中断运行,再次运行时,可以使用 -d 参数让 sail up 命令在后台运行。如图23
此时你可以 ctrl+c 中断运行,再次运行时,可以使用 -d 参数让 sail up 命令在后台运行。

图23



meilisearch_1   | [2021-12-21T03:09:36Z INFO  actix_web::middleware::logger] 127.0.0.1:51806 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000297
^CGracefully stopping... (press Ctrl+C again to force)
Stopping example-app_laravel.test_1 ... done
Stopping example-app_mailhog_1      ... done
Stopping example-app_mysql_1        ... done
Stopping example-app_selenium_1     ... done
Stopping example-app_redis_1        ... done
Stopping example-app_meilisearch_1  ... done
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/example-app$ ./vendor/bin/sail up -d
example-app_laravel.test_1   start-container                  Exit 137
Shutting down old Sail processes...
Creating network "example-app_sail" with driver "bridge"
Creating example-app_redis_1       ... done
Creating example-app_mailhog_1     ... done
Creating example-app_meilisearch_1 ... done
Creating example-app_selenium_1    ... done
Creating example-app_mysql_1       ... done
Creating example-app_laravel.test_1 ... done
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/example-app$


26、打开 Docker Desktop,容器列表中存在容器:example-app,状态为运行中。如图24
打开 Docker Desktop,容器列表中存在容器:example-app,状态为运行中。

图24

27、在浏览器中打开网址:http://localhost/ ,响应 200 。Laravel v8.76.2 (PHP v8.1.0)。开发环境部署成功。如图25
在浏览器中打开网址:http://localhost/ ,响应 200 。Laravel v8.76.2 (PHP v8.1.0)。开发环境部署成功。

图25

28、针对 3306 端口被占用的问题,还有另外一种方案,即修改容器的端口为 43306。本地 mysql 数据库仍然使用 3306 端口。计划后续基于 Nginx Proxy Manager 实现。 29、编辑 C:/Windows/System32/Drivers/etc/hosts 文件,指定 IP 与域名之间的映射关系。


127.0.0.1 example-app.test


30、在浏览器中打开网址:http://example-app.test/ 。响应 200。如图26
在浏览器中打开网址:http://example-app.test/ 。响应 200。

图26

]]>
https://www.shuijingwanwq.com/2021/12/23/5559/feed/ 0