DEV Community

drevispas
drevispas

Posted on

3 3

Setup Laravel in Local Host

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
Enter fullscreen mode Exit fullscreen mode

Install laravel installer.

composer global require "laravel/installer"
export PATH=~/.composer/vendor/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

Now you can create a new Laravel project on the working directory.

laravel new {project}
cd {project}
Enter fullscreen mode Exit fullscreen mode

Run the new project with sail tool.

composer require laravel/sail --dev
php artisan sail:install
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Lastly install a debugger for php.

# on MacOS
pecl install xdebug
# on Ubuntu
sudo apt install php-xdebug
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
janesmith profile image
Jane Smith

Looks like you're running a Laravel project on your local host using Sail! If you're running into any issues with containers or debugging, double-check your Docker setup and environment variables.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay