The easy way to setup macOS for Laravel app development
The easiest way to setup macOS for developing Laravel 11 | PHP applications using Laravel sail or manual setup
Introduction
In this article, I'll guide you through setting up macOS for Laravel application development. Whether you're a beginner or an experienced developer, you'll find tips on how to build Laravel application using macOS and boost productivity. Walk with me to the end for a complete understanding.
Using Laravel Sail - Step 1
What is Laravel Sail
Laravel Sail is a lightweight CLI tool for managing Laravel's default Docker development environment. It simplifies building applications with PHP, MySQL, and Redis, even without prior Docker experience. Sail relies on a docker-compose.yml
file and a sail
script for easy container management and supports macOS, Linux, and Windows (via WSL2).
Docker Installation
Visit the docker website to download the docker for your macOS type intel or chip.
After downloading the installer, click to install the application.
Next, move the docker app to the applications folder.
Next, double click the docker icon on the desktop screen or open it from the applications folder
Next, accept the terms and conditions
- the recommended option is checked by default or you can choose advance settings and click finish
Next, Select installation type: Personal or work or you can skip
Next, after logging in with work or personal account you can participate in the survey or click skip.
There you go after clicking skip to the docker dashboard.
Next, head over to the terminal and check if the installation was done using
docker --v
Sail Setup
mysql
, redis
, meilisearch
, mailpit
, and selenium
will be configured. — laravel docs- Head over to the terminal and run the command below.
example-app
is the name of the app
curl -s "https://laravel.build/example-app" | bash
- Next, Laravel sail installation begins
- During the installation, You’ll get a pop up from docker informing you that an application wants to create a container click ok.
- Next, It’ll install a couple of images needed for Laravel application to be executed such as laravelsail/php83-composer, redis, milisearch, mysql-server.
mysql
, redis
, meilisearch
, mailpit
, and selenium
will be configured. — laravel docsNext, After the images have been installed before it proceed with the installation…
Next, change directory and run the sail up command:
cd name-of-app
./vendor/bin/sail up
http://0.0.0.0:80
OR
http://localhost/
Next, run the command below to migrate the tables:
./vendor/bin/sail artisan migrate
Next, Head over to the browser to access the application:
Yep!!! We’ve got Laravel setup using sail
If you’re new to Laravel checkout my previous article and Youtube channel for resources.
Using PHP, composer and the Laravel Installer - Step 2
Before creating your first Laravel application, your macOS machine needs the following: PHP, Composer, and the Laravel installer.
PHP
composer
Laravel installer
Additionally, install Node and NPM or Bun to manage frontend assets.
The following commands below and steps guide you on how to set them up on macOS.
PHP installation
/bin/bash -c "$(curl -fsSL https://php.new/install/mac)"
php.new
, you can re-run the command in your terminal.- Open a new terminal to add the path
export PATH="/Users/kb/.config/herd-lite/bin:$PATH"
- `or open /etc/paths to add the path permanently
sudo code /etc/paths
Next, Run the following command to confirm the php installation
php --version
- Next, Run the following command to confirm the composer installation
composer --version
- Next, Run the following command to confirm the Laravel installation
laravel --version
Next, You can then proceed to create a new application using the laravel command
laravel new app-name
- After successfully installation
Next, change directory and serve the application
SESSION_DRIVER=database
which might throw an error if you don’t have a database setup. Consider setting up any database of your choice.Conclusion
In this article, we’ve learnt an in-depth guide, complete with screenshots, to help you develop Laravel applications on macOS using two approaches: Laravel Sail and direct PHP, composer, Laravel installation. Whether you prefer the simplicity of Docker using Laravel sail or a manual setup, you now have the tools to get started efficiently.
Sure this article is useful… kindly share with your network and feel free to use the comment section for questions, answers, and contributions.
Follow me on Hashnode: Alemsbaja --- X: Alemsbaja---- Youtube: Tech with Alemsbaja to stay updated on more articles