January 2, 2024 · 8 min read · 5,272 views
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.
Building a modern application with Laravel requires setting up your development environment with various tools. For our daily work, we use the Laravel Herd Pro package, which has improved our performance and greatly reduced the number of bugs we encounter. We've made things simple by explaining how to install Laravel with Herd. But if you want to try something different, you can find instructions for Laravel Valet on MacOS and Laragon on Windows at the end of this article.
For MacOS users, Laravel Herd, Valet and Homebrew are popular solutions that simplify the installation, while Windows users can decide between Laravel Herd and Laragon for a hassle-free setup. We also include a step-by-step guide to installing PHP, Composer, Node.js, NPM, and setting up a database using SQLite or MySQL.
Herd already has Composer and Node.js, so you can instantly use them from the terminal.
Download Laravel Herd from the official website and follow the installation instructions.
Launch Herd and it will show as a small H icon on the top-right of your screen. Right-click on it and see if Nginx is running with a green circle next to it. If not, click Start All.
Herd uses the concept of parked paths and linked directories for serving sites. Create a new folder Sites
on your main directory. Open Herd Settings and on the Herd Paths add the newly created Site
folder. After installation, your Laravel projects are automatically found at project-name.test
.
Herd already has Composer and Node.js, so you can instantly use them from the terminal.
Download Laravel Herd from the official website and follow the installation instructions.
Launch Herd and it will show as a small H icon on the bottom-right of your screen. Right-click on it and see if Nginx is running with a green circle next to it. If not, click Start All.
Herd uses the concept of parked paths and linked directories for serving sites. Create a new folder Sites
on your Desktop. Open Herd Settings and on the Herd Paths add the newly created Sites
folder. After installation, your Laravel projects are automatically found at project-name.test
.
Open your terminal and navigate to your Site
directory before installing Laravel.
Once you have PHP, Composer, Node.js, and NPM installed (through Laravel Herd or individually), 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
.
We will show you how to set up SQLite and MySQL. It's up to you to decide which one to use. Just a heads-up, SQLite is the go-to database by default for Laravel 11. That's why we will keep it simple with SQLite for now, but at the end of the article, you can also learn how to install MySQL if you want.
With the new Laravel 11 installation, the migration process occurs automatically during the installation, so the command php artisan migrate
is not needed for now.
Keep in mind: If you clone an existing Laravel project, the SQLite file may be missing. You have to run the command touch database/database.sqlite
and it will make the database.sqlite
file in the database folder of the project you cloned locally.
If you're using Laravel Herd or Valet, you can simply visit http://blog.test
in your browser. The same applies even if you're a Windows user using Laravel Herd or Laragon.
Laravel Herd has the Sites tab where you can see the links and settings for each project you create. You can also switch from HTTP to HTTPS if needed. You can choose a different PHP version for each project as required and Herd will do it automatically for you.
Your application is ready and you can start playing around with it. We recommend that you continue learning more about Laravel by following our detailed guide series Laravel 11 for Beginners: A Step-by-Step Guide to Learn the Concepts.
The rest of the article will show you how to install Laravel through Valet for MacOS and Laragon for Windows users. Feel free to skip it if you already installed Laravel Herd as we explained above and continue with the Laravel 11 for Beginners: The MVC pattern lesson.
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)"
Use Homebrew command to install PHP:
brew install php
Composer is a PHP dependency manager. Install it with Homebrew using
brew install composer
Node.js comes with NPM, and you can install both using Homebrew:
brew install node
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 as individual sites. We usually save our projects in a Sites folder on our main directory, 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
.
Laragon is a great alternative to WAMPP & XAMPP if you're familiar with those technologies. Laragon includes Composer, PHP, and many other development tools such as MySQL, Apache, Node.js, and more. It is a complete package for local development environment setup.
Make sure to download the latest version from the official Laragon site.
Just download the latest version and follow the on-screen instructions. Nothing too complicated.
Open Laragon and start the services you need. Choose Apache or Nginx as your web server to handle HTTP requests for your Laravel application. If you chose MySQL over SQLite, then you also need to start the MySQL service in Laragon.
Laragon uses a pretty URL where any Laravel project within the 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
.
Herd includes MySQL with the Pro package (which we highly recommend if you want to simplify things even more).
If you don't want to pay Herd Pro, we suggest installing MySQL with DBngin on your MacOS system, instead of manually installing it via Homebrew (if you prefer streetfighting). We also recommend installing TablePlus for managing your database data.
Laragon already has MySQL installed for you so you simply have to make sure that it's running.
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
If you're not using the services we mentioned above (Laravel Herd, Valet or Laragon), you can use the built-in PHP command to serve your Laravel application locally:
php artisan serve
This will start a development server at http://localhost:8000
.
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.
This article is part of our series Laravel 11 for Beginners: A Step-by-Step Guide to Learn the Concepts.
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
Technologies:
Related Posts
Stay up to date
Be updated with all news, products and tips we share!