はじめに
レンタルサーバーの管理画面でPHPのバージョンを指定したのに、SSHした環境では設定したPHPが反映されていなかったことがありました。
SSHした環境でもPHPのバージョン設定を反映させるやり方をご紹介します。
環境
- レンタルサーバーはロリポップ
- 管理画面ではPHP8.1を設定したが、SSH環境ではPHP8.0が適用されている
事象
composerを使ったときにPHPバージョンが8.1以上でないため実行できないことがありました。
管理画面ではPHP8.1を設定したから問題ないはず・・・。
$ composer require drupal/admin_toolbar drupal/devel drupal/devel_kint_extras drupal/shield drupal/restui drupal/eva
Using version ^3.4 for drupal/admin_toolbar
Using version ^5.1 for drupal/devel
Using version ^1.1 for drupal/devel_kint_extras
Using version ^1.7 for drupal/shield
Using version ^1.21 for drupal/restui
Using version ^3.0 for drupal/eva
./composer.json has been updated
Running composer update drupal/admin_toolbar drupal/devel drupal/devel_kint_extras drupal/shield drupal/restui drupal/eva
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- drupal/core 10.1.7 requires php >=8.1.0 -> your php version (8.0.30) does not satisfy that requirement.
- drupal/shield 1.7.0 requires drupal/core ^9.2 || ^10 -> satisfiable by drupal/core[10.1.7].
- Root composer.json requires drupal/shield ^1.7 -> satisfiable by drupal/shield[1.7.0].
You can also try re-running composer require with an explicit version constraint, e.g. "composer require drupal/admin_toolbar:*" to figure out if any version is installable, or "composer require drupal/admin_toolbar:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
PHPバージョンを確認すると確かにPHP8.1ではなく8.0系が適用されている。
$ php -v
PHP 8.0.30 (cli) (built: Aug 7 2023 10:05:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
解消方法: PHPのパスを通す
(ロリポップの場合は)/usr/local/phpにPHPの実行ファイルがあるため、どのバージョンが使用できるかを確認する。
$ ls -la /usr/local/php/
合計 10
drwxr-xr-x 7 root root 61 4月 10 2023 .
drwxr-xr-x 8 root root 78 5月 27 2021 ..
drwxr-xr-x 8 root root 2048 5月 27 2022 7.3
drwxr-xr-x 8 root root 2048 11月 4 2022 7.4
drwxr-xr-x 8 root root 2048 8月 7 10:19 8.0
drwxr-xr-x 8 root root 2048 11月 24 10:19 8.1
drwxr-xr-x 8 root root 2048 11月 24 10:40 8.2
下記コマンドでパスを通す。
「8.1」の部分は先ほど確認したバージョンの中なら任意で問題ないです。
$ export PATH=/usr/local/php/8.1/bin:$PATH
再度composerを実行すると問題なく実行できた。
$ composer require drupal/admin_toolbar drupal/devel drupal/devel_kint_extras drupal/shield drupal/restui drupal/eva
Using version ^3.4 for drupal/admin_toolbar
Using version ^5.1 for drupal/devel
Using version ^1.1 for drupal/devel_kint_extras
Using version ^1.7 for drupal/shield
Using version ^1.21 for drupal/restui
Using version ^3.0 for drupal/eva
./composer.json has been updated
Running composer update drupal/admin_toolbar drupal/devel drupal/devel_kint_extras drupal/shield drupal/restui drupal/eva
Loading composer repositories with package information
Updating dependencies
Lock file operations: 10 installs, 0 updates, 0 removals
- Locking doctrine/common (3.4.3)
- Locking doctrine/event-manager (2.0.0)
- Locking doctrine/persistence (3.2.0)
- Locking drupal/admin_toolbar (3.4.2)
- Locking drupal/devel (5.1.2)
- Locking drupal/devel_kint_extras (1.1.0)
- Locking drupal/eva (3.0.0)
- Locking drupal/restui (1.21.0)
- Locking drupal/shield (1.7.0)
- Locking kint-php/kint (4.2.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
- Downloading doctrine/event-manager (2.0.0)
- Downloading doctrine/persistence (3.2.0)
- Downloading doctrine/common (3.4.3)
- Downloading drupal/admin_toolbar (3.4.2)
- Downloading kint-php/kint (4.2.3)
- Downloading drupal/devel (5.1.2)
- Downloading drupal/devel_kint_extras (1.1.0)
- Downloading drupal/eva (3.0.0)
- Downloading drupal/restui (1.21.0)
- Downloading drupal/shield (1.7.0)
- Installing doctrine/event-manager (2.0.0): Extracting archive
- Installing doctrine/persistence (3.2.0): Extracting archive
- Installing doctrine/common (3.4.3): Extracting archive
- Installing drupal/admin_toolbar (3.4.2): Extracting archive
- Installing kint-php/kint (4.2.3): Extracting archive
- Installing drupal/devel (5.1.2): Extracting archive
- Installing drupal/devel_kint_extras (1.1.0): Extracting archive
- Installing drupal/eva (3.0.0): Extracting archive
- Installing drupal/restui (1.21.0): Extracting archive
- Installing drupal/shield (1.7.0): Extracting archive
3 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
42 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
以上