18

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.

Fredy Rosero
  • 371
  • 1
  • 3
  • 8
  • 1
    `${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 ? – Kamlesh Paul Apr 12 '21 at 06:33
  • 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 port – Fredy Rosero Apr 12 '21 at 07:02
  • 1
    use `- '${APP_PORT:-80}:${APP_CLIENT_PORT}'` and create a new in `.env` be like `APP_CLIENT_PORT=3000` – Kamlesh Paul Apr 12 '21 at 07:07
  • @KamleshPaul what do you call "CLIENT" to? to the host or to the guest? – Fredy Rosero Apr 15 '21 at 15:50
  • 1
    client means which will consume your port `docker(HOST)` your machine is client – Kamlesh Paul Apr 16 '21 at 03:40
  • 2
    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. – Roman May 19 '21 at 09:15

6 Answers6

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

zero8
  • 1,997
  • 3
  • 15
  • 25
  • 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. – Namwanza Ronald May 08 '22 at 09:22
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

Bishal
  • 181
  • 1
  • 6
  • 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. – Namwanza Ronald May 08 '22 at 09:23
  • @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.\ – Bishal May 09 '22 at 10:38
  • well, that did not work for me either, like I said, editing my docker-composer file saved my sleepless night. – Namwanza Ronald May 11 '22 at 00:21
  • 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 [http://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.. – Manuel Jun 13 '23 at 16:04
8

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.

Fredy Rosero
  • 371
  • 1
  • 3
  • 8
  • Thanks very much! I had the same issue with sail reading the .env file and changing to LF resolved it for me. – Jamesil Jul 04 '22 at 21:46
3

add to your .env:

SERVER_PORT=3001
catomatic
  • 661
  • 8
  • 10
  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) 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. – Yunnosch Aug 28 '22 at 18:56
  • works well, simple solution. thankyou bro – Alauddin Afif Cassandra Jun 23 '23 at 07:34
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
Nahid
  • 2,911
  • 1
  • 20
  • 17
-1

you should also check this file:

vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php

and change the default port, so when you type in cmd php artisan serve it realy changes the port. just alone in env somehow doesnt work.

binding with php artisan serve --host=0.0.0.0 --port=8080 works somehow just one time.

  • There's no reason to modify vendor code. Providing the port in the command line, as in your example, is sufficient. – Gsinti May 15 '23 at 21:33