
How to Run Old Laravel Apps with Different PHP Versions
Laravel, a powerful PHP framework, evolves rapidly with new versions, updated dependencies, and performance improvements. But what if you’re handed an older Laravel project—say Laravel 5.6 or 6.x—and your system has PHP 8.2 or above? Running older Laravel applications on newer PHP versions (or vice versa) can be a real challenge.
In this article, we’ll cover how to run old Laravel apps with different PHP versions using tools like Docker, Laravel Homestead, Valet, multiple PHP installations, and even shared hosting.
Why This Matters
- Older Laravel versions have strict PHP version compatibility (e.g., Laravel 5.6 requires PHP 7.1.3 or higher, but won’t work well with PHP 8+).
- Composer packages used in the project may not be compatible with newer PHP versions.
- You may not be able to upgrade Laravel immediately due to legacy code or business constraints.Option 1: Use Docker (Recommended)
Docker allows you to spin up an environment with the specific PHP version your project needs.
Advantages
- Isolated environment per project.
- Easily switch between PHP versions.
- Works on any OS (Windows, Mac, Linux).
Steps to Set Up
- Install Docker
Get Docker from https://www.docker.com - Create a Dockerfile
FROM php:7.3-apache RUN docker-php-ext-install pdo pdo_mysql COPY . /var/www/html WORKDIR /var/www/html
- Create docker-compose.yml
version: '3.8' services: app: build: . ports: - "8080:80" volumes: - .:/var/www/html depends_on: - db db: image: mysql:5.7 environment: MYSQL_DATABASE: laravel MYSQL_ROOT_PASSWORD: root
- Run the App
docker-compose up -d
- Visit your Laravel app at: http://localhost:8080
Option 2: Install Multiple PHP Versions (Linux/macOS)
You can use tools like update-alternatives, Homebrew, or phpbrew to manage multiple PHP versions.
For Ubuntu/Debian:
- Add the PHP PPA
sudo add-apt-repository ppa:ondrej/php sudo apt update
- Install Specific PHP Version
sudo apt install php7.3 php7.3-mbstring php7.3-xml php7.3-mysql
- Switch Between Versions
sudo update-alternatives --config php
- Verify
php -v
For macOS (using Homebrew)
brew install php@7.3 brew link php@7.3 --force --overwrite
💡 Tip: Use Laravel Valet to serve apps with the right PHP version per project.
Option 3: Use Laravel Homestead
Laravel Homestead is an official pre-packaged Vagrant box with support for multiple PHP versions.
Advantages
- Comes with PHP 5.6–8.x, Composer, MySQL, Nginx, and more.
- Great for running multiple Laravel versions side by side.
Setup
- Install Vagrant & VirtualBox
- Install Homestead
git clone https://github.com/laravel/homestead.git ~/Homestead cd ~/Homestead bash init.sh
- Configure Homestead.yaml
sites: - map: laravel-app.test to: /home/vagrant/code/laravel-app/public php: "7.3"
- Run Homestead
vagrant up
- Add to your /etc/hosts file:
192.168.10.10 laravel-app.test
Visit your app at: http://laravel-app.test
Option 4: Use Shared Hosting
Many hosting providers allow you to select the PHP version per directory or account.
Advantages
- No local setup required.
- Hosting providers often handle PHP configuration.
- Easy to deploy and test older Laravel versions.
Steps to Set Up
- Check PHP Version Compatibility
Log in to your hosting provider’s control panel (e.g., cPanel or Plesk). - Select PHP Version
- In cPanel:
Navigate to Software > MultiPHP Manager, select the directory, and choose the desired PHP version. - In Plesk:
Go to Hosting Settings for your domain and choose the PHP version.
- In cPanel:
- Update .htaccess (Optional)
<IfModule mime_module> AddType application/x-httpd-php73 .php </IfModule>
- Upload Your Laravel Project
Use FTP or File Manager to upload the project. - Set Permissions
chmod -R 775 storage bootstrap/cache
- Update .env
Configure database and environment settings. - Run Composer (if supported)
composer install --no-dev php artisan config:cache php artisan route:cache
💡 If SSH is not available, run these commands locally and upload the updated filesTroubleshooting Common Issues
- Composer dependency errors: Use --ignore-platform-reqs if needed.
- Old package versions: Lock required versions in composer.json.
- Laravel Mix/npm errors: Use the correct Node.js version (nvm can help).
- Timezone or locale errors: Check php.ini and Laravel config.
Tips for Long-Term Maintenance
- Upgrade Laravel to a supported LTS version when possible.
- Use version control (e.g., Git) and containerization (e.g., Docker).
- Set up CI/CD pipelines that mirror your local PHP version.
Summary Table
Approach PHP Flexibility Setup Time OS Compatibility Best For
| Docker | ✅ High | ⏳ Moderate | ✅ All | Isolated, reproducible environments
| Multiple PHP (CLI) | ✅ Medium | ⚡ Fast | 🐧 Linux/macOS | Lightweight dev environment
| Homestead | ✅ High | ⏳ Longer | ✅ All | Full-featured dev stack
| Shared Hosting | ✅ Medium | ⚡ Fast | ✅ All | Quick deployment for legacy apps
Conclusion
Running older Laravel apps with a different PHP version doesn’t have to be a headache. Whether you're using Docker, multiple PHP installations, Homestead, or shared hosting, there’s a reliable solution for every developer’s workflow.
Stick to good practices, isolate your environments, and your legacy Laravel apps will run smoothly alongside your modern stacks.
Would you like this content saved as a downloadable .md file?