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.2php81
for PHP 8.1php80
for PHP 8.0php74
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 Version | Supported WordPress Version | PHP EOL Date |
---|---|---|
7.4 | 5.3 or higher | November 28, 2022 |
8.0 | 5.6 or higher | November 26, 2023 |
8.1 | 5.9 or higher | November 25, 2024 |
8.2 | 6.1 or higher | December 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:
Feature | kusanagi php |
kusanagi container |
---|---|---|
Affects | Host PHP (system-wide) | Per-profile using Podman |
Version switching | Global | Per profile |
Container required | No | Yes |
Setup complexity | Simple | May require additional configuration |
Pros of kusanagi php
- Available on all editions of KUSANAGI 9—not just Business Edition or higher.
- No need to modify WordPress settings during initial setup.
- Automatically optimizes configuration after changes.
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.