How to use Multiple Laravel sail project with Custom Domain

Spread the love

Running multiple Laravel Sail projects? Learn to use custom domains for clean organization and easy access.

Are you a delighted Laravel Sail user who recently transitioned from Laravel Homestead? If you previously managed multiple websites within your Homestead environment, you might be wondering how to replicate that functionality with Laravel Sail. Unfortunately, like Homestead, Laravel Sail doesn’t natively support multi-site setups. However, there’s a solution available that will allow you to work seamlessly, reminiscent of your experience with Homestead.

Laravel Sail is a fantastic tool for creating a Docker-based development environment for your Laravel applications. However, unlike Laravel Homestead, Sail doesn’t inherently support running multiple projects with custom domains. But fear not, there’s a workaround!

Benefits of Using Custom Domains

While the introduction mentions the ability to manage multiple projects, delve deeper into the benefits of using custom domains. Here are some points to consider:

  • Improved Organization: Each project has its own dedicated address, making it easier to identify and access specific applications.
  • Realistic Development Environment: Working with custom domains mimics a production environment, providing a more realistic development experience.
  • Easier Collaboration: Sharing projects with team members becomes more streamlined by using clear and memorable domain names.
image How to use Multiple Laravel sail project with Custom Domain

Before getting started, ensure you have the following in place:

  • Windows with WSL2 (Windows Subsystem for Linux 2)
  • Docker Desktop running on WSL2

To embark on this journey of managing multiple Laravel Sail projects with custom domains, there are a few prerequisites. First up, you’ll need to be running Windows 10 or 11. But that’s not all! Windows Subsystem for Linux 2 (WSL2) needs to be enabled on your system, acting as a Linux environment within Windows. Finally, to leverage the power of containers, Docker Desktop must be up and running, specifically configured to utilize WSL2. Once you’ve ensured these elements are in place, you’re ready to dive into the exciting world of custom domains for your Laravel Sail projects.

Setup Nginx Proxy Manager

Nginx Proxy Manager is a user-friendly web interface that sits in front of your Laravel Sail projects. It acts as a reverse proxy, routing traffic to the appropriate project based on the custom domain.

In this guide, we’ll utilize the user-friendly Nginx Proxy Manager tool to effectively manage our websites

1. Use wsl enter your Ubuntu

2cd ~go to your home directory in Ubuntu

3mkdir proxy-manager create a folder for this tool

4cd proxy-manager && nano docker-compose.yml for composing container
copy and paste the content below

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_SQLITE_FILE: "/data/database.sqlite"
      # Uncomment this if IPv6 is not enabled on your host
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt

5. Save & Exit

6. docker-compose up -d to start the container (to turn off: docker-compose down)

7. Type http://localhost:81 in your browser, you should be able to see the GUI

image How to use Multiple Laravel sail project with Custom Domain

Default Login

Email: admin@example.com
Password: changeme

8. Complete the necessary new account setup and come back again later.

Also, check out this blog – HOW TO EXTRACT TEXT FROM A PDF FILE IN LARAVEL?

Troubleshooting Tips

Even with the best planning, occasional hiccups might arise. Here are some troubleshooting pointers to help you navigate any challenges:

  • Port Conflicts: Double-check that you’ve assigned unique ports to each Laravel Sail project in their respective docker-compose.yml files. Conflicting ports can prevent projects from functioning correctly.
  • Hosts File Errors: Ensure there are no typos in your hosts file entries. A misplaced character can throw everything off course.
  • Nginx Proxy Manager Configuration: Verify that the Proxy Hosts within Nginx Proxy Manager are configured accurately. Incorrect domain names or port mappings will lead to routing issues.

Wrapping Up

While Laravel Sail doesn’t offer built-in multi-site functionality, fret not! Nginx Proxy Manager comes to the rescue.

With Nginx Proxy Manager, you can effortlessly manage numerous Laravel Sail projects. It streamlines access by routing traffic to the appropriate project based on your designated custom domain. This translates to a well-organized development environment, mirroring the experience of Laravel Homestead.

Leave a Comment