Dorokhov.codes
02. Laravel installation
Home page: 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 (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-composer
laravelsail/php83-composer
laravelsail/php82-composer
laravelsail/php81-composer
laravelsail/php80-composer
laravelsail/php74-composer
laravelsail/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.yml
file 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.yml
file.
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
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.