PHP项目运行Composer install报错

     0评论

最近研究了一个ss面板,面板是PHP开发的,需要composer安装一些依赖。安装时碰到【Your requirements could not be resolved to an installable set of packages】、【To enable extensions, verify that they are enabled in your .ini files】错误,这里将解决过程记录下来。

尝试运行composer install,结果输出了一堆错误:

[email protected]:/vagrant# composer install Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for aws/aws-sdk-php 3.38.5 -> satisfiable by aws/aws-sdk-php[3.38.5]. - aws/aws-sdk-php 3.38.5 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system. Problem 2 - Installation request for doctrine/annotations v1.5.0 -> satisfiable by doctrine/annotations[v1.5.0]. - doctrine/annotations v1.5.0 requires php ^7.1 -> your PHP version (7.0.30) does not satisfy that requirement. Problem 3 - Installation request for gregwar/captcha v1.1.3 -> satisfiable by gregwar/captcha[v1.1.3]. - gregwar/captcha v1.1.3 requires ext-gd * -> the requested PHP extension gd is missing from your system. Problem 4 - Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0]. - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.30) does not satisfy that requirement. Problem 5 - Installation request for phar-io/manifest 1.0.1 -> satisfiable by phar-io/manifest[1.0.1]. - phar-io/manifest 1.0.1 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 6 - Installation request for phpmd/phpmd 2.6.0 -> satisfiable by phpmd/phpmd[2.6.0]. - phpmd/phpmd 2.6.0 requires ext-xml * -> the requested PHP extension xml is missing from your system. Problem 7 - Installation request for phpunit/php-code-coverage 5.2.3 -> satisfiable by phpunit/php-code-coverage[5.2.3]. - phpunit/php-code-coverage 5.2.3 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 8 - Installation request for phpunit/phpunit 6.4.4 -> satisfiable by phpunit/phpunit[6.4.4]. - phpunit/phpunit 6.4.4 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 9 - Installation request for squizlabs/php_codesniffer 2.9.1 -> satisfiable by squizlabs/php_codesniffer[2.9.1]. - squizlabs/php_codesniffer 2.9.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system. Problem 10 - Installation request for theseer/fdomdocument 1.6.6 -> satisfiable by theseer/fdomdocument[1.6.6]. - theseer/fdomdocument 1.6.6 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 11 - Installation request for theseer/tokenizer 1.1.0 -> satisfiable by theseer/tokenizer[1.1.0]. - theseer/tokenizer 1.1.0 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 12 - aws/aws-sdk-php 3.38.5 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system. - pongtan/framework v0.1.13 requires aws/aws-sdk-php 3.* -> satisfiable by aws/aws-sdk-php[3.38.5]. - Installation request for pongtan/framework v0.1.13 -> satisfiable by pongtan/framework[v0.1.13]. To enable extensions, verify that they are enabled in your .ini files: - /etc/php/7.0/cli/php.ini - /etc/php/7.0/cli/conf.d/10-mysqlnd.ini - /etc/php/7.0/cli/conf.d/10-opcache.ini - /etc/php/7.0/cli/conf.d/10-pdo.ini - /etc/php/7.0/cli/conf.d/20-calendar.ini - /etc/php/7.0/cli/conf.d/20-ctype.ini - /etc/php/7.0/cli/conf.d/20-curl.ini - /etc/php/7.0/cli/conf.d/20-exif.ini - /etc/php/7.0/cli/conf.d/20-fileinfo.ini - /etc/php/7.0/cli/conf.d/20-ftp.ini - /etc/php/7.0/cli/conf.d/20-gettext.ini - /etc/php/7.0/cli/conf.d/20-iconv.ini - /etc/php/7.0/cli/conf.d/20-json.ini - /etc/php/7.0/cli/conf.d/20-mbstring.ini - /etc/php/7.0/cli/conf.d/20-mysqli.ini - /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini - /etc/php/7.0/cli/conf.d/20-phar.ini - /etc/php/7.0/cli/conf.d/20-posix.ini - /etc/php/7.0/cli/conf.d/20-readline.ini - /etc/php/7.0/cli/conf.d/20-shmop.ini - /etc/php/7.0/cli/conf.d/20-sockets.ini - /etc/php/7.0/cli/conf.d/20-sysvmsg.ini - /etc/php/7.0/cli/conf.d/20-sysvsem.ini - /etc/php/7.0/cli/conf.d/20-sysvshm.ini - /etc/php/7.0/cli/conf.d/20-tokenizer.ini You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

错误信息很多,感觉十分不友好,不知从何处下手。其实仔细看一下,就能理出头绪。根本原因是缺少一些扩展/组件,没有安装或者没有开启。关于ini文件的警告可以不用理会,因为PHP扩展安装后它们通常会自动配置好,这里关于ini的警告根本还是扩展的缺失。扩展的问题在Problem里面都列出了,其中很多重复项,整理后就是下面几个:

数目 缺失项 版本要求 备注
5 ext-dom * * 由php-xml包提供
3 ext-simplexml * * 由php-xml包提供
2 php ^7.1 ^7.1
1 aws/aws-sdk-php 3.* 3.*
1 ext-gd * * 由php-gd包提供
1 ext-xml * * 由php-xml包提供

Google后知道备注里面的信息,我们先解决这两项。安装PHP扩展包之前查询下包名称:

# [email protected]:/vagrant# apt-cache search php7 libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module) php-all-dev - package depending on all supported PHP development packages php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP php7.0-curl - CURL module for PHP php7.0-dev - Files for PHP7.0 module development php7.0-gd - GD module for PHP php7.0-gmp - GMP module for PHP php7.0-json - JSON module for PHP php7.0-ldap - LDAP module for PHP php7.0-mysql - MySQL module for PHP php7.0-odbc - ODBC module for PHP php7.0-opcache - Zend OpCache module for PHP php7.0-pgsql - PostgreSQL module for PHP php7.0-pspell - pspell module for PHP php7.0-readline - readline module for PHP php7.0-recode - recode module for PHP php7.0-snmp - SNMP module for PHP php7.0-sqlite3 - SQLite3 module for PHP php7.0-tidy - tidy module for PHP php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.0-xmlrpc - XMLRPC-EPI module for PHP libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library) php7.0-bcmath - Bcmath module for PHP php7.0-bz2 - bzip2 module for PHP php7.0-enchant - Enchant module for PHP php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.0-imap - IMAP module for PHP php7.0-interbase - Interbase module for PHP php7.0-intl - Internationalisation module for PHP php7.0-mbstring - MBSTRING module for PHP php7.0-mcrypt - libmcrypt module for PHP php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary) php7.0-soap - SOAP module for PHP php7.0-sybase - Sybase module for PHP php7.0-xsl - XSL module for PHP (dummy) php7.0-zip - Zip module for PHP php7.0-dba - DBA module for PHP php7.2-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.2-common - documentation, examples and common module for PHP

知道了包名称直接安装就可以了:

# [email protected]:/vagrant# apt install php7.0-xml Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: php7.0-xml 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 113 kB of archives. After this operation, 479 kB of additional disk space will be used. Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 php7.0-xml amd64 7.0.30-0ubuntu0.16.04.1 [113 kB] Fetched 113 kB in 1s (108 kB/s) Selecting previously unselected package php7.0-xml. (Reading database ... 186099 files and directories currently installed.) Preparing to unpack .../php7.0-xml_7.0.30-0ubuntu0.16.04.1_amd64.deb ... Unpacking php7.0-xml (7.0.30-0ubuntu0.16.04.1) ... Setting up php7.0-xml (7.0.30-0ubuntu0.16.04.1) ... Creating config file /etc/php/7.0/mods-available/dom.ini with new version Creating config file /etc/php/7.0/mods-available/simplexml.ini with new version Creating config file /etc/php/7.0/mods-available/wddx.ini with new version Creating config file /etc/php/7.0/mods-available/xml.ini with new version Creating config file /etc/php/7.0/mods-available/xmlreader.ini with new version Creating config file /etc/php/7.0/mods-available/xmlwriter.ini with new version Creating config file /etc/php/7.0/mods-available/xsl.ini with new version

# [email protected]:/vagrant# apt install php7.0-gd Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: php7.0-gd 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 27.1 kB of archives. After this operation, 134 kB of additional disk space will be used. Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 php7.0-gd amd64 7.0.30-0ubuntu0.16.04.1 [27.1 kB] Fetched 27.1 kB in 0s (32.9 kB/s) Selecting previously unselected package php7.0-gd. (Reading database ... 186120 files and directories currently installed.) Preparing to unpack .../php7.0-gd_7.0.30-0ubuntu0.16.04.1_amd64.deb ... Unpacking php7.0-gd (7.0.30-0ubuntu0.16.04.1) ... Setting up php7.0-gd (7.0.30-0ubuntu0.16.04.1) ... Creating config file /etc/php/7.0/mods-available/gd.ini with new version

再次运行composer install,只有下面的错误信息了,都指向PHP的版本。

[email protected]:/vagrant# composer install Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for doctrine/annotations v1.5.0 -> satisfiable by doctrine/annotations[v1.5.0]. - doctrine/annotations v1.5.0 requires php ^7.1 -> your PHP version (7.0.30) does not satisfy that requirement. Problem 2 - Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0]. - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.30) does not satisfy that requirement. Problem 3 - doctrine/annotations v1.5.0 requires php ^7.1 -> your PHP version (7.0.30) does not satisfy that requirement. - zircote/swagger-php 2.0.12 requires doctrine/annotations * -> satisfiable by doctrine/annotations[v1.5.0]. - Installation request for zircote/swagger-php 2.0.12 -> satisfiable by zircote/swagger-php[2.0.12].

到这一步,只剩下PHP版本的问题了,不过我不想为了doctrine去升级PHP版本,所以采用了下面的workaround:

composer install --ignore-platform-reqs

更新:后来频繁遇到此类问题,我将PHP更新到7.1了,记录在将Ubuntu16.04的PHP升级到7.1并更新扩展一文。

问题解决!

关于PHP的版本问题,另有下面的办法,不过运行update时很久没反应,我直接Ctrl-C了。这个办法GitHub上很多人点赞,应该没问题:

修改根目录下面的composer.json,在文件末尾修改/添加config选项:

"config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true, "platform": {"php": "[WHATEVER YOUR SERVER PHP VERSION IS E.G: 7.0]"} }

保存关闭上面的文件后,运行composer update

重新运行composer install

参考资料

-- EOF --

本文最后修改于2年前 (2018-06-19)

差评不太行一般挺好非常不错 (No Ratings Yet)
读取中...
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址