そもそも新しいサーバーを建てた理由の1つが、PHPSpreadsheetを使いたかったということなので、その前にcomposerを入れることになる。
Composer を CentOS にインストールする手順に従って
# mkdir /etc/composer
# cd /etc/composer
# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# php composer-setup.php
...
でインストール完了。
# mv /etc/composer/composer.phar /usr/local/bin/
とやっておいてから
# composer require phpoffice/phpspreadsheet
Cannot use phpoffice/phpspreadsheet's latest version 1.25.2 as it requires ext-zip * which is missing from your platform.
...
はいそうですか。
要はphp-zip
を入れればよいらしいので、ちょっと調べる。
# dnf list | grep zip
bzip2.x86_64 1.0.8-8.el9 @anaconda
bzip2-libs.x86_64 1.0.8-8.el9 @anaconda
gzip.x86_64 1.12-1.el9 @anaconda
unzip.x86_64 6.0-56.el9 @anaconda
zip.x86_64 3.0-33.el9 @anaconda
bzip2-devel.i686 1.0.8-8.el9 appstream
bzip2-devel.x86_64 1.0.8-8.el9 appstream
bzip2-libs.i686 1.0.8-8.el9 baseos
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.352.b08-2.el9_1 appstream
java-11-openjdk-javadoc-zip.x86_64 1:11.0.17.0.8-2.el9_0 appstream
java-17-openjdk-javadoc-zip.x86_64 1:17.0.5.0.8-2.el9_0 appstream
libzip.i686 1.7.3-7.el9 appstream
libzip.x86_64 1.7.3-7.el9 appstream
nbdkit-gzip-filter.x86_64 1.30.8-1.el9 appstream
pbzip2.x86_64 1.1.13-6.el9 appstream
perl-Compress-Bzip2.x86_64 2.28-5.el9 appstream
perl-Compress-Raw-Bzip2.x86_64 2.101-5.el9 appstream
php-pecl-zip.x86_64 1.19.2-6.el9 appstream
qatzip.x86_64 1.0.9-1.el9 appstream
qatzip-libs.x86_64 1.0.9-1.el9 appstream
zziplib.i686 0.13.71-9.el9 appstream
zziplib.x86_64 0.13.71-9.el9 appstream
zziplib-utils.x86_64 0.13.71-9.el9 appstream
というわけで
# dnf install -y php-pecl-zip
一応
# dnf list installed | grep php
php.x86_64 8.0.20-3.el9 @appstream
php-cli.x86_64 8.0.20-3.el9 @appstream
php-common.x86_64 8.0.20-3.el9 @appstream
php-fpm.x86_64 8.0.20-3.el9 @appstream
php-gd.x86_64 8.0.20-3.el9 @appstream
php-mbstring.x86_64 8.0.20-3.el9 @appstream
php-mysqlnd.x86_64 8.0.20-3.el9 @appstream
php-opcache.x86_64 8.0.20-3.el9 @appstream
php-pdo.x86_64 8.0.20-3.el9 @appstream
php-pecl-zip.x86_64 1.19.2-6.el9 @appstream
php-xml.x86_64 8.0.20-3.el9 @appstream
では気を取り直してもう一度。
# composer require phpoffice/phpspreadsheet
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^1.25 for phpoffice/phpspreadsheet
./composer.json has been created
Running composer update phpoffice/phpspreadsheet
Loading composer repositories with package information
Updating dependencies
Lock file operations: 10 installs, 0 updates, 0 removals
- Locking ezyang/htmlpurifier (v4.16.0)
- Locking maennchen/zipstream-php (v2.4.0)
- Locking markbaker/complex (3.0.2)
- Locking markbaker/matrix (3.0.1)
- Locking myclabs/php-enum (1.8.4)
- Locking phpoffice/phpspreadsheet (1.25.2)
- Locking psr/http-client (1.0.1)
- Locking psr/http-factory (1.0.1)
- Locking psr/http-message (1.0.1)
- Locking psr/simple-cache (3.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
- Downloading myclabs/php-enum (1.8.4)
- Downloading psr/simple-cache (3.0.0)
- Downloading psr/http-message (1.0.1)
- Downloading psr/http-factory (1.0.1)
- Downloading psr/http-client (1.0.1)
- Downloading markbaker/matrix (3.0.1)
- Downloading markbaker/complex (3.0.2)
- Downloading maennchen/zipstream-php (v2.4.0)
- Downloading ezyang/htmlpurifier (v4.16.0)
- Downloading phpoffice/phpspreadsheet (1.25.2)
- Installing myclabs/php-enum (1.8.4): Extracting archive
- Installing psr/simple-cache (3.0.0): Extracting archive
- Installing psr/http-message (1.0.1): Extracting archive
- Installing psr/http-factory (1.0.1): Extracting archive
- Installing psr/http-client (1.0.1): Extracting archive
- Installing markbaker/matrix (3.0.1): Extracting archive
- Installing markbaker/complex (3.0.2): Extracting archive
- Installing maennchen/zipstream-php (v2.4.0): Extracting archive
- Installing ezyang/htmlpurifier (v4.16.0): Extracting archive
- Installing phpoffice/phpspreadsheet (1.25.2): Extracting archive
8 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
2 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
一応マニュアルに書いてあるとおりにやってみると
/var/www/html/phpspreadsheet/index.php
<?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');
ブラウザでアドレスを叩いてみたが空白のページが見えるだけ…。
あ、そうかと思ってFTPで見たところちゃんと'hello world.xlsx'ができていた。
-
/var/www/html/直下に入れ忘れてインストールしたファイルが行方不明になったのは秘密。 ↩