Deploying a Laravel application to shared hosting should be straightforward—until your environment throws a PHP version mismatch. This exact issue halted one developer’s Laravel 13 deployment on Hostinger shared hosting. Despite setting PHP 8.3 in the control panel, SSH commands still used PHP 8.2, causing composer install to fail with a platform requirement error. Here’s how the problem was diagnosed and permanently fixed.
Why the Version Mismatch Happens
When Laravel 13 requires PHP 8.3, shared hosting environments like Hostinger often present a hidden disconnect between what the web server runs and what the command-line interface (CLI) uses. Hostinger’s hPanel allows users to switch PHP versions for web applications, but SSH sessions default to a system-wide PHP version unless manually adjusted.
In this case, the Laravel project’s composer.lock was generated with PHP 8.3, and the root composer.json specified "php": "^8.3". Hostinger’s web server correctly ran PHP 8.3 for browser requests, but SSH commands like php -v and composer install still referenced PHP 8.2.30. This mismatch caused Composer to refuse installation, even when updates or ignore flags were attempted.
Common Workarounds That Don’t Work
Many developers try quick fixes that ultimately create more problems:
- Running `composer update` — This attempts to resolve dependencies but fails immediately because the root
composer.jsonexplicitly requires PHP 8.3. - Using `composer install --ignore-platform-reqs` — This bypasses version checks, allowing installation to proceed, but risks runtime errors since installed packages may rely on PHP 8.3-specific features not present in the CLI environment.
- Changing PHP version only in hPanel — The hPanel’s PHP selector controls what runs in the browser via FPM, not the CLI version used in SSH sessions. This explains why the error persisted even after updating the panel.
The Correct Fix: Adjusting the $PATH Variable
Hostinger installs multiple PHP versions in parallel under /opt/alt/, with each version in its own directory (e.g., /opt/alt/php83/usr/bin/). The CLI’s php command defaults to the system version, but the correct PHP binary can be accessed directly.
To resolve the issue permanently:
- Identify the correct PHP binary
Check which PHP versions are available:
ls /opt/alt/This lists directories like php74, php80, php81, php82, php83, and php85. Locate the version required by your Laravel project.
- Prepend the correct PHP path to $PATH
Temporarily override the php command by adding the required binary path to your shell’s PATH environment variable. For PHP 8.5:
export PATH="/opt/alt/php85/usr/bin:$PATH"- Verify the change
Run php -v to confirm the CLI now uses the correct version:
php -vYou should see output like:
PHP 8.5.0 (cli) (built: ...)- Run Composer commands
With the correct PHP version in use, composer install will now proceed without platform requirement errors.
Making the Change Permanent
The export command only affects the current SSH session. To apply it automatically on login, add the line to your shell profile file.
For Bash (most common on shared hosting):
echo 'export PATH="/opt/alt/php85/usr/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcFor Zsh (less common but possible):
echo 'export PATH="/opt/alt/php85/usr/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcAfter this, every new SSH session will default to the specified PHP version, eliminating the need for manual overrides.
How This Fix Works Under the Hood
Shared hosting providers like Hostinger isolate PHP versions to support multiple customers with differing requirements. Each version is installed in a dedicated directory under /opt/alt/, and the web server (via FPM) reads the selected version from hPanel settings.
However, SSH sessions start with a default $PATH that often points to a system-wide PHP binary. By prepending the version-specific binary path to $PATH, the shell prioritizes the correct PHP version when executing commands. Since Composer reads the php command from $PATH, it now uses the intended version, allowing dependencies to install as expected.
Confirm the change with:
which phpThis should output the full path to the correct PHP binary:
/opt/alt/php85/usr/bin/phpFinal Recommendations for Laravel Deployments
This issue isn’t unique to Hostinger—similar setups exist on other cPanel-based shared hosts using alt-php. Before deploying a Laravel application, always verify that both the web server and CLI environments use the same PHP version. A simple php -v in SSH and a browser-based phpinfo() check can reveal version mismatches early.
While workarounds like ignoring platform requirements or forcing updates may seem expedient, they risk instability. Instead, use the $PATH override method to align CLI and web PHP versions permanently. This ensures consistent behavior across all environments and prevents runtime errors linked to version incompatibilities.
AI summary
Hostinger paylaşımlı barındırmada PHP versiyon uyuşmazlığı yaşadınız mı? Laravel projelerinde karşılaşılan bu sorunu çözmek için gereken adımları ve kalıcı düzeltmeyi öğrenin. Hızlı ve güvenilir yöntemler.