Back to Blog
Lesson 2 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 24, 20263 min read

Installing Laravel and Exploring Directory Structure

Learn how to use the Laravel installer to scaffold a new project and master the framework's directory structure to navigate your application with confidence.

LaravelPHPBeginnerProject SetupDirectory Structurebackend

Previously in this course, we set up our local development environment by installing PHP, Composer, and SQLite. Now that your machine is ready, we are going to perform our first project initialization and explore the directory structure that powers every Laravel application.

Creating Your First Project

The most efficient way to start a new project is by using the official Laravel installer. While you can use Composer directly, the installer provides a cleaner, more streamlined experience for scaffolding applications.

If you haven't already, install the installer globally via Composer:

Bash
composer global require laravel/installer

Once installed, you can create your new project—which we will eventually turn into our Task Manager app—by running:

Bash
laravel new task-manager

The installer will prompt you with a few configuration questions (like your preferred testing framework or starter kit). For now, you can select the defaults. Once it finishes, move into your new directory:

Bash
cd task-manager

Understanding the Directory Structure

Laravel follows a predictable, convention-over-configuration structure. While the number of files can look intimidating at first, every folder has a specific, well-defined purpose. Let’s break down the most critical directories you’ll interact with daily.

The app Directory

This is the heart of your application. Almost all of your custom code—models, controllers, and service logic—resides here.

The config Directory

Everything in your application that needs external configuration—like database credentials, mail settings, or timezones—lives here. You rarely change these files directly; instead, you'll modify your .env file, which feeds these configuration files.

The public Directory

This is the only directory accessible from the web. It contains your index.php file, which acts as the entry point for all requests to your application. You will also place your compiled assets (CSS, JavaScript, images) here. Never put your sensitive application logic or private configuration files inside public.

Other Key Folders

  • database/: Contains your migration files (which define your database schema) and database seeders.
  • routes/: This is where you define your URL endpoints. The web.php file is where we will define the routes for our Task Manager.
  • resources/: Houses your raw UI assets, including your Blade templates (the view layer) and uncompiled CSS/JS.

Hands-on Exercise: Locating Files

To ensure you are comfortable with the environment, perform these three tasks:

  1. Open your task-manager project in your code editor (VS Code, PhpStorm, etc.).
  2. Navigate to app/Models and locate the User.php file. This is an example of an Eloquent model.
  3. Open routes/web.php. You will see a single route defined that returns a welcome view.
  4. Finally, look in the config/ folder and open app.php. Scroll through the file to see how the application name and timezone are configured.

Common Pitfalls

  • Editing files in the wrong place: Beginners often try to put business logic inside the public folder. Remember: public is for assets, app is for logic.
  • Ignoring the .env file: You might be tempted to hardcode API keys or database passwords directly into the config/ files. Always use the .env file for sensitive credentials to prevent them from being committed to version control.
  • Over-complicating the structure: Laravel is designed to be simple. If you find yourself creating a massive directory tree, you are likely over-engineering. Stick to the standard structure until you have a specific reason to deviate.

Recap

In this lesson, we successfully used the Laravel installer to scaffold our task-manager project. We reviewed the directory structure, highlighting that app/ is for your core logic, config/ handles settings, and public/ is your web-facing entry point. Understanding these locations is essential for the project initialization phase of any Laravel app.

Up next: We will dive deep into the .env file and learn how to manage application configuration securely.

Similar Posts