简体   繁体   English

php依赖性/软件包管理器Composer将不会安装软件包

[英]php dependency/package manager Composer will not install packages

I'm building a website with PHP framework "Slim" as my templating framework, and it recommends using composer as the package manager. 我正在使用PHP框架“ Slim”作为模板框架来构建网站,并且建议使用composer作为软件包管理器。 SO... I'm now using composer for the first time, developing locally on 64 bit Ubuntu 16.04 and composer is not installing anything into my project . 所以...我现在是第一次使用composer,是在64位Ubuntu 16.04上本地开发的,而composer 并没有在我的项目中安装任何东西

I've followed the installation instructions on the Slim Framework & Composer websites to a tee. 我已按照Slim Framework&Composer网站上的安装说明进行操作。

Basically this is the order of what I've done: 基本上,这是我所做的工作的顺序:

  1. Installed composer into /var/www/html directory [1.] 将作曲家安装到/var/www/html目录[1.]

  2. Created Slim project using Slim-Skeleton as a base 以Slim-Skeleton为基础创建了Slim项目

    php composer.phar create-project slim/slim-skeleton slimLittleTest php composer.phar create-project slim / slim-skeleton slimLittleTest

Note: the php composer.phar create-project slim/slim-skeleton command automatically creates a composer.json file, I will put the contents of that file down farther in my question. 注意: php composer.phar create-project slim/slim-skeleton命令会自动创建一个composer.json文件,我将把该文件的内容放在我的问题中。

  1. Change into that directory and run php composer.phar install 转到该目录并运行php composer.phar install

  2. Nothing is installed! 没有安装任何东西!

If I try to run php -S localhost:8080 -t public public/index.php as you're now supposed to able to (from the Slim framework website homepage tutorial) I get the following error: 如果我尝试运行php -S localhost:8080 -t public public/index.php因为您现在应该能够(来自Slim框架网站主页教程),则会出现以下错误:

[Tue Sep  5 18:55:04 2017] PHP Fatal error:  require(): Failed opening required '/var/www/html/slimLittleTest/public/../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/slimLittleTest/public/index.php on line 12
[Tue Sep  5 18:55:05 2017] PHP Warning:  
require(/var/www/html/slimLittleTest/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/slimLittleTest/public/index.php on line 12

This error of course makes sense because nothing got installed! 这个错误当然是有道理的,因为没有安装任何东西! There is no vendor/autoload.php because Composer hasn't installed anything. 没有vendor/autoload.php因为Composer尚未安装任何东西。 (By default Composer installs dependencies into the vendor folder in the root of your project) (默认情况下,Composer将依赖项安装到项目根目录中的vendor文件夹中)

SEPTEMBER 7th QUESTION UPDATE 9月7日问题更新

From some comments down below, I've been alerted to the fact that something must have gone wrong on the command composer create-project , that my solution of just re-requiring all packages shouldn't be necessary. 从下面的一些注释中,我已经意识到以下事实:命令composer create-project一定有问题,我的解决方案仅需要重新包装所有软件包就没有必要了。 Upon further inspection, I did get some errors upon running command php composer.phar create-project slim/slim-skeleton projectName . 经过进一步检查,在运行命令php composer.phar create-project slim/slim-skeleton projectName时,确实出现了一些错误。 Below is exactly what got output from the console after running that command: 下面正是运行该命令后从控制台获得的输出:

php composer.phar create-project slim/slim-skeleton tester
Installing slim/slim-skeleton (3.1.2)
  - Installing slim/slim-skeleton (3.1.2): Loading from cache
 Created project in tester
 Loading composer repositories with package information
 Updating dependencies (including require-dev)
 Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit 5.7.9 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.7.8 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.7.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
   [.......]

 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-imagick.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-mcrypt.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.

Would either that .ini extensions issue or Problem 1 php unit requires ext-dom issue be the main source of my problem? .ini extensions问题还是Problem 1 php unit requires ext-dom问题成为我问题的主要根源?

I got lucky and stumbled upon an answer that worked in my situation. 我很幸运,偶然发现了适合我情况的答案。

I just had to run php composer.phar require [package_name] , for each package name, and if it wasn't in composer.json yet that dependency would get installed. 我只php composer.phar require [package_name]为每个软件包名称运行php composer.phar require [package_name] ,并且如果不在composer.json中,则将安装该依赖项。 So what I needed to do was delete the composer.json file, then go back and require each package from it. 因此,我需要做的是删除composer.json文件,然后返回并从中要求每个软件包。 Nothing else worked, such as php composer.phar update , or php composer.phar install . 没有其他工作,例如php composer.phar updatephp composer.phar install

So I ran php composer.phar require slim/php , php composer.phar require php , etc. from the command line and everything installed correctly. 所以我从命令行运行了php composer.phar require slim/phpphp composer.phar require php ,等等,并且一切都正确安装了。

This is potentially a failure of the getting started documentation from SlimFramework.com , It's not necessarily "wrong" because maybe it works in some/most situations, but they should at least address the potential for the problem I ran into, and a solution or way to avoid it. 这可能是SlimFramework.com入门文档的失败 ,不一定是“错误的”,因为它可能在某些/大多数情况下都有效,但是它们至少应解决我遇到的问题的可能性以及解决方案或避免它的方法。

EVEN BETTER SOLUTION 更好的解决方案

Turns out that the main error I was getting here is that I was missing ext-dom . 原来,我到这里来的主要错误是我缺少ext-dom Thank you to this badass @Anar Bayramov's answer on another StackOverflow question I know that I can get the missing ext-dom by simply downloading php7.0-xml . 感谢这个坏蛋@Anar Bayramov对另一个StackOverflow问题的回答,我知道我可以通过简单地下载php7.0-xml来获得缺少的ext-dom

sudo apt-get update
sudo apt-get install php7.0-xml

And BOOM! 还有BOOM! Now when I run php composer.phar create-project slim/slim-skeleton projectName all vendor packages are installed successfully and it works like a charm. 现在,当我运行php composer.phar create-project slim/slim-skeleton projectName所有供应商软件包都已成功安装,并且像php composer.phar create-project slim/slim-skeleton projectName一样工作。 Problem solved. 问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM