Home page: open_in_new https://laravel.com .
There are many ways to install Laravel.
Using Composer
There is a starter template for Laravel applications in Packagist. So you can install it using Composer and the create-project command:
composer create-project laravel/laravel .
It will install the starter files, and composer.json with the next dependencies:
"require": {
"php": "^8.2",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.13",
"laravel/sail": "^1.41",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5.3"
}
As well as a series of commands will be executed (take a look at the scripts section of the composer.json file).
Let’s take Docker
With Docker, it can be more simple because we don’t need to install PHP and Composer on the local machine.
Also, instead of using the official Composer image, I will prefer to use images created by the Laravel team (open_in_new laravelsail ). This way we will avoid situations when some PHP extensions are missing.
docker run --rm \
--interactive \
--tty \
--volume "$(pwd):/var/www/html" \
--workdir /var/www/html \
--user $(id -u):$(id -g) \
laravelsail/php84-composer \
composer create-project laravel/laravel .
Currently, Docker Hub has the next images from this organization:
laravelsail/php84-composerlaravelsail/php83-composerlaravelsail/php82-composerlaravelsail/php81-composerlaravelsail/php80-composerlaravelsail/php74-composerlaravelsail/php73-composer
Using Laravel Sail
Laravel Sail is a light-weight command-line interface for interacting with Laravel’s default Docker development environment.
At its heart, Sail is the
docker-compose.ymlfile and the sail script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by thedocker-compose.ymlfile.
Installation:
curl -s https://laravel.build/example-app | bash
curl -s https://laravel.build/example-app?with=mysql,redis | bash
curl -s https://laravel.build/example-app?with=none | bash
Adding an alias for Sail:
alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
Commands
sail up
sail stop
Debugging
To start using xdebug, add the next string to the .env file:
SAIL_XDEBUG_MODE=debug
Using Laravel Installer
There is a package in Packagist that helps install Laravel and different Starter Kits for Laravel:
composer global require laravel/installer
Install Laravel:
# If we install it globally:
laravel new example-app
# If we install it locally:
php vendor/bin/laravel new example-app
This tool is interactive and will ask you a couple of question about what you want to install.
We can use the open_in_new docker-laravel-installer to speed up the process:
docker run --rm -it \
-v "$(pwd):/app" \
-u $(id -u):$(id -g) \
steadfast/docker-laravel-installer \
new example
Andrew Dorokhov