User

Laravel and PHP Versions

PHP version requirements for Laravel 10 and 11, and how to switch PHP versions for a Laravel application in Opterius.

Last updated 1775606400

PHP Version Requirements

Laravel version Minimum PHP Recommended
Laravel 10 PHP 8.1 PHP 8.2 or 8.3
Laravel 11 PHP 8.2 PHP 8.3 or 8.4

Opterius supports PHP 8.1, 8.2, 8.3, and 8.4. All four are available per domain.

Switching PHP Version

  1. Go to Hosting Mode → PHP.
  2. Click the domain running your Laravel app.
  3. Under PHP Version, select the target version.
  4. Click Save.

The panel rewrites the Nginx vhost and FPM pool config and reloads both services. The switch is immediate.

For full details on what changes and what does not carry over between PHP versions, see Switching PHP Version.

After Switching: Clear Laravel Caches

Laravel caches compiled configuration and routes. After switching PHP versions, clear them:

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

Run these from the project root:

cd /home/username/domain.com/laravel-app/
php artisan config:clear && php artisan cache:clear && php artisan route:clear && php artisan view:clear

[!NOTE] Use the versioned PHP binary if the CLI default does not yet match what you set in the panel. Example: php8.3 artisan config:clear.

Checking Composer Dependency Compatibility

Before switching PHP versions on a production application, verify that all Composer dependencies support the target PHP version.

Check composer.json for a platform constraint under config:

"config": {
    "platform": {
        "php": "8.1"
    }
}

If set, this tells Composer which PHP version to resolve packages for. Update it to match your new target version before running composer update.

Run a dry-run check without actually updating:

composer update --dry-run

If any package reports that it requires a PHP version incompatible with your target, you will see an error. Either update that package or keep the current PHP version until a compatible release is available.

Check for packages with hard PHP version constraints:

composer show --platform-check

Common Issues After a Version Switch

500 error immediately after switching

Usually means a Composer package does not support the new PHP version. Check the Laravel log:

tail -n 50 /home/username/domain.com/laravel-app/storage/logs/laravel.log

Class not found / unexpected token errors

The OPcache may be serving bytecode compiled under the old PHP version. Clear it:

php artisan opcache:clear
# Or restart PHP-FPM (requires admin access)
sudo systemctl restart php8.3-fpm

Composer install fails after switching

If you run composer install or composer update after switching, make sure you are calling the correct PHP binary:

/usr/bin/php8.3 /usr/local/bin/composer install

[!TIP] Test PHP version switches on a staging domain before applying them to production. Spin up a subdomain, deploy a copy of the application, and switch PHP version there first.