Speeding Up Laravel Tests with tmpfs (MySQL in RAM)
If your Laravel test suite is painfully slow and does a lot of database work (multi-tenancy, migrations, seeding), the bottleneck is almost…
I'll show you how to install Laravel Sail on your existing Laravel application that uses an older PHP version, using the correct PHP version for your project.
Before starting, you need to determine the correct versions:
composer.json:
"require": {
"php": "^7.3"
}
composer.json:
"require": {
"laravel/framework": "^8.0"
}
We'll use a Docker container to avoid relying on local PHP installation. The command format is:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php74-composer:latest \
composer require laravel/sail:^1.12 --dev --ignore-platform-reqs
Note: Replace php74 with your required PHP version (e.g., php73 for PHP 7.3).
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php74-composer:latest \
php artisan sail:install --with=mysql
This command:
--with=mysqlAfter installation, modify your docker-compose.yml file.
First, find this line:
context: ./vendor/laravel/sail/runtimes/8.2
Change it to match your PHP version:
context: ./vendor/laravel/sail/runtimes/7.4
Then, change the Node.js version to avoid npm compatibility issues. Add NODE_VERSION: '18' to the Laravel container's build args:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/7.4
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
NODE_VERSION: '18'
Then rebuild your containers:
sail down && sail build --no-cache && sail up -d
Ensure your .env file exists:
cp .env.example .env
Update your .env database configuration:
DB_HOST=mysql
DB_USERNAME=sail
DB_PASSWORD=password
./vendor/bin/sail up -d
./vendor/bin/sail artisan migrate
Add this to your ~/.bashrc or ~/.zshrc:
alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
Then reload your shell configuration:
source ~/.bashrc # or ~/.zshrc if using zsh
If you see errors about PHP version compatibility, make sure you're using the correct Sail version:
If you see errors about missing PHP extensions during installation, use the --ignore-platform-reqs flag with Composer. The actual Docker environment will include all required extensions.
If you can't connect to the database after setup, verify:
sail ps).env file has the correct database configurationGive Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com