January 2, 2024 · 5 min read · 183 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 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.
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 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
.
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.
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
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.
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
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.
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 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 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
.
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.
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!