DirectAdmin allows you to host multiple PHP versions simultaneously (e.g., PHP 8.1 for legacy sites and PHP 8.3 for new ones). The most reliable way to update or change these versions is via the command line using CustomBuild.
This process involves compiling PHP from source code. This is CPU-intensive and can take 10 to 30 minutes depending on your server resources. During the final switch, web services will restart briefly.
Step 1: Update CustomBuild
Before making changes, always ensure the build script itself is up to date.
cd /usr/local/directadmin/custombuild
./build update
Step 2: Configure PHP Versions
DirectAdmin supports up to 4 concurrent PHP slots (php1_release to php4_release). The php1 slot is the system default.
Example scenario: You want to set PHP 8.2 as default and keep PHP 8.1 as a secondary option.
# Set primary version to 8.2
./build set php1_release 8.2
./build set php1_mode php-fpm
# Set secondary version to 8.1
./build set php2_release 8.1
./build set php2_mode php-fpm
We strongly recommend using php-fpm mode for performance.
Step 3: Start the Compilation
Once configured, start the build process. Grab a coffee, this will take a while.
./build php
Once the process finishes successfully, rewrite the configuration files to ensure all websites pick up the changes:
./build rewrite_confs
You can verify the new default version with:
php -v
Troubleshooting Compilation Errors
Common Issue: Missing Libraries (libzip)
If the process fails with an error regarding libzip (especially on older CentOS 7 systems), you may need to remove the conflicting package and let CustomBuild compile its own version.
yum remove libzip
./build php
General Build Failures
If the compilation fails for other reasons, it is usually due to outdated OS libraries. Run the following commands to update your system headers and try again:
# For CentOS 7
yum update -y
# For AlmaLinux / Rocky Linux / CentOS 8+
dnf update -y
After updating the OS, retry the PHP build:
./build php