Install an Older Version of Laravel with Sail

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Downgrading Laravel with Sail: Installing Laravel 8.x on Older PHP Environments

Dealing with legacy server environments is a common challenge in software development. You find yourself needing to maintain compatibility with older PHP versions, like your existing setup running PHP 7.4.x, but the modern installation scripts automatically push you toward the latest framework releases (like Laravel 9.x). When combined with tools like Laravel Sail, this version mismatch can halt development.

This post will walk you through the developer-focused method for installing an older version of Laravel, specifically Laravel 8.x, using the Laravel Sail ecosystem, ensuring compatibility with your existing PHP environment.

The Challenge: Version Lock and Automatic Updates

The standard installation command provided by Laravel's build scripts, such as curl -s "https://laravel.build/example-app?with=mysql" | bash, is designed for ease of use by installing the absolute latest stable version available. This process pulls down dependencies tailored for current PHP standards. When you run this on a server running PHP 7.4, it often installs Laravel 9.x, which might introduce incompatibilities with older dependency chains or specific framework expectations you have, forcing an unnecessary upgrade path.

The core issue is that the automated scripts prioritize the newest releases rather than respecting existing environmental constraints. We need to bypass this default behavior and enforce a specific version constraint.

The Solution: Manual Installation via Composer within Docker Context

Since direct Composer installation on your local machine might be restricted, the most reliable method involves controlling the container build process itself. Laravel Sail is built upon Docker, which gives us granular control over the base images used for the application environment. To install an older version of Laravel, we need to explicitly tell the installer what version to target before it executes the final setup steps.

Here is the step-by-step approach to achieve this targeted installation:

Step 1: Prepare a Clean Environment

First, ensure you are operating within an environment where you can manage dependency versions. Although we cannot use the standard one-liner directly, we can leverage Docker commands to pull specific base images.

For Laravel 8 compatibility on PHP 7.4, you must ensure your Docker setup targets an image built for that era. The key is to modify the underlying installation logic if possible, or revert to a more manual dependency management approach within the Sail context.

Step 2: Forcing Laravel 8 Installation (The Practical Approach)

Instead of relying solely on the public build script, which locks into the latest release, we will use Composer directly inside a Docker setup that mimics the required environment. This gives us complete control over the version pinning.

If you are setting up Sail from scratch on your server, instead of running the automated install, you should manually create a docker-compose.yml file and define the PHP version explicitly within the service definitions.

Here is an example structure for forcing Laravel 8 dependencies:

# docker-compose.yml (Example Snippet)
version: '3.7'
services:
  app:
    build: .
    # Crucially, specify the desired PHP version compatible with Laravel 8
    image: php:7.4-fpm
    volumes:
      - .:/var/www/html
    # Ensure Sail dependencies are installed correctly for L8 requirements
    command: /bin/bash -c "composer require laravel/framework:^8.0 --no-dev && composer install"

Explanation: By explicitly setting the base image to php:7.4-fpm and then manually running composer require laravel/framework:^8.0, you bypass the automatic version detection that defaults to Laravel 9.x. This forces Composer to resolve dependencies strictly for the Laravel 8 ecosystem, ensuring compatibility with your existing PHP setup.

Conclusion

Downgrading framework installations when dealing with legacy infrastructure requires moving away from single-command scripts and embracing manual dependency management within a containerized environment. By leveraging the flexibility of Docker and explicitly specifying both the required base PHP version (7.4) and the target Laravel version (8.x) via Composer commands, you gain complete control over your deployment environment. This practice is fundamental for maintaining stability on older servers and ensures that your application seamlessly integrates with existing infrastructure, aligning perfectly with best practices discussed at laravelcompany.com.