我正在使用PHP框架"Slim"构建一个网站作为我的模板框架,并建议使用composer作为包管理器。所以...我现在第一次使用作曲家,在64位Ubuntu 16.04本地开发,而作曲家没有在我的项目中安装任何东西。
我已经按照Slim Framework上的安装说明进行了操作。作曲家网站到发球台。
基本上这是我所做的顺序:
将作曲家安装到/var/www/html
目录 [1。]
使用Slim-Skeleton作为基础
创建了Slim项目php composer.phar create-project slim / slim-skeleton slimLittleTest
注意:php composer.phar create-project slim/slim-skeleton
命令会自动创建一个composer.json
文件,我会将该文件的内容放在我的问题中。
转到该目录并运行php composer.phar install
什么都没安装!
如果我尝试运行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
这个错误当然有意义,因为没有安装!没有vendor/autoload.php
因为Composer没有安装任何东西。 (默认情况下,Composer会将依赖项安装到项目根目录中的vendor
文件夹中)
9月7日问题更新
从下面的一些评论中,我已经注意到composer create-project
命令一定出错的事实,我只是重新要求所有包裹的解决方案不应该是必要。经过进一步检查,我在运行命令php composer.phar create-project slim/slim-skeleton projectName
时遇到了一些错误。以下是运行该命令后从控制台获得输出的确切内容:
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.
.ini extensions
问题或Problem 1 php unit requires ext-dom
问题会成为我问题的主要来源吗?
答案 0 :(得分:0)
我很幸运,偶然发现了一个在我的情况下有效的答案。
我必须为每个软件包名称运行php composer.phar require [package_name]
,如果它不在composer.json中,那么依赖项将被安装。所以我需要做的是删除composer.json文件,然后返回并要求每个包。没有其他工作,例如php composer.phar update
或php composer.phar install
。
所以我从命令行运行了php composer.phar require slim/php
,php composer.phar require php
等,所有内容都安装正确。
这可能是来自SlimFramework.com的入门文档的失败,它不一定是“错误的”,因为它可能在某些/大多数情况下有效,但它们至少应该解决我遇到的问题的可能性,以及避免它的解决方案或方法。
更好的解决方案
原来我在这里遇到的主要错误是我缺少ext-dom 。感谢这个badass @Anar Bayramov's answer on another StackOverflow question我知道只需下载 php7.0-xml 即可获得缺失的 ext-dom 。
sudo apt-get update
sudo apt-get install php7.0-xml
和BOOM!现在,当我运行php composer.phar create-project slim/slim-skeleton projectName
时,所有供应商软件包都已成功安装,它就像魅力一样。问题解决了。