Laravel 11 for Beginners: Installing on MacOS and Windows

Arlind Musliu Portrait
Arlind Musliu

January 2, 2024 · 5 min read

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, Homebrew is a popular package manager that simplifies installations, while Windows users often prefer Laragon for a hassle-free setup. 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. Additionally, we recommend Laragon:

Step 1: Install Laragon

Download the Laragon full version from the official website and follow the installation instructions. Open Laragon and start its services. Laragon includes PHP, MySQL, and Apache out of the box.

Step 2: Install Composer and Node.js

Laragon makes it easy to install Composer. Open Laragon and click on "Menu" > "Tools" > "Quick add" and select "Composer" from the list. Click on "Menu" > "Tools" > "Quick add" and select "Node.js" from the list.

After you have installed PHP and Composer, you may create a new Laravel project via Composer's create-project command:


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

Laragon includes MySQL. You can access the database via Laragon's "Database" menu, which opens up phpMyAdmin, where you can manage your databases. 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 Laragon (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.

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 using Homebrew or on Windows using Laragon. 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!