This guide assume you are installing on a Mac OS.
Install composer
which is a package manager for Laravel.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
Install laravel
installer.
composer global require "laravel/installer"
export PATH=~/.composer/vendor/bin:$PATH
Now you can create a new Laravel project on the working directory.
laravel new {project}
cd {project}
Run the new project with sail
tool.
composer require laravel/sail --dev
php artisan sail:install
After that docer-compser.yml
and Dockerfile
are created. For now mysql 8.0.25
and php8.0
were installed. It builds docker images and prints container logs like tail -f
. You could use sail up -d
to run containers in background.
Save the current code on github for backup.
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:{username}/laravel-example.git
git push -u origin main
Let's see what containers are running. sail
command is similar to docker-compose
command.
# list containers
sail ps
# list databases
sail exec mysql mysql -usail -ppassword -e"show databases"
Open a browser and go to http://localhost
to see Laravel.
To stop containers, open a new terminal and go to {project} directory and run down command.
sail down
Lastly install a debugger for php.
# on MacOS
pecl install xdebug
# on Ubuntu
sudo apt install php-xdebug
Top comments (0)