【发布时间】:2019-05-08 15:47:59
【问题描述】:
我在 unbuntu 16 上安装了两个带有 composer 的软件包:
- phpoffice/php电子表格
- setasign/fpdi-tcpdf:2.1
两个都安装好了,这是phpoffice的输出。
Using version ^1.5 for phpoffice/phpspreadsheet
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Installing markbaker/complex (1.4.7): Downloading (100%)
- Installing psr/simple-cache (1.0.1): Downloading (100%)
- Installing phpoffice/phpspreadsheet (1.5.2): Downloading (100%)
phpoffice/phpspreadsheet suggests installing mpdf/mpdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing dompdf/dompdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing jpgraph/jpgraph (Option for renderi ng charts, or including charts with PDF or HTML Writers)
Writing lock file
Generating autoload files
对于这两个我都使用了他们主页上的基本示例,例如 phpoffice 之一 (https://phpspreadsheet.readthedocs.io/en/develop/)
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
运行此程序时,我在 apache 错误日志中得到以下信息(运行 fpdi-tcpdf 时我得到类似的日志。)
[Thu Dec 06 21:14:42.835498 2018] [:error] [pid 1582] [client 192.168.223.1:53200] PHP Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/custom/excel.php on line 3
[Thu Dec 06 21:14:42.835716 2018] [:error] [pid 1582] [client 192.168.223.1:53200] PHP Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/custom/excel.php on line 3
【问题讨论】:
-
您收到此错误是因为 PHP 在您的当前文件夹中找不到
vendor/autoload.php(根据错误消息,它应该是/var/www/html/custom/vendor/autoload.php)。我建议检查您的作曲家vendor文件夹的完整路径
标签: php ubuntu composer-php