How to Run Old Laravel Apps with Different PHP Versions

How to Run Old Laravel Apps with Different PHP Versions

How to Run Old Laravel Apps with Different PHP Versions

ComputerKida
ComputerKida
Category: Tutorials

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

  1. Install Docker
    Get Docker from https://www.docker.com
  2. Create a Dockerfile
  3. FROM php:7.3-apache
    
    RUN docker-php-ext-install pdo pdo_mysql
    
    COPY . /var/www/html
    
    WORKDIR /var/www/html
    
  4. Create docker-compose.yml
  5. 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
    
  6. Run the App
  7. docker-compose up -d
    
  8. 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:

  1. Add the PHP PPA
  2. sudo add-apt-repository ppa:ondrej/php
    sudo apt update
    
  3. Install Specific PHP Version
  4. sudo apt install php7.3 php7.3-mbstring php7.3-xml php7.3-mysql
    
  5. Switch Between Versions
  6. sudo update-alternatives --config php
    
  7. Verify
  8. 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

  1. Install Vagrant & VirtualBox
  2. Install Homestead
  3. git clone https://github.com/laravel/homestead.git ~/Homestead
    cd ~/Homestead
    bash init.sh
    
  4. Configure Homestead.yaml
  5. sites:
      - map: laravel-app.test
        to: /home/vagrant/code/laravel-app/public
    php: "7.3"
    
  6. Run Homestead
  7. vagrant up
    
  8. Add to your /etc/hosts file:
  9. 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

  1. Check PHP Version Compatibility
    Log in to your hosting provider’s control panel (e.g., cPanel or Plesk).
  2. 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.
  3. Update .htaccess (Optional)
  4. <IfModule mime_module>
        AddType application/x-httpd-php73 .php
    </IfModule>
    
  5. Upload Your Laravel Project
    Use FTP or File Manager to upload the project.
  6. Set Permissions
  7. chmod -R 775 storage bootstrap/cache
    
  8. Update .env
    Configure database and environment settings.
  9. Run Composer (if supported)
  10. 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?

Share:

Related Posts

Laravel CRUD Operation Step by Step

Laravel CRUD Operation Step by Step

Learn how to build a complete Laravel CRUD (Create, Read, Update, Delete) application from scratch....

Apr 21, 2025
Prefix Your Booleans – Learn the Right Way to Name True/False Values in Programming

Prefix Your Booleans – Learn the Right Way to Name True/False Values in Programming

If you are learning languages like C++, Java, Python, or JavaScript, you must have already used bool...

Apr 15, 2025
Laravel 2025 में क्यों बहुत ज़्यादा Famous है? – पूरी जानकारी हिंदी में

Laravel 2025 में क्यों बहुत ज़्यादा Famous है? – पूरी जानकारी हिंदी में

Laravel आज के समय का सबसे पॉपुलर PHP Framework बन चुका है, और 2025 में इसकी लोकप्रियता और भी बढ़ चुक...

Mar 24, 2025
Shared Hosting के लिए Best PHP Frameworks कौन से हैं

Shared Hosting के लिए Best PHP Frameworks कौन से हैं

अगर आप Shared Hosting का इस्तेमाल कर रहे हैं और अपनी वेबसाइट या वेब एप्लिकेशन को PHP में डेवेलप करना...

Mar 24, 2025

Comments

Please login to comment. Login.

New Updates

Creating Useful Laravel Apps - A Practical Guide for Developers

In this guide, we'll explore how to create useful Laravel ap...

May 21, 2025 Read more

Laravel Route Model Binding with Slug

Laravel is known for its elegant syntax and developer-friend...

May 21, 2025 Read more

How to Run Old Laravel Apps with Different PHP Versions

Laravel, a powerful PHP framework, evolves rapidly with new...

May 21, 2025 Read more

Laravel CRUD Operation Step by Step

Learn how to build a complete Laravel CRUD (Create, Read, Up...

Apr 21, 2025 Read more

Prefix Your Booleans – Learn the Right Way to Name True/False Values in Programming

If you are learning languages like C++, Java, Python, or Jav...

Apr 15, 2025 Read more

Leaderboard Statistics

Total Users: 6
Updated Daily

Live Users

No users online

We use cookies to enhance your browsing experience and analyze our traffic. By clicking "Accept", you consent to our use of cookies. Read our Privacy Policy and Cookie Policy to learn more.