Windows WSL2环境下Laravel Sail安装失败无目录排查求助
问题
在Windows系统搭配WSL2环境下,按照Laravel官方Windows安装教程操作时,执行命令curl -s https://laravel.build/example-app | bash后出现错误,未生成example-app目录,具体报错信息如下:
~$ curl -s https://laravel.build/example-app | bash latest: Pulling from laravelsail/php82-composer bb263680fed1: Pull complete 0825793cba86: Pull complete de3c011d207b: Pull complete 7e3c5bd9650e: Pull complete e5ef4f07283b: Pull complete 729644263cfa: Pull complete 9c646fe3f3c5: Pull complete e7c9e0a2bc78: Pull complete 87fd6a1f6441: Pull complete 136b5bfaa68e: Pull complete cf33f30cc64a: Pull complete 9250c2dfc674: Pull complete 4f4fb700ef54: Pull complete 59bc22386503: Pull complete 376a1c60a489: Pull complete Digest: sha256:37549f980be6146efcb16b0dc352644edfc5cca32b9862494631eb197ef89737 Status: Downloaded newer image for laravelsail/php82-composer:latest _ _ | | | | | | __ _ _ __ __ ___ _____| | | | / _` | '__/ _` \ \ / / _ \ | | |___| (_| | | | (_| |\ V / __/ | |______\__,_|_| \__,_| \_/ \___|_| WARN TTY mode requires /dev/tty to be read/writable. Creating a "laravel/laravel" project at "./example-app" https://repo.packagist.org could not be fully loaded (curl error 35 while downloading https://repo.packagist.org/packages.json: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to repo.packagist.org:443 ), package information was loaded from the local cache and may be out of date In CurlDownloader.php line 365: curl error 35 while downloading https://repo.packagist.org/p2/laravel/larav el.json: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to repo.packa gist.org:443 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] [--no-audit] [--audit-format AUDIT-FORMAT] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [<package> [<directory> [<version>]]] bash: line 17: cd: example-app: No such file or directory bash: line 19: ./vendor/bin/sail: No such file or directory bash: line 20: ./vendor/bin/sail: No such file or directory Please provide your password so we can make some final adjustments to your application's permissions. [sudo] password for my-user: Thank you! We hope you build something incredible. Dive in with: cd example-app && ./vendor/bin/sail up
排查与解决步骤
验证WSL2网络连通性
在WSL2终端执行curl -I https://repo.packagist.org,若无法返回正常HTTP响应,说明网络存在问题。可尝试修改WSL2的DNS配置:- 备份原DNS配置文件:
sudo cp /etc/resolv.conf /etc/resolv.conf.bak - 编辑配置文件:
sudo nano /etc/resolv.conf,将nameserver改为8.8.8.8或114.114.114.114 - 保存退出后,重新执行网络测试命令
- 备份原DNS配置文件:
临时绕过SSL验证测试
执行curl -s https://laravel.build/example-app | bash -s -- --no-secure-http,该命令会禁用Composer的SSL安全验证(仅用于测试,不建议长期使用),若能完成安装,说明问题出在SSL证书或验证环节。手动通过Composer创建项目
- 先在WSL2中安装Composer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && php -r "unlink('composer-setup.php');" && sudo mv composer.phar /usr/local/bin/composer - 执行
composer create-project laravel/laravel example-app,观察是否仍出现SSL相关错误,以此缩小问题范围
- 先在WSL2中安装Composer:
检查Docker网络状态
- 确认Windows上的Docker Desktop已启动,且已开启WSL2集成(在Docker设置的Resources > WSL Integration中勾选对应WSL发行版)
- 重启WSL2:在Windows终端执行
wsl --shutdown,然后重新打开WSL终端 - 重启Docker Desktop后,再次尝试安装命令
清理缓存后重试
执行composer clear-cache清理Composer本地缓存,然后删除可能残留的不完整文件(若有),重新运行安装命令排查防火墙与代理影响
- 暂时关闭Windows防火墙,测试安装命令是否正常执行
- 若使用代理服务,需在WSL2终端配置代理环境变量:
配置完成后再执行安装命令export HTTP_PROXY=http://your-proxy-address:port export HTTPS_PROXY=http://your-proxy-address:port
内容的提问来源于stack exchange,提问作者nahusznaj
相关产品推荐
相关产品推荐

