Skip to main content
Laravel Basics Tutorial
CHAPTER 02 Beginner

Setting Up Laravel Development Environment

Updated: May 14, 2026
15 min read

# CHAPTER 2

Setting Up Laravel Development Environment

1. Introduction

Unlike a simple HTML file, you cannot just download Laravel in a .zip file and double-click it. Laravel is a massive ecosystem of interdependent PHP packages. To install and run Laravel, you need a package manager, a local server environment, and a command-line interface. In this chapter, we will walk through the exact steps to install Composer, create a new Laravel project, and boot up your local development server.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand and install Composer (PHP's package manager).
  • Create a brand new Laravel application via the command line.
  • Configure Laravel to connect to a MySQL database.
  • Use Laravel Artisan to serve the application locally.

3. Beginner-Friendly Explanation

Imagine building a custom car. You don't manufacture the tires, the steering wheel, and the engine from scratch. You order the parts from a factory and assemble them. In PHP, Composer is the delivery truck. When you tell Composer, "I want to build a Laravel app," Composer drives to the internet, downloads the 50+ different software packages that Laravel relies on (routing, security, database connectors), and perfectly assembles them into a new folder on your computer. Once the parts are assembled, you use Artisan (Laravel's built-in mechanic) to turn the engine on.

4. Step 1: Installing Prerequisites

Before installing Laravel, your computer MUST have:
  1. 1. PHP (8.1 or higher): Installed via XAMPP (Windows/Mac) or Laravel Herd (Mac/Windows).
  1. 2. MySQL: Included in XAMPP.
  1. 3. Composer: Go to getcomposer.org, download the installer, and run it. (It will ask you where php.exe is located. If using XAMPP, it's usually C:\xampp\php\php.exe).

5. Step 2: Creating a New Laravel Project

Once Composer is installed, open your Terminal (Mac) or Command Prompt/PowerShell (Windows). Navigate to the folder where you want your code to live (e.g., your Desktop or htdocs).

Run this exact command to instruct Composer to download Laravel and create a folder named my-first-app:

bash
1
composer create-project laravel/laravel my-first-app

*Note: This will take a few minutes as Composer downloads thousands of files.*

6. Step 3: Using Laravel Artisan to Run the Server

In core PHP, we had to put our files inside C:\xampp\htdocs and use Apache. Laravel is smarter. It has a tiny web server built into it!

In your terminal, navigate inside your new project folder:

bash
1
cd my-first-app

Now, tell the Artisan mechanic to start the engine:

bash
1
php artisan serve

Your terminal will output: Server running on [http://127.0.0.1:8000]. Open your web browser and type http://127.0.0.1:8000. You will see the beautiful default Laravel welcome screen!

7. Step 4: Configuring MySQL (The .env File)

Laravel uses a hidden file called .env (Environment) to store secret database passwords. This file is never uploaded to the public internet.
  1. 1. Open XAMPP and make sure MySQL is running.
  1. 2. Go to http://localhost/phpmyadmin and create a new database called laravel_db.
  1. 3. Open your Laravel project in VS Code.
  1. 4. Find the .env file in the root directory. Modify the Database section:
env
123456
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=

Save the file. Laravel is now perfectly connected to your MySQL database!

8. Understanding the Directory Structure

When you open a Laravel project, the amount of folders is overwhelming. Here is what matters right now:
  • app/Http/Controllers/ - Where your logic goes.
  • routes/web.php - Where you define your URLs.
  • resources/views/ - Where your HTML/Blade files live.
  • public/ - The only folder the outside world can see. (It holds CSS/JS).

9. Best Practices

  • Never Commit .env: The .env file contains your super-secret database passwords. Laravel automatically configures Git to ignore this file. Never bypass this. If you put .env on GitHub, hackers will steal your database.

10. Common Mistakes

  • The "Missing Vendor Folder" Error: If you download a Laravel project from GitHub, it will not work immediately. GitHub does not store the massive vendor/ folder (the engine parts). You must open your terminal and run composer install. This tells Composer to read your project files and re-download all the missing parts.

11. Exercises

  1. 1. Explain the role of Composer in the PHP ecosystem. Why don't we just download a .zip file of Laravel?

12. Coding Challenges

  • Challenge: Successfully run composer create-project laravel/laravel task-manager in your terminal. cd into the directory, run php artisan serve, and view the homepage in your browser.

13. MCQs with Answers

Question 1

What is Composer?

Question 2

Which command is used in the terminal to start Laravel's built-in local development web server?

14. Interview Questions

  • Q: Explain the purpose of the .env file in a Laravel project. Why is it used, and what are the security implications of uploading it to a public repository?
  • Q: If you clone an existing Laravel repository from GitHub, what is the first terminal command you must run to make the application functional, and why?

15. FAQs

Q: I get an error saying 'composer is not recognized as an internal or external command'. A: This means Windows doesn't know where Composer is installed. You need to reinstall Composer and ensure you check the box that says "Add to PATH", or manually add the Composer path to your Windows Environment Variables.

16. Summary

In Chapter 2, we built our development laboratory. We learned that Composer is the magical package manager that downloads and perfectly assembles the massive Laravel framework on our computers. By utilizing the php artisan serve command, we bypassed the need for complex Apache folder configurations. Finally, by editing the .env file, we securely tethered our new Laravel application to our local MySQL database.

17. Next Chapter Recommendation

Before we write any code, we must understand *where* the code goes. Proceed to Chapter 3: Understanding MVC Architecture in Laravel.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·