Setting Up Laravel with Sail | Learn Laravel The Right Way

Setting Up Laravel with Sail | Learn Laravel The Right Way

Getting Started with Laravel Development

Setting Up Laravel Locally

  • There are multiple methods to set up and configure Laravel for local development, ranging from easy to complex. The simplest method is using Laravel Herd, a native development environment that operates without Docker, providing a one-click solution for getting started.
  • An alternative is Laravel Sail, which utilizes Docker to create the development environment. Sail aims to simplify the process of building Laravel applications within Docker containers.
  • Docker allows developers to run applications in isolated containers, packaging an application with its dependencies for consistent deployment across various environments. A brief overview of Docker is available in the speaker's PHP series.
  • Choosing between different installation methods depends on individual needs; options include tools like LAMP or XAMPP. Each method has its pros and cons, so it's advisable to consult documentation and select what feels most comfortable.

Installing Laravel Using Sail

  • In this course, the focus will be on using Laravel Sail with Docker. The speaker guides viewers through accessing documentation and installing necessary components.
  • Before creating a Laravel application with Sail, ensure that both Docker Desktop and WSL2 (Windows Subsystem for Linux) are installed and enabled on your system.
  • It's crucial to install Laravel within WSL2 when using Docker; otherwise, issues such as slow loading pages may arise if installed outside of WSL2.

Running Commands in Terminal

  • The speaker demonstrates how to use a curl command in the terminal to pull in Laravel into a specified directory (e.g., example-app). This process may require entering a sudo password during installation.
  • After successful installation, users can navigate into their project directory using cd commands and list files with ls to confirm that the source code is present.

Starting Containers

  • To start the application containers, users execute vendor/bin/sail up, which functions similarly to docker-compose up. This command initializes all necessary services defined in the configuration file.
  • Users can run sail up -d to launch containers in detached mode. Once initiated successfully, users can open their project in any preferred code editor (e.g., PHPStorm or VS Code).

Accessing Your Application

  • It’s important that source code resides within WSL2's Linux distribution rather than typical Windows directories (C: or D:) due to potential performance issues when running under Sail and Docker.
  • Upon navigating through directories within WSL2, users can locate their projects easily. The structure includes essential files like docker-compose.yml, preconfigured for running the Laravel application effectively.

Verifying Installation Success

  • After setting everything up correctly, users should check by visiting localhost in their browser. If successful, they will see Laravel's default welcome page indicating that everything is functioning properly.

Understanding Database Migration Issues

Reasons for Missing Sessions Table

  • The absence of the sessions table can stem from various issues, with the primary reason being that database migrations have not been executed.
  • To resolve this issue, the command vendor/bin/sail artisan migrate should be run to initiate the migration process and create all necessary tables in the database.
  • Upon executing the migration command, if there are no migrations left to run, it indicates that previous migrations have already been completed successfully.
Video description

In this episode of "Learn Laravel The Right Way," we'll go through the steps to set up Laravel using Laravel Sail. Sail uses Docker to create a development environment that's easy to work with. We'll start by making sure everything is ready on Windows with WSL2, then we'll install Laravel and get our project running. Follow along, and you'll have your Laravel setup ready to go in no time. SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL 👍 Like the video 🤝 Subscribe to the channel & turn the notifications on 💬 Post comments, any feedback is greatly appreciated ⭐ Become a Patreon: https://www.patreon.com/programwithgio THANK YOU! 🛠️ TOOLS & SERVICES I USE Laracasts - https://laracasts.com/referral/GGio Domains on Namecheap - https://namecheap.pxf.io/rnRjdQ Envato Elements - https://1.envato.market/c/2937311/298927/4662 FULL PLAYLIST - https://www.youtube.com/playlist?list=PLr3d3QYzkw2xTKNyWpm7XZ63j-HntTyvC LESSON - 3 - RESOURCES https://laravel.com/docs/11.x/installation#sail-on-windows ** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.