Laravel Sail how to change local dev domain

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Laravel Sail how to change local dev domain on this date .

I have recently decided to try out Laravel Sail instead of my usual setup with Vagrant/Homestead. Everything seems to be beautifully and easily laid out but I cannot seem to find a workaround for changing domain names in the local environment.

I tried serving the application on say port 89 with the APP_PORT=89 sail up command which works fine using localhost:89 however it seems cumbersome to try and remember what port was which project before starting it up.

I am looking for a way to change the default port so that I don’t have to specify what port to serve every time I want to sail up. Then I can use an alias like laravel.test for localhost:89 so I don’t have to remember ports anymore I can just type the project names.

I tried changing the etc/hosts file but found out it doesn’t actually help with different ports

I essentially am trying to access my project by simply typing ‘laravel.test’ on the browser for example.

Also open for any other suggestions to achieve this.
Thanks

**Update **
After all this search I actually decided to change my workflow to only have one app running at a time so now I am just using localhost and my CPU and RAM loves it, so if you are here moving from homestead to docker, ask yourself do you really need to run all these apps at the same time. If answer is yes research on, if not just use localhost, there is nothing wrong with it

Answer

To change the local name in Sail from the default ‘laravel.test’ and the port, add the following to your .env file:

APP_SERVICE="yourProject.local"
APP_PORT=89

This will take effect when you build (or rebuild using sail build --no-cache) your Sail container.

And to be able to type in ‘yourProject.local’ in your web browser and have it load your web page, ensure you have your hosts file updated by adding
127.0.0.1 yourProject.local
to your hosts file. This file is located:

  • Windows 10 – “C:WindowsSystem32driversetchosts”
  • Linux – “/etc/hosts”
  • Mac OS X – “/private/etc/hosts”

You’ll need to close all browser instances and reopen after making chnages to the hosts file. With this, try entering the alias both with and without the port number to see which works. Since you already set the port via .env you may not need to include it in your alias.

If this doesn’t work, change the .env APP_URL=http://yourProject.local:89

Ok another option, in /routes/web.php I assume you have a route set up that may either return a view or call a controller method. You could test to see if you can have this
‘return redirect(‘http://yourProject.local:89’);’ This may involve a little playing around with the routes/controller, but this may be worth looking into.