windows(10)執行laravel new blog出錯

極思創意發表於2021-10-03

新人學習中遇到的問題,不一定正確,文章如出錯,以後會回來改正

執行php -v獲取版本資訊

C:\Users\kefu\Desktop>php -v
PHP 7.2.1 (cli) (built: Jan  4 2018 04:28:54) ( NTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

執行laravel -v獲取laravel資訊【同時,輸入laravel的過程按tab能夠自動補全】

C:\Users\kefu\Desktop>laravel -v
Laravel Installer 3.0.1

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help  Display help for a command
  list  List commands
  new   Create a new Laravel application

執行composer獲取composer的資訊【這裡輸入composer過程中無法自動補全,猜測可能是沒新增到環境變數中嗎?】

C:\Users\kefu\Desktop>composer -v
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.8 2021-09-15 13:55:14

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                Shows a short information about Composer.
  archive              Creates an archive of this composer package.
  browse               Opens the package's repository URL or homepage in your browser.
  cc                   Clears composer's internal package cache.
  check-platform-reqs  Check that platform requirements are satisfied.
  clear-cache          Clears composer's internal package cache.
  clearcache           Clears composer's internal package cache.
  config               Sets config options.
  create-project       Creates new project from a package into given directory.
  depends              Shows which packages cause the given package to be installed.
  diagnose             Diagnoses the system to identify common errors.
  dump-autoload        Dumps the autoloader.
  dumpautoload         Dumps the autoloader.
  exec                 Executes a vendored binary/script.
  fund                 Discover how to help fund the maintenance of your dependencies.
  global               Allows running commands in the global composer dir ($COMPOSER_HOME).
  help                 Displays help for a command
  home                 Opens the package's repository URL or homepage in your browser.
  i                    Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  info                 Shows information about packages.
  init                 Creates a basic composer.json file in current directory.
  install              Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses             Shows information about licenses of dependencies.
  list                 Lists commands
  outdated             Shows a list of installed packages that have updates available, including their latest version.
  prohibits            Shows which packages prevent the given package from being installed.
  reinstall            Uninstalls and reinstalls the given package names
  remove               Removes a package from the require or require-dev.
  require              Adds required packages to your composer.json and installs them.
  run                  Runs the scripts defined in composer.json.
  run-script           Runs the scripts defined in composer.json.
  search               Searches for packages.
  self-update          Updates composer.phar to the latest version.
  selfupdate           Updates composer.phar to the latest version.
  show                 Shows information about packages.
  status               Shows a list of locally modified packages.
  suggests             Shows package suggestions.
  u                    Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  update               Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  upgrade              Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate             Validates a composer.json and composer.lock.
  why                  Shows which packages cause the given package to be installed.
  why-not              Shows which packages prevent the given package from being installed.

執行laravel new blog報出如下程式碼【未連線梯子】

C:\Users\kefu\Desktop>laravel new blog
Crafting application...

In CurlFactory.php line 200:

  cURL error 7: Failed to connect to 127.0.0.1 port 1080: Connection refused (see https://curl.haxx.se/libcurl/c/libc
  url-errors.html)


new [--dev] [--auth] [-f|--force] [--] [<name>]

猜測可能是因為沒掛TZ的問題,就又掛上,又重新執行laravel new blog就又報出如下程式碼

C:\Users\kefu\Desktop>laravel new blog
Crafting application...

In RequestException.php line 113:

  Client error: `GET http://cabinet.laravel.com/latest.zip` resulted in a `404 Not Found` response:
  <html>
  <head><title>404 Not Found</title></head>
  <body>
  <center><h1>404 Not Found</h1></center>
  <hr><center>nginx</c (truncated...)


new [--dev] [--auth] [-f|--force] [--] [<name>]

掛沒掛TZ報了兩種程式碼,疑惑中…

再執行另外一種方法創作專案檔案composer create-project --prefer-dist laravel/laravel blog【在沒掛TZ的情況下】
成功報錯/太悲催了

C:\Users\kefu\Desktop>composer create-project --prefer-dist laravel/laravel blog
Creating a "laravel/laravel" project at "./blog"
https://repo.packagist.org could not be fully loaded (curl error 7 while downloading https://repo.packagist.org/packages.json: Failed to connect to 127.0.0.1 port 1080: Connection refused), package information was loaded from the local cache and may be out of date


  [Composer\Downloader\TransportException]
  curl error 7 while downloading https://repo.packagist.org/p2/laravel/laravel.json: Failed to connect to 127.0.0.1 p
  ort 1080: Connection refused


create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [<package>] [<directory>] [<version>]

掛上再試試【成功拉取】(可能是沒用composer 全量映象導致的/太難了)

C:\Users\kefu\Desktop>composer create-project --prefer-dist laravel/laravel blog
Creating a "laravel/laravel" project at "./blog"
Installing laravel/laravel (v6.18.35)
  - Installing laravel/laravel (v6.18.35): Extracting archive
Created project in C:\Users\kefu\Desktop\blog
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 87 installs, 0 updates, 0 removals
  - Locking doctrine/inflector (2.0.3)
  - Locking doctrine/instantiator (1.4.0)
  - Locking doctrine/lexer (1.2.1)
  - Locking dragonmantank/cron-expression (v2.3.1)
  - Locking egulias/email-validator (2.1.25)
  - Locking facade/flare-client-php (1.9.1)
  - Locking facade/ignition (1.18.0)
  - Locking facade/ignition-contracts (1.0.1)
  - Locking fideloper/proxy (4.4.1)
  - Locking filp/whoops (2.14.3)
  - Locking fzaninotto/faker (v1.9.2)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking jakub-onderka/php-console-color (v0.2)
  - Locking jakub-onderka/php-console-highlighter (v0.4)
  - Locking laravel/framework (v6.18.43)
  - Locking laravel/tinker (v2.4.2)
  - Locking league/commonmark (1.6.6)
  - Locking league/flysystem (1.0.46)
  - Locking mockery/mockery (1.3.5)
  - Locking monolog/monolog (2.3.5)
  - Locking myclabs/deep-copy (1.10.2)
  - Locking nesbot/carbon (2.53.1)
  - Locking nikic/php-parser (v4.13.0)
  - Locking nunomaduro/collision (v3.1.0)
  - Locking opis/closure (3.6.2)
  - Locking paragonie/random_compat (v9.99.100)
  - 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.2.2)
  - Locking phpdocumentor/type-resolver (1.5.1)
  - Locking phpoption/phpoption (1.8.0)
  - Locking phpspec/prophecy (1.14.0)
  - Locking phpunit/php-code-coverage (7.0.15)
  - Locking phpunit/php-file-iterator (2.0.4)
  - Locking phpunit/php-text-template (1.2.1)
  - Locking phpunit/php-timer (2.1.3)
  - Locking phpunit/php-token-stream (3.1.3)
  - Locking phpunit/phpunit (8.5.21)
  - Locking psr/container (1.1.1)
  - Locking psr/log (1.1.4)
  - Locking psr/simple-cache (1.0.1)
  - Locking psy/psysh (v0.10.8)
  - Locking ramsey/uuid (3.9.6)
  - Locking scrivo/highlight.php (v9.18.1.7)
  - Locking sebastian/code-unit-reverse-lookup (1.0.2)
  - Locking sebastian/comparator (3.0.3)
  - Locking sebastian/diff (3.0.3)
  - Locking sebastian/environment (4.2.4)
  - Locking sebastian/exporter (3.1.3)
  - Locking sebastian/global-state (3.0.1)
  - Locking sebastian/object-enumerator (3.0.4)
  - Locking sebastian/object-reflector (1.1.2)
  - Locking sebastian/recursion-context (3.0.1)
  - Locking sebastian/resource-operations (2.0.2)
  - Locking sebastian/type (1.1.4)
  - Locking sebastian/version (2.0.1)
  - Locking swiftmailer/swiftmailer (v6.2.7)
  - Locking symfony/console (v4.4.30)
  - Locking symfony/css-selector (v4.4.27)
  - Locking symfony/debug (v4.4.31)
  - Locking symfony/error-handler (v4.4.30)
  - Locking symfony/event-dispatcher (v4.4.30)
  - Locking symfony/event-dispatcher-contracts (v1.1.9)
  - Locking symfony/finder (v4.4.30)
  - Locking symfony/http-client-contracts (v1.1.10)
  - Locking symfony/http-foundation (v4.4.30)
  - Locking symfony/http-kernel (v4.4.32)
  - Locking symfony/mime (v4.4.31)
  - Locking symfony/polyfill-ctype (v1.23.0)
  - Locking symfony/polyfill-iconv (v1.23.0)
  - 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/process (v4.4.30)
  - Locking symfony/routing (v4.4.30)
  - Locking symfony/service-contracts (v1.1.9)
  - Locking symfony/translation (v4.4.32)
  - Locking symfony/translation-contracts (v1.1.10)
  - Locking symfony/var-dumper (v4.4.31)
  - Locking theseer/tokenizer (1.2.1)
  - Locking tijsverkoyen/css-to-inline-styles (2.2.3)
  - Locking vlucas/phpdotenv (v3.6.9)
  - Locking webmozart/assert (1.10.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 87 installs, 0 updates, 0 removals
  - Downloading symfony/var-dumper (v4.4.31)
  - Downloading monolog/monolog (2.3.5)
  - Downloading vlucas/phpdotenv (v3.6.9)
  - Downloading symfony/mime (v4.4.31)
  - Downloading symfony/debug (v4.4.31)
  - Downloading symfony/http-kernel (v4.4.32)
  - Downloading ramsey/uuid (3.9.6)
  - Downloading nikic/php-parser (v4.13.0)
  - Downloading phpdocumentor/type-resolver (1.5.1)
  - Downloading phpunit/phpunit (8.5.21)
  - Installing doctrine/inflector (2.0.3): Extracting archive
  - Installing doctrine/lexer (1.2.1): Extracting archive
  - Installing dragonmantank/cron-expression (v2.3.1): Extracting archive
  - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
  - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
  - Installing symfony/var-dumper (v4.4.31): Extracting archive
  - Installing psr/container (1.1.1): Extracting archive
  - Installing symfony/service-contracts (v1.1.9): Extracting archive
  - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
  - Installing symfony/console (v4.4.30): Extracting archive
  - Installing scrivo/highlight.php (v9.18.1.7): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing monolog/monolog (2.3.5): Extracting archive
  - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
  - Installing phpoption/phpoption (1.8.0): Extracting archive
  - Installing vlucas/phpdotenv (v3.6.9): Extracting archive
  - Installing symfony/css-selector (v4.4.27): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.3): Extracting archive
  - Installing symfony/routing (v4.4.30): Extracting archive
  - Installing symfony/process (v4.4.30): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
  - Installing symfony/mime (v4.4.31): Extracting archive
  - Installing symfony/http-foundation (v4.4.30): Extracting archive
  - Installing symfony/http-client-contracts (v1.1.10): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v1.1.9): Extracting archive
  - Installing symfony/event-dispatcher (v4.4.30): Extracting archive
  - Installing symfony/debug (v4.4.31): Extracting archive
  - Installing symfony/error-handler (v4.4.30): Extracting archive
  - Installing symfony/http-kernel (v4.4.32): Extracting archive
  - Installing symfony/finder (v4.4.30): Extracting archive
  - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.2.7): Extracting archive
  - Installing paragonie/random_compat (v9.99.100): Extracting archive
  - Installing ramsey/uuid (3.9.6): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.2): Extracting archive
  - Installing symfony/translation-contracts (v1.1.10): Extracting archive
  - Installing symfony/translation (v4.4.32): Extracting archive
  - Installing nesbot/carbon (2.53.1): Extracting archive
  - Installing league/flysystem (1.0.46): Extracting archive
  - Installing league/commonmark (1.6.6): Extracting archive
  - Installing laravel/framework (v6.18.43): Extracting archive
  - Installing filp/whoops (2.14.3): Extracting archive
  - Installing facade/ignition-contracts (1.0.1): Extracting archive
  - Installing facade/flare-client-php (1.9.1): Extracting archive
  - Installing facade/ignition (1.18.0): Extracting archive
  - Installing fideloper/proxy (4.4.1): Extracting archive
  - Installing fzaninotto/faker (v1.9.2): Extracting archive
  - Installing jakub-onderka/php-console-color (v0.2): Extracting archive
  - Installing nikic/php-parser (v4.13.0): Extracting archive
  - Installing psy/psysh (v0.10.8): Extracting archive
  - Installing laravel/tinker (v2.4.2): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.3.5): Extracting archive
  - Installing jakub-onderka/php-console-highlighter (v0.4): Extracting archive
  - Installing nunomaduro/collision (v3.1.0): Extracting archive
  - Installing webmozart/assert (1.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.2.2): Extracting archive
  - Installing phpunit/php-token-stream (3.1.3): Extracting archive
  - Installing sebastian/version (2.0.1): Extracting archive
  - Installing sebastian/type (1.1.4): Extracting archive
  - Installing sebastian/resource-operations (2.0.2): Extracting archive
  - Installing sebastian/recursion-context (3.0.1): Extracting archive
  - Installing sebastian/object-reflector (1.1.2): Extracting archive
  - Installing sebastian/object-enumerator (3.0.4): Extracting archive
  - Installing sebastian/global-state (3.0.1): Extracting archive
  - Installing sebastian/exporter (3.1.3): Extracting archive
  - Installing sebastian/environment (4.2.4): Extracting archive
  - Installing sebastian/diff (3.0.3): Extracting archive
  - Installing sebastian/comparator (3.0.3): Extracting archive
  - Installing phpunit/php-timer (2.1.3): Extracting archive
  - Installing phpunit/php-text-template (1.2.1): Extracting archive
  - Installing phpunit/php-file-iterator (2.0.4): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (1.0.2): Extracting archive
  - Installing phpunit/php-code-coverage (7.0.15): Extracting archive
  - Installing doctrine/instantiator (1.4.0): Extracting archive
  - Installing phpspec/prophecy (1.14.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 (8.5.21): Extracting archive
83 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
59 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan key:generate --ansi
Application key set successfully.

但是接近尾巴的地方有黃色提示,翻譯了下應該是無關緊要

Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.

總結(小白總結,不一定對)

laravel專案安裝,已知有2種方式

  • 最簡單的應該是laravel new blog
    依託方式為啥?laravel
    前幾天折騰了下,在Mac上能正常執行。
    但是在windows下沒成功,不知道是環境配置還是TZ等問題。
  • 想來是依託composer
    依目前來看使用composer create-project --prefer-dist laravel/laravel blog建立專案,與網路有關係,也就是要掛TZ或者改成中文源。
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章