Effortlessly Manage PHP Versions with “kusanagi php”

福田拓朗

This page explains how to use "kusanagi php" and how it compares to "kusanagi container".

This article explains how to use the kusanagi php command and compares it with kusanagi container.

Hello, this is Fukuda from Prime Strategy.

Did you know there’s a command that lets you switch PHP versions instantly and optimize settings automatically? That’s exactly what kusanagi php does.

For reference, in KUSANAGI 9 (Business Edition or higher), there is also an alternative called kusanagi container, which allows you to switch PHP versions per profile. We’ll explore the differences later in this article.

Switching PHP Versions with the –use Option

To switch PHP versions, simply use the --use option. As of October 26, 2023, the available options are:

  • php82 for PHP 8.2
  • php81 for PHP 8.1
  • php80 for PHP 8.0
  • php74 for PHP 7.4

This command uses dnf under the hood, which uninstalls the old version and installs the new one, so the process takes several seconds to a few minutes.

For example, when upgrading from PHP 8.1 to 8.2, you’ll see output similar to the following. Once you see Complete! followed by php completed., the switch is complete.

[root@host~]# kusanagi php --use php82 
Last metadata expiration check: 1:07:54 ago on Fri Oct 27 02:17:40 2023.                                                Dependencies resolved.                                                                                                  ================================================================================                                         Package              Architecture Version                Repository       Size                                         ================================================================================
Installing:
  kusanagi-php82       x86_64       8.2.11-1.el8           kusanagi         11 M
Installing dependencies:
  libargon2            x86_64       20171227-3.el8         epel             29 k
Removing:
  kusanagi-php81       x86_64       8.1.24-1.el8           @kusanagi        60 M                                                                                                                                                                 Transaction Summary                                                                                                     ================================================================================
Install  2 Packages
Remove   1 Package                                                                                                                                                                                                                              Total download size: 11 M 
Downloading Packages:
(1/2): libargon2-20171227-3.el8.x86_64.rpm      712 kB/s |  29 kB     00:00
(2/2): kusanagi-php82-8.2.11-1.el8.x86_64.rpm    45 MB/s |  11 MB     00:00
--------------------------------------------------------------------------------
Total                                            14 MB/s |  11 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Running scriptlet: libargon2-20171227-3.el8.x86_64                        1/1
  Installing       : libargon2-20171227-3.el8.x86_64                        1/3
  Installing       : kusanagi-php82-8.2.11-1.el8.x86_64                     2/3
  Running scriptlet: kusanagi-php82-8.2.11-1.el8.x86_64                     2/3
  Erasing          : kusanagi-php81-8.1.24-1.el8.x86_64                     3/3
  Running scriptlet: kusanagi-php81-8.1.24-1.el8.x86_64                     3/3
  Verifying        : libargon2-20171227-3.el8.x86_64                        1/3
  Verifying        : kusanagi-php82-8.2.11-1.el8.x86_64                     2/3
  Verifying        : kusanagi-php81-8.1.24-1.el8.x86_64                     3/3

Installed:
  kusanagi-php82-8.2.11-1.el8.x86_64       libargon2-20171227-3.el8.x86_64
Removed:
  kusanagi-php81-8.1.24-1.el8.x86_64

Complete!
php completed.

⚠️ Please be sure to confirm compatibility with your applications before switching versions.

Reference: PHP Versions Compatible with WordPress on KUSANAGI

PHP VersionWordPress version that worksPHP EOL Date
7.45.3 or higherNovember 28, 2022
8.05.6 or higherNovember 26, 2023
8.15.9 or higherNovember 25, 2024
8.26.1 or higherDecember 8, 2025

As you can see, PHP 7.4 is already past its end of life (EOL). Therefore, support for PHP 7.4 will soon be removed in KUSANAGI 9.

Restarting PHP and Optimizing Settings

If you’ve changed settings or encountered issues requiring a PHP restart, you typically use systemctl restart php-fpm. But with KUSANAGI, it’s much simpler.

Just run kusanagi php with no options. It will restart PHP and also optimize the instance settings if needed. Once php completed. is displayed, the restart was successful.

Comparing kusanagi php and kusanagi container

Both kusanagi php and kusanagi container deal with PHP, but they work differently:

Featurekusanagi phpkusanagi container
AffectsHost PHP (system-wide)Per-profile using Podman
Version switchingGlobalPer profile
Container requiredNoYes
Setup complexitySimpleMay require additional configuration

Pros of kusanagi php

  • Automatically optimizes configuration after changes.
  • Available on all editions of KUSANAGI 9—not just Business Edition or higher.
  • No need to modify WordPress settings during initial setup.

A Double-Edged Sword: Version Switching for All Profiles

A key characteristic of kusanagi php is that it changes the PHP version for all profiles at once (if you’re not using containers). This can be both a benefit and a drawback.

  • Pros:
    • Easier to apply security patches, feature updates, and performance improvements.
    • No need to update versions one profile at a time.
  • Cons:
    • If a new PHP version includes breaking changes, an across-the-board upgrade could break one or more sites.

Cons of kusanagi php

You cannot run multiple PHP versions simultaneously. All profiles must use the same version.
For example, if you want to try out new features in PHP 8.2 on one profile but still need PHP 7.4 on another, kusanagi php alone won’t support that.

Conclusion

We’ve explored the features of kusanagi php and how it compares to kusanagi container.
We hope this helps you better understand how KUSANAGI handles PHP version management.

References

<< Using PostgreSQL with KUSANAGI 9

関連記事

Webサイト運用の課題解決事例100選 プレゼント

Webサイト運用の課題を弊社プロダクトで解決したお客様にインタビュー取材を行い、100の事例を108ページに及ぶ事例集としてまとめました。

・100事例のWebサイト運用の課題と解決手法、解決後の直接、間接的効果がわかる

・情報通信、 IT、金融、メディア、官公庁、学校などの業種ごとに事例を確認できる

・特集では1社の事例を3ページに渡り背景からシステム構成まで詳解