Installation

Laravel can be installed in different ways, I’m going to cover those methods in this article. So sit back and enjoy. The operating system I use is Linux, so you would encounter issues on other types of OS. Maybe it is time to switch …

Install using Laravel’s installer

Laravel provides a global command (installer app) that can setup a new project for us. This command can be installed by issuing following command in a terminal:

composer global require laravel/installer

After installation is done, we can create a new project (in this example my-project) using following command:

laravel new my-project

Install using composer’s create-project command

We can initialize a new project without laravel installer. Composer has a command create-project that does just that. It is done as simple as using following command:

composer create-project laravel/laravel my-project

Using Laravel Sail

Laravel Sail is another cool package in Laravel ecosystem, that uses Docker to bring a development system up as fast as possible. It can also be used to initialize a new project, with help of an online tool (laravel.build). The usage is as follows:

curl -s "https://laravel.build/my-project" | bash

Curl is a command line tool available on Linux (and other Unix descendants Mac OSX etc.). In this example it takes an URL and access it over web, capturing and outputting the result back on the screen. The result then will be piped to bash command, which in turn execute it.

The output of above command without piping it to bash would be something like this:

docker info > /dev/null 2>&1

# Ensure that Docker is running...
if [ $? -ne 0 ]; then
    echo "Docker is not running."

    exit 1
fi

docker run --rm \
    --pull=always \
    -v "$(pwd)":/opt \
    -w /opt \
    laravelsail/php82-composer:latest \
    bash -c "laravel new my-project && cd my-project && php ./artisan sail:install --with=mysql,redis,meilisearch,mailpit,selenium "

cd my-project

# Allow build with no additional services..
if [ "mysql redis meilisearch mailpit selenium" == "none" ]; then
    ./vendor/bin/sail build
else
    ./vendor/bin/sail pull mysql redis meilisearch mailpit selenium
    ./vendor/bin/sail build
fi

CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
BOLD='\033[1m'
NC='\033[0m'

echo ""

if sudo -n true 2>/dev/null; then
    sudo chown -R $USER: .
    echo -e "${BOLD}Get started with:${NC} cd my-project && ./vendor/bin/sail up"
else
    echo -e "${BOLD}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
    echo ""
    sudo chown -R $USER: .
    echo ""
    echo -e "${BOLD}Thank you! We hope you build something incredible. Dive in with:${NC} cd my-project && ./vendor/bin/sail up"
fi

After project initialization is done we can simply enter into its directory and use following commands to bring sail up and head to the Laravel sea:

cd my-project
./vendor/bin/sail up