在国内安装yii2新项目由于网络超时安装失败的解决办法

在国内安装yii2新项目由于网络超时安装失败的解决办法

安装命令如下:

bash 复制代码
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

错误信息如下

bash 复制代码
PHP Warning:  Xdebug MUST be loaded as a Zend extension in Unknown on line 0
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
PHP Warning:  Xdebug MUST be loaded as a Zend extension in Unknown on line 0
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug
Creating a "yiisoft/yii2-app-basic" project at "./basic"
Installing yiisoft/yii2-app-basic (2.0.51)
  - Downloading yiisoft/yii2-app-basic (2.0.51)
  - Installing yiisoft/yii2-app-basic (2.0.51): Extracting archive
Created project in C:\Users\xxxxxx\basic
Loading composer repositories with package information
A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.

In CurlDownloader.php line 401:

  curl error 28 while downloading https://cdn.asset-packagist.org/p/provider-latest/4ce2ba113a0543e1004801046ff7797f6
  07bdd162226d4a7ca5cfeca6045ff2e.json: Connection timed out after 10003 milliseconds


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] [--no-security-blocking] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [<package> [<directory> [<version>]]]

这时候已生成成了basic文件夹和composer.json文件,但是没有composer.lock文件。

进入basic文件夹,再次执行

bash 复制代码
composer install

长时间等待后还是同样的报错

解决办法

打开composer.json文件

将文件末尾

bash 复制代码
"repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }

改成

bash 复制代码
"repositories": [{
        "name": "packagist",
        "type": "composer",
        "url": "https://repo.packagist.org"
    }]

或直接改国内的腾讯镜像源

bash 复制代码
"repositories": [{
        "name": "packagist",
        "type": "composer",
        "url": "https://mirrors.cloud.tencent.com/composer/"
    }]

再次执行

bash 复制代码
composer install

如果报如下错误

bash 复制代码
Problem 1

Root composer.json requires yiisoft/yii2 ~2.0.45 -> satisfiable by yiisoft/yii2[2.0.55].
yiisoft/yii2 2.0.55 requires bower-asset/jquery 3.7.@stable | 3.6.@stable | 3.5.@stable | 3.4.@stable | 3.3.@stable | 3.2.@stable | 3.1.@stable | 2.2.@stable | 2.1.@stable | 1.11.@stable | 1.12.*@stable -> could not be found in any version, but the following packages provide it:
yidas/yii2-bower-asset Bower Assets for Yii 2 app provided via Composer repository
craftcms/cms Craft CMS
yidas/yii2-composer-bower-skip A Composer package that allows you to install or update Yii2 without Bower-Asset
demokn/yii2-composer-asset
...

下列方法任选一个

方法1. 在composer.json中添加jQuery bower-asset 包依赖,只需要在原有的require基础上加上yidas/yii2-bower-asset即可

bash 复制代码
// composer.json
"require": {
    "yidas/yii2-bower-asset": "*"
}

然后执行

bash 复制代码
composer install

方法2.直接运行:

bash 复制代码
composer require yidas/yii2-bower-asset

再执行

bash 复制代码
composer install
补充,过程序可能会用到github Token,请提前准备好
关于cookieValidationKey
bash 复制代码
yii\web\Request::cookieValidationKey must be configured with a secret key.

请打开config/web.php文件,找到cookieValidationKey并设置secret key,可以用uuid或任意值

php 复制代码
return [
    // 其他配置...
    'components' => [
        'request' => [
            'cookieValidationKey' => '你的秘密密钥',
        ],
        // 其他组件配置...
    ],
];
关于Yii2无法正确定位手动安装的yii2-bower-asset

报错信息如下

html 复制代码
Invalid Argument -- yii\base\InvalidArgumentException
The file or directory to be published does not exist: D:\www\php\xxx\vendor/bower-asset/jquery/dist

打开config/web.php文件,找到

php 复制代码
'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],

改成

php 复制代码
'aliases' => [
        '@bower' => '@vendor/yidas/yii2-bower-asset/bower',
        '@npm'   => '@vendor/npm-asset',
    ],

问题解决

相关推荐
qq_4480111618 小时前
C语言中的动态内存分配
c语言·开发语言·php
叠层归一研究院20 小时前
AGI 系统(十一):二阶网络 — 二阶递归 × 多主体 (元符号网络)
开发语言·人工智能·算法·php·agi
数据知道21 小时前
反序列化漏洞:Java、PHP、Python 三条线各讲透
java·网络·python·安全·网络安全·php
江畔柳前堤21 小时前
Function Calling 与 Tool Calling:从认知到工程的全景深度解析
开发语言·网络·人工智能·深度学习·算法·机器学习·php
那年窗外下的雪.1 天前
AIDC 学习日志 Day 3:OSPF Underlay 实验、故障排查与深入解析
服务器·网络·php
Hello.Reader1 天前
REALITY 技术深度解析从 TLS 伪装、抗主动探测到 VLESS + XTLS Vision 完整实践
开发语言·php
catchadmin1 天前
Fiber 与 PHP 8.6 Polling API 异步初探
android·开发语言·php
梅菲塔亚1 天前
Keepalived高可用全解析
linux·运维·服务器·开发语言·网络·php
weixin_307779131 天前
PHP 大文件上传:内存占用、超时与最佳实践
linux·服务器·开发语言·nginx·php
郑州光合科技余经理1 天前
餐饮预定系统架构拆解:订单链路、权限组织与私有化源码交付
java·开发语言·前端·数据库·人工智能·系统架构·php