To install Laravel 12 on WSL2 Ubuntu with Docker on Windows 11, you can follow these steps. Note that as of my knowledge cutoff in October 2023, Laravel 12 might not be released yet, so I'll provide instructions based on the latest available version, which you can adapt once Laravel 12 is released.
Prerequisites
- WSL2 and Ubuntu: Ensure you have WSL2 set up with Ubuntu. You can install it from the Microsoft Store if you haven't already.
- Docker Desktop: Install Docker Desktop for Windows and ensure it is configured to use WSL2 as the backend.
Steps to Install Laravel with Docker
-
Open WSL2 Ubuntu Terminal: Launch your Ubuntu terminal from WSL2.
-
Install Docker in WSL2: Although Docker Desktop integrates with WSL2, you might need to ensure Docker is accessible from your WSL2 environment. You can verify this by running:
docker --versionIf Docker is not recognized, ensure Docker Desktop is running and WSL integration is enabled in Docker Desktop settings.
-
Install Composer: Laravel requires Composer, a PHP dependency manager. You can install it using the following commands:
sudo apt update sudo apt install curl php-cli php-mbstring unzip curl -sS https://getcomposer.org/installer -o composer-setup.php php composer-setup.php --install-dir=/usr/local/bin --filename=composer -
Set Up a Dockerized Laravel Environment: You can use a pre-built Docker setup for Laravel. One popular choice is the
laradockorlaravel/sail. Here, I'll show you how to use Laravel Sail, which is the official Docker setup for Laravel.-
Create a new Laravel project:
curl -s "https://laravel.build/example-app" | bashReplace
example-appwith your desired project name. -
Navigate to your project directory:
cd example-app -
Start the Docker containers:
./vendor/bin/sail upThis command will build and start the Docker containers defined in the
docker-compose.ymlfile.
-
-
Access Your Laravel Application: Once the containers are up and running, you can access your Laravel application by navigating to
http://localhostin your web browser. -
Develop Your Application: You can now start developing your Laravel application. Use the
sailcommand to run Artisan commands, Composer, and other tools. For example:./vendor/bin/sail artisan migrate
Additional Tips
- Environment Variables: Ensure your
.envfile is correctly set up, especially the database connection settings, which should match the Docker services. - Docker Commands: Familiarize yourself with Docker commands to manage your containers effectively.
By following these steps, you should have a Laravel environment set up on WSL2 Ubuntu with Docker on Windows 11. Adjust the steps as necessary when Laravel 12 is officially released.