Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set the APP_PORT on .env for Laravel Sail

I have the following problem in Windows 10 (in Ubuntu works properly):

I'm working in Laravel 8 with Sail When I create the APP_PORT variable on .env...

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_PORT=3000

...and launch the web with sail up I get this error:

services.laravel.test.ports contains an invalid type, it should be a number, or an object

This is how the docker-compose.yml looks

    version: '3'
    services:
        laravel.test:
            build:
                context: ./docker/8.0
                dockerfile: Dockerfile
                args:
                    WWWGROUP: '${WWWGROUP}'
            image: sail-8.0/app
            ports:
                - '${APP_PORT:-80}:80'
...

I know that I could just put ports: - '3000:80' but since I'm working in team and the php artisan sail:install command will overwrite the docker-compose.yml file I don't wanna change the docker-compose.yml file.

Thanks in advance.

like image 365
Fredy Rosero Avatar asked Apr 12 '21 06:04

Fredy Rosero


Video Answer


4 Answers

run sail in

sudo APP_PORT=3001 ./vendor/bin/sail up

thats the only way i made is work. is still dont know why other configurations dont allow it in .env

like image 183
zero8 Avatar answered Oct 25 '22 16:10

zero8


There’s no need to change docker-compose.yml file, just adding a line on your .env file should work:

  1. on your .env file add a line

    APP_PORT=3001 //or instead of 3001 any other port number of your choice

  2. restart Sail

    sail up

  3. Now you should be able to access your application with the port number you set on step 1

    http://localhost:3001

like image 39
Bishal Avatar answered Oct 25 '22 17:10

Bishal


The solution for Laravel Sail (Docker) on Windows 10 was changing the .env EOL from CRLF to LF. I found it out because I was trying to resolve this warnings from another issue:

./.env: line X: $'\r': command not found
/usr/bin/env: bash: No such file or directory

After I resolved that EOL conflict the sail up command was able to read all the enviroment variables. I also changed the EOL to LR in the following files:

.env
artisan
docker/7.4/start-container
docker/8.0/start-container
vendor/laravel/sail/runtimes/8.0/start-container
vendor/laravel/sail/runtimes/7.4/start-container

It's clear why this problem wasnt present on Ubuntu.

like image 28
Fredy Rosero Avatar answered Oct 25 '22 17:10

Fredy Rosero


add to your .env:

SERVER_PORT=3001
like image 1
catomatic Avatar answered Oct 25 '22 16:10

catomatic