Laravel 11 for Beginners: Installing on MacOS and Windows

Arlind Musliu Portrait
Arlind Musliu

January 2, 2024 · 5 min read · 955 views

Laravel Blogpost Image

2024 UPDATE - LARAVEL 11

We're excited to announce that we have updated all of our blog post examples to reflect the new Laravel 11 version! Our previous examples were based on Laravel 10, but with the release of Laravel 11, we wanted to ensure that our readers have access to the most up-to-date information and examples.

Install Laravel on MacOS / Windows

Building a modern application with Laravel requires setting up your development environment with various tools. For MacOS users, Laravel Herd and Homebrew are popular package managers that simplify the installation, while Windows users often prefer Laragon for a hassle-free setup. Laravel Herd is also available for Windows. Here's a step-by-step guide to installing PHP, Composer, Node.js, NPM, and setting up a database using SQLite or MySQL.

Laravel Installation For MacOS

Step 1: Install Homebrew

Open the Terminal and run the following command to install Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install PHP

Use Homebrew command to install PHP:

brew install php

Step 3: Install Composer

Composer is a PHP dependency manager. Install it with Homebrew using

brew install composer

Step 4: Install Node.js and NPM

Node.js comes with NPM, and you can install both using Homebrew:

brew install node

Step 5: Install Laravel Valet

Install Valet with Composer and you will be able to access your site with blog.test. First run:

composer global require laravel/valet

Then run the following:

valet install

With Valet, you use the park command in a directory to serve all projects within as individual sites. We usually save our projects in a Sites directory on our Desktop, feel free to do the same. Navigate to your projects directory, for example cd Sites , then run:

valet park

Now, any Laravel project within this directory can be accessed via the <project-name>.test URL. For example, if your Laravel blog directory is named blog, you can access it at blog.test.


Laravel Installation For Windows

Before creating your first Laravel project

Make sure that your local machine has PHP and Composer installed. If you are developing on macOS or Windows, PHP and Composer can be installed in minutes via Laravel Herd.

Step 1: Install Laravel Herd

Download Laravel Herd from the official website and follow the installation instructions. Open Herd and start its services.

Step 2: Install Composer and Node.js

Herd already has Composer and Node.js included so you can instantly use them from the terminal.


Starting your first Laravel app

Step 1: Laravel Install

Once you have PHP, Composer, Node.js, and NPM installed, you can install Laravel using Composer:

composer create-project laravel/laravel blog

This command will create a new Laravel project in a directory called blog.

You could also install the Laravel installer and then it's even easier to start your app.

composer global require laravel/installer

Then you simply run the following command to install a fresh Laravel app:

laravel new blog

Step 2: Setting Up the Database

We will show you how to set up SQLite or MySQL in this guide. It's up to you to decide which one. Just a heads-up, with Laravel 11, SQLite is the go-to database by default.

SQLite - MacOS and Windows

Update your .env file:

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=blog
# DB_USERNAME=root
# DB_PASSWORD=

We need to comment out (put a # sign in front of them) the rest of the database configuration when using SQLite because we don't need them. We can simply run the following command and it will ask if we want to create the database. Choose yes and it will do it for you.

php artisan migrate

MySQL

Install MySQL for MacOS

We strongly suggest that you install DBngin for MySQL on your MacOS system, but you can also manually install it via Homebrew if you prefer streetfighting.

Install MySQL for Windows

Herd includes MySQL with the Pro package. Or you can install MySQL from the official website. After you complete the installation, add a new database named blog.

Update .env file - MacOS and Windows

Update your Laravel .env file to use the MySQL blog database created in DBngin (MacOS) or Herd (Windows).

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=

Now, simply run the migration script and you have your database ready:

php artisan migrate

Step 3: Serve Your Application

If you're using Laravel Valet and you've parked your directory, you can simply visit http://blog.test in your browser. Or, if you're a Windows user and using Laragon, the same applies. Laravel Herd has the Sites tab where you can see the links and settings for each project that you create.

If you're not using Valet or Laragon, you can use the built-in PHP server to serve your Laravel application locally:

php artisan serve

This will start a development server at http://localhost:8000.

Conclusion

With these steps, you've set up your development environment on MacOS and Windows using Laravel Herd. You might have also chosen to use Homebrew for MacOS or Laragon for Windows. Now you have PHP, Composer, Node.js, NPM, and a database ready to go for your Laravel application project. Laravel's simplicity and elegance, combined with these tools, make for a powerful development experience, whether you're a beginner or an experienced developer.

Upcoming Articles in the Series

  1. Laravel for Beginners: The MVC pattern

  2. Laravel for Beginners: Model Relationships

  3. Laravel for Beginners: Laravel Migrations


Bring Your Ideas to Life 🚀

If you need help with a Laravel project let's get in touch.

Lucky Media is proud to be recognized as a Top Laravel Development Agency

Arlind Musliu Portrait
Arlind Musliu

Cofounder and CFO of Lucky Media

Technologies:

Laravel
Heading Pattern

Related Posts

Stay up to date

Be updated with all news, products and tips we share!