Unable to set the APP_PORT on .env for Laravel Sail
Asked Answered
B

5

19

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.

Bailsman answered 12/4, 2021 at 6:16 Comment(6)
${APP_PORT:-80}:80 here ${APP_PORT:-80} this is container port which will be 8000 as php artisan serve run on that port and 80 is you local machine port i think you want to change your local machine port ?Okie
Thanks for commenting. Actually my Laravel Sail is serving on the port 80, I know by default artisan-serve one it's the 8000 but the 80 port it's the one tha 'sail up' is giving me. And I want to change my host port (on the left) I don't care the container portBailsman
use - '${APP_PORT:-80}:${APP_CLIENT_PORT}' and create a new in .env be like APP_CLIENT_PORT=3000Okie
@KamleshPaul what do you call "CLIENT" to? to the host or to the guest?Bailsman
client means which will consume your port docker(HOST) your machine is clientOkie
Hi, I have the same configuration and didn't change docker.yml file, just added APP_PORT to .env and run sail up command, now I see the app running on localhost:8000 when I access through the browser.Caterina
B
9

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.

Bailsman answered 12/6, 2021 at 17:14 Comment(1)
Thanks very much! I had the same issue with sail reading the .env file and changing to LF resolved it for me.Ridotto
H
18

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

Hobbism answered 29/5, 2021 at 9:44 Comment(1)
Well, this did not solve my problem, I had to go to docker-composer.yml file in my laravel project and edited these two lines for the port from '${APP_PORT:-80}:80' to '${APP_PORT:-89}:80' and ${HMR_PORT:-808-}:8080' ----> ${HMR_PORT:-8084}:8080' and everything worked like charming.Mauldin
H
17

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

Hydrogen answered 23/11, 2021 at 23:54 Comment(4)
Well, this did not solve my problem, I had to go to docker-composer.yml file in my laravel project and edited these two lines for the port from '${APP_PORT:-80}:80' to '${APP_PORT:-89}:80' and ${HMR_PORT:-808-}:8080' ----> ${HMR_PORT:-8084}:8080' and everything worked like charming.Mauldin
@NamwanzaRonald I am not sure but in your case as you are editing HMR_PORT value as well so may be if you also add "HMR_PORT=8084" on your .env file it might solve the problem of having not to edit your docker file, please let me know if this works, thanks.\Hydrogen
well, that did not work for me either, like I said, editing my docker-composer file saved my sleepless night.Mauldin
Yes it is working, although it's a little bit confusing after running the "sail up" command, I can see in the command line: "INFO Server running on [0.0.0.0:80].", which conveys the idea that the new port mapping hasn't do anything and it's still (trying) to use port 80..Aeromechanic
B
9

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.

Bailsman answered 12/6, 2021 at 17:14 Comment(1)
Thanks very much! I had the same issue with sail reading the .env file and changing to LF resolved it for me.Ridotto
C
5

add to your .env:

SERVER_PORT=3001
Copeland answered 28/8, 2022 at 18:42 Comment(2)
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Formant
When containerizing an existing Laravel 7 app in Docker, this was the needed fix. APP_PORT was ignored.Emancipation
I
0

Foollowing are the ports that you will must set / change in the .env file if any of them are already taken:

APP_PORT=8011
FORWARD_DB_PORT=3307
FORWARD_REDIS_PORT=6380
FORWARD_MEILISEARCH_PORT=7701
FORWARD_MAILHOG_PORT=1026
FORWARD_MAILHOG_DASHBOARD_PORT=8026
VITE_PORT=5174
Interior answered 12/10, 2022 at 10:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.