The easy way to setup macOS for Laravel app development

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.

💡
This article will cover two kinds of macOS setup (using Laravel sail and the php, composer, laravel installation)
  • 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

💡
You’ll see the pop below. Are you sure? click open to continue

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

💡
Ensure docker is running

  • Sail Setup

💡
If you do not specify which services you would like configured, a default stack of 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
💡
Of course, you can change "example-app" in this URL to anything you like - just make sure the application name only contains alpha-numeric characters, dashes, and underscores. The Laravel application's directory will be created within the directory you execute the command from. - Laravel Docs
  • 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.
💡
If you do not specify which services you would like configured, a default stack of mysql, redis, meilisearch, mailpit, and selenium will be configured. — laravel docs

Next, After the images have been installed before it proceed with the installation…

💡
To complete the installation it’ll ask for the system password

Next, change directory and run the sail up command:

cd name-of-app

./vendor/bin/sail up

💡
The application can be accessed via any of the following URL below:
http://0.0.0.0:80

OR

http://localhost/
💡
It’ll display the error below. So you’ll have to run the migration command to migrate the tables of the application

Next, run the command below to migrate the tables:

./vendor/bin/sail artisan migrate

Next, Head over to the browser to access the application:

Simple Emoji Of Someone Teaching Computer Software, Computer, Emoji,  Software PNG Transparent Image and Clipart for Free Download

💡
In the docker application under the container session you’ll see the app running also

Yep!!! We’ve got Laravel setup using sail

💡
To continue learning more about Laravel Sail, review its complete documentation.

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)"
💡
After running one of the commands above, you should restart your terminal session. To update PHP, Composer, and the Laravel installer after installing them via 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

💡
By default a new laravel application session is set to database in the env file 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

Did you find this article valuable?

Support Alemoh Rapheal Baja by becoming a sponsor. Any amount is appreciated!