Backend••11 min read•12 views

Installation and Folder Structure in Laravel

A comprehensive guide for developers to understand the foundations of the Laravel framework. Dissecting the three best installation methods and thoroughly discussing the anatomy of folder structures, configuration files, and best practices in managing scalable application architecture

Have you ever opened a frameworkproject for the first time and felt intimidated? The editor screen is filled with dozens of folders and dozens of files that seem to scream for attention. That's the experience that almost everyone feels when they run the Laravel installation command for the first time.

Move away from writing native PHP code that might just consist of a few index.php and koneksi.php in one folder, towards a modern framework architecture does require adjustments. But don't worry, this seemingly complicated architecture was actually created precisely to make our lives as developers much easier, organized, and most importantly: scalable when the project gets bigger.

In this module, we will cover everything from scratch. We will not only learn how to install Laravel, but we will thoroughly dissect the anatomy of its folder structure. Let's say we're touring the inside of a software factory; we will see where raw materials are stored, where the main machines work, and which doors customers use to enter.

Grab a cup of coffee, open your favorite terminal, and let's get started.

Preparation and Installation

Before we can dissect the anatomy of Laravel, we must first have it on our local machine. The Laravel ecosystem is very flexible and offers different ways to start a new project, depending on the development style you prefer.

The absolute requirements that must be on your computer before installing Laravel locally (without containers) are PHP and Composer. Composer is like the "Play Store" or "App Store" specifically for the PHP ecosystem. It is through Composer that we download Laravel and all its supporting libraries.

There are three main approaches that developers in the industry today typically use to install Laravel:

1. Installation via Composer Create-Project

This is the most classic way and probably the most widely used because it is very straightforward. You just need to open a terminal, navigate to the folder where you usually save projects (for example htdocs or the projects folder), then type this command:

Bash
composer create-project laravel/laravel your-app-name

The above command will tell Composer to download the latest stable version of Laravel, place it in the your-app-name folder, and install all the required dependencies. This process will also copy the file .env.example to .env and generate the application key automatically.

2. Installation via Laravel Global Installer

For those of you who work on creating lots of Laravel applications every day, using the Laravel Installer will feel much faster and more elegant. First, you have to install the installer globally on your computer via Composer:

Bash
composer global require laravel/installer

Once it's installed, whenever you need to create a new project, you just type this short command from the terminal:

Bash
laravel new your-app-name

Interestingly, in the latest versions, the laravel new command will provide a kind of interactive wizard. The terminal will ask whether you want to use a starter kit such as Breeze or Jetstream, what testing framework you want to use (PHPUnit or Pest), and what database to use. This saves a lot of initial setup time.

3. Installation via Laravel Sail (Docker-based)

Many modern software engineers now prefer to use containerization (containerization) for developmentdoes not pollute the main operating system. Laravel provides a built-in feature called Sail, which is basically an elegant CLI interface for interacting with Docker.

As a side note from the field of experience: if you happen to use macOS for development, I highly recommend using Orbstack as the container engine rather than standard Docker Desktop. Orbstack is much lighter, consumes much less memory, and the process of spin-up a container to a database or Redis via Laravel Sail is instant.

To install Laravel via Sail on a system that already has Docker (or Orbstack), run this command in the terminal:

Bash
curl -s https://laravel.build/your-application-name | bash

Once finished, all you have to do is go to the project folder and turn on the service:

Bash
cd your-app-name
./vendor/bin/sail up

Web services, MySQL databases, and Redis will come live in isolated containers, ready to use without you having to install MySQL or a web server on your own computer.

Dissecting the Anatomy of a Laravel Folder

After the installation is complete, open your project folder using your favorite code editor, such as VS Code or PhpStorm. You will be greeted by a neat row of folders. Understanding this structure is key to becoming a productive Laravel developer. Let's dissect them one by one.

Folder /app

Think of this folder as the brain and heart of your application. Almost all of the business logic (the code you write specifically for your application) will be nested here. By default, this folder follows the PSR-4 autoloading standard and is under the namespace App.

In the /app folder, you will find several important sub-folders:

  • Http: This is your application's security guard and receptionist post. Everything related to web login (HTTP) is here. Inside there are the Controllers folders (which organize the logic flow after receiving request) and Middleware (which acts as a filter, for example checking whether a user has login before allowing them to enter a certain page).

  • Models: This is where the structural representation of your database resides. Laravel uses Eloquent ORM, a tool that allows us to interact with databases like we interact with regular PHP objects. If you have a users table in your database, you will have a User.php model here.

  • Providers: This folder contains a set of Service Provider classes. They are the ones in charge of preparing and connecting the various application components when Laravel is first "turned on" (at-booting).

  • Console: If you need to create custom commands in the terminal (using php artisan), they will be saved here.

Folder /bootstrap

Not to be confused with framework CSS Bootstrap. This folder has nothing to do with CSS. The bootstrap folder in Laravel serves as the starter folder. Inside there is the file app.php which is the first script run by the framework to load everything needed. This folder also has a sub-folder cache which Laravel uses to store cache files to speed up routingand configuration. Generally, you almost never need to touch the files in this folder manually.

Folder /config

As the name suggests, this is your application control panel. All system settings—starting from database configuration (database.php), email (mail.php), zone settings time and language (app.php), to third-party connections (services.php)—are set here. Even though there are a lot of files, you don't need to memorize them. The best approach is to refer to this folder only when you really need to change Laravel's default behavior.

Folder /database

This is the memory center and data structure of your application. This folder is divided into three vital parts:

  • migrations: Think of this as version control (like Git) but specifically for your database structure. Instead of creating tables directly in phpMyAdmin or TablePlus, you write the table schema using PHP code here. This allows the database structure to be easily shared with teammates.

  • seeders: Usually used to fill the database with initial data. For example, creating a default admin account when the app is first deployed.

  • factories: Working closely with seeders, factories is used to generate thousands of fake/dummy data (usually using the Faker library) for the purposes of testing or visualizing the appearance before the real data sign in.

Folder /public

This is the front door of your application, and the only folder that is allowed to be exposed or accessed directly by the outside world (visitors' browsers). This is where the index.php file lives, serving as a single entry point (entry point) for all requests.

In addition to index.php, this folder is a great place to store static assets such as images, pre-compiled CSS files, and JavaScript files. It is important to remember during the deployment stage (for example on cPanel or VPS), make sure the Document Root of your web server points to the /public, not to the root project folder. It is a basic security practice to prevent your .env and source code files from being downloaded by hackers.

Folder /resources

If the /app folder is the brain, then the /resources folder is the face of your application. This is where uncompiled files or files that will be displayed to the user are stored.

  • views: The place where you put your application's HTML files. Laravel uses a template engine called Blade, so the files here end in .blade.php.

  • css & js: Place to store raw assets. If you use Tailwind CSS, Vue, React, or just write SASS, the raw files go here. Later, a tool like Vite (which is built into the latest Laravel) will compile it and put it in the /public folder.

Folder /routes

Think of this as a navigation map. When someone types a URL in the browser, Laravel will look at this folder to determine which page or logic should be executed.

  • web.php: Used for all routes accessed via browser. Routes here are automatically protected by security systems such as CSRF protection and support session.

  • api.php: If you build a backend application that returns a JSON response (e.g. for an mobileor third-party service), you write it here. This route is stateless (does not use session based cookie).

  • console.php: Used to define custom CLI command routes.

Folder /storage

Primary storage warehouse. As your app runs, Laravel will write all sorts of things, and they all go here. This folder contains:

  • app: Storage place for files uploaded by users (e.g. profile photos or PDF documents). So that the files in storage/app/public can be accessed from the browser, we must create a "bridge" to the /public folder using the php artisan storage:link.

  • framework: Used by Laravel itself to store session, cache, and the compiled views.

  • logs: Where the file laravel.log is nested. If your app is error or displays a blank screen (white screen of death), this is the first place you should check. This log file is like an airplane black box that records every error that occurs.

Folder /tests

As a professional software engineer, writing automated testing is a must. This folder is home to all those automated tests. There are Feature tests (testing the overall workflow of the application, such as simulating a user pressing the login) and Units tests (testing one specific function in isolation).

Folder /vendor

This is Composer's black box. Any library, package, and third-party components (including core of the Laravel framework itself) that you installwill be downloaded to this folder. The golden rule: Never modify any files in this folder manually! If you do, all your changes will be overwritten and lost when you or your coworkers run composer update. This folder is also default ignored by Git (via .gitignore).

Critical Files in Root Directory

Beyond all the folders above, there are several individual files whose role is very crucial in the application development life cycle.

1. File .env

This environment file stores the most confidential information of your application. Starting from database connection credentials (username, password, hostname), API keys from third-party services (such as payment gateway or AWS), to application status (whether it is in local development or production).

It's important to realize that this .env file should not be committed to a repository such as GitHub or GitLab. Instead, Laravel provides the file .env.example as a blueprint. Your teammates cloning the project just need to copy the .example file into their own .env and fill it in with their local credentials.

2. Files composer.json and composer.lock

composer.json is the passport of your application. This file records what third-party package is required for the application to run, the specifications of the requested PHP version, and the autoloading configuration. Meanwhile composer.lock records the absolute version of the installed package, ensuring that all developers on the team (and the production) uses the exact same version of the library, preventing the "It works on my machine" problem.

3. File artisan

This is not a folder, but rather a PHP script. artisan is the magical Command Line Interface (CLI) that Laravel includes. It is through this intermediary file that you execute various commands to speed up your work, starting from creating Controller (php artisan make:controller), carrying out database migration (php artisan migrate), to turning on the local development server (php artisan serve).

Best Practices and Mindset for Managing Laravel Structures

Understanding the function of each folder is only half the battle. Knowing where to place code as a project grows is a skill that differentiates a novice programmer from a system analyst or software engineer mature.

Avoid "Fat Controllers"

Often, beginners cram all the logic inside the Controller. The controller is tasked with receiving requests, validating the form, processing the database query, calling an external API, then returning a response. If your Controller starts to reach hundreds or thousands of rows, it means you have violated the Single Responsibility principle.

  • Best Practices: Use Laravel's built-in Form Requests feature to move validation logic outside the Controller. If you have complex business logic (for example, transaction calculations in a cashier application or Point of Sale), create a new folder inside /app, for example /app/Services or /app/Actions, and put that logic there. The controller should ideally only be the conductor who directs the traffic of the code, not the main instrument player.

Use Resource Controllers

Instead of writing manual routes one by one for CRUD operations (Create, Read, Update, Delete), utilize the php artisan make:controller ControllerName --resource command. Laravel will automatically create a standard method framework (index, create, store, show, edit, update, destroy) which drastically makes your application code uniform and easy for other developers to guess.

Conclusion

Laravel's folder structure may initially look like a labyrinth, but it is built on very mature conventions agreed upon by thousands of world-class developers. They've thought about where configurations should live, where logic should be nested, and where assets should be stored securely.

By following these conventions (rather than fighting them), you'll find that the development process becomes much smoother. You no longer need to waste time thinking about directory architecture; You can immediately focus on solving business problems and designing solutions for your application users. The more often you interact with Laravel, the more this structure will feel natural and intuitive, like home, right?

Sigit Wasis Subekti

Sigit Wasis Subekti

Software Engineer & Tech Educator

Software Engineer and Tech Educator sharing insights on web development and software architecture.