PHP Version Switching in DirectAdmin โ
DirectAdmin supports multiple simultaneous PHP versions via CustomBuild 2.0. Each domain can run a different PHP version โ useful when hosting a mix of legacy and modern applications.
Installing PHP versions (server admin) โ
PHP versions are installed via CustomBuild on the server via SSH:
bash
cd /usr/local/directadmin/custombuild
# See current PHP configuration
./build options | grep php
# Set PHP version slots (up to php4)
./build set php1_release 8.3
./build set php2_release 8.2
./build set php3_release 8.1
./build set php4_release 7.4 # legacy only if needed
# Set PHP mode (php-fpm recommended)
./build set php1_mode php-fpm
./build set php2_mode php-fpm
# Build and install
./build php n # n = number of PHP versions configured
./build rewrite_confsThis takes 10โ20 minutes per version. The server stays online during the build.
Switching PHP per domain (user level) โ
Once multiple versions are installed, users can switch PHP version for each domain:
- Log into DirectAdmin as the user.
- Go to Extra Features โ PHP Version Selector.
- Select the domain from the dropdown.
- Choose the PHP version from the list of installed versions.
- Click Save.
Changes take effect immediately โ no restart needed.
Checking the active PHP version โ
From the domain's document root via SSH:
bash
php -v
# Or create a phpinfo file temporarily
echo "<?php phpinfo();" > /home/username/public_html/info.php
# Visit https://yourdomain.com/info.php
# Delete it afterwards
rm /home/username/public_html/info.phpCustomizing PHP settings per domain โ
DirectAdmin allows custom php.ini values per domain via .htaccess:
apache
# In .htaccess (PHP-FPM mode)
php_value memory_limit 512M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300Or through the user panel: Extra Features โ PHP Configuration (if enabled).
Verifying PHP-FPM is running โ
bash
# Check PHP-FPM pools
ps aux | grep php-fpm
# Check which PHP-FPM version is running for a user
ls /var/www/php-fpm/username/Use PHP 8.2 or 8.3 for new sites
PHP 8.2+ is significantly faster than 7.4 and 8.0. New WordPress sites should default to 8.2 or 8.3. Only use older versions for legacy code that hasn't been updated. 
