Unable to set the APP_PORT on .env for Laravel Sail
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Troubleshooting APP_PORT in Laravel Sail for Windows Environments
Body:
When working on Laravel 8 with Sail, you might face issues when attempting to set the APP_PORT variable in your .env file while running it under Windows. This problem can be particularly frustrating because Ubuntu machines seem to work just fine. Let's explore why this happens and provide a solution for setting the APP_PORT on your local Windows machine.
Understanding the Issue
The error message "services.laravel.test.ports contains an invalid type, it should be a number, or an object" indicates that something is off with the ports section of your docker-compose.yml file. This occurs because Laravel Sail expects APP_PORT to be either a single port number (a string of a valid port) or a mapping of ports. If you provide a literal value like "3000" for APP_PORT, the engine assumes it's a fixed port, and in Windows, it doesn't know how to handle this as an argument for docker-compose.yml.
Solution for Setting APP_PORT with Laravel Sail
To resolve this issue, follow these steps:
1. Comment out the ports section in your docker-compose.yml file. This will temporarily disable any specific port mapping.# - '${APP_PORT:-80}:80' ...
ports:
- '${APP_PORT:-80}:80:host'
...If you prefer not to modify your docker-compose.yml file, you can always use a custom .env file for each of your environments or local machines. This allows you to keep the port settings separate for different setups.
By following these steps, you should be able to set and test the APP_PORT variable in Laravel Sail on Windows while maintaining proper communication between your application and docker-compose.yml file. Your laravel company can provide a comprehensive guide with best practices and further details on this issue for more specific use cases.