In this lesson, you will create a Laravel application, explore its main files and folders, start the development server, and build your first working page.
Before creating a Laravel project, make sure PHP and Composer are installed correctly.
Check PHP:
php -v
Check Composer:
composer --version
Check the available PHP extensions:
php -m
If any command fails, verify your installation and PATH settings. Also confirm that your PHP version satisfies the requirements of the Laravel release you intend to install.
You can use Command Prompt or PowerShell on Windows, or a terminal on Linux and macOS.
Open your terminal in the directory where you want to store your application.
Run the following command:
composer create-project laravel/laravel student-app
This command creates a new Laravel project in a folder
named student-app and installs its
dependencies.
Move into the project folder:
cd student-app
Open the project in Visual Studio Code:
code .
The code . command requires the VS Code
command-line tool to be available in your PATH.
Composer normally installs the latest compatible Laravel release when no version constraint is specified. Installation time depends on your internet connection and computer.
Laravel automatically creates the main directories and configuration files for your application.
student-app/
|
|-- app/
| |-- Http/
| | |-- Controllers/
| |-- Models/
|
|-- bootstrap/
|-- config/
|-- database/
|-- public/
|-- resources/
| |-- views/
|
|-- routes/
| |-- web.php
| |-- console.php
|
|-- storage/
|-- tests/
|-- vendor/
|
|-- .env
|-- artisan
|-- composer.json
|-- composer.lock
Important directories:
app/ — application classes and business logic.app/Http/Controllers/ — HTTP controllers.app/Models/ — Eloquent models.resources/views/ — Blade view templates.routes/web.php — web route definitions.database/ — migrations, seeders, and factories.public/ — public entry point and public assets.vendor/ — Composer dependencies.
Keep database passwords and application secrets in
your protected environment configuration. Do not
commit your real .env file to a public
repository.
Open the terminal inside your project directory and run:
php artisan serve
Laravel will display a local development URL, commonly:
http://127.0.0.1:8000
Open the URL displayed in your terminal. You should see the Laravel welcome page if the project was installed successfully.
What is Artisan?
Artisan is Laravel's command-line interface. It provides commands for running the development server, creating controllers, managing routes, running migrations, and performing other development tasks.
Check the Laravel version:
php artisan --version
Stop the development server with
Ctrl + C in the terminal.
A route connects a URL and HTTP method to the code that handles the request.
Open routes/web.php and add this route
while keeping any existing routes you need.
<?php
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
return 'Hello from my first Laravel project!';
});
Save the file and start the development server if it is not already running.
Open this URL:
http://127.0.0.1:8000/hello
Expected output:
Hello from my first Laravel project!
The Route::get() method registers a route
for GET requests. Laravel matches the requested URL
and runs the associated callback.
Blade is Laravel's templating engine. It helps you create reusable HTML pages.
Create a file named
resources/views/welcome-student.blade.php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My First Laravel Page</title>
</head>
<body>
<h1>Welcome to Laravel</h1>
<p>This is my first Laravel view.</p>
</body>
</html>
Now update routes/web.php to return the view:
use Illuminate\Support\Facades\Route;
Route::get('/student', function () {
return view('welcome-student');
});
Visit http://127.0.0.1:8000/student to
display the page.
The view helper uses the view name without the
.blade.php extension and directory path.
You can pass data from a route or controller to a view.
Update the route in routes/web.php:
Route::get('/student-profile', function () {
$name = 'Rahul';
$course = 'Laravel Development';
return view('student-profile', [
'name' => $name,
'course' => $course
]);
});
Create
resources/views/student-profile.blade.php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Profile</title>
</head>
<body>
<h1>Student Profile</h1>
<p>Name: {{ $name }}</p>
<p>Course: {{ $course }}</p>
</body>
</html>
Open
http://127.0.0.1:8000/student-profile.
Laravel passes the values to the Blade view, and
Blade's double-brace syntax escapes output by default.
Learn these commonly used commands:
| Command | Purpose |
|---|---|
php artisan --version |
Display Laravel version. |
php artisan list |
List available Artisan commands. |
php artisan route:list |
Display registered routes. |
php artisan make:controller StudentController |
Create a controller. |
php artisan make:model Student |
Create an Eloquent model. |
php artisan make:migration create_students_table |
Create a migration file. |
php artisan serve |
Start the local development server. |
Some commands create files, while others inspect
or run parts of the application. Use
php artisan list to discover commands
available in your installed Laravel version.
Complete the following tasks to practise creating a Laravel application.
student-app./hello route.welcome-student.blade.php./student-profile route.php artisan route:list and find your routes.Challenge:
Create a page that displays your institute name, student name, course name, and current learning topic. Use a Blade view to display the information.
In the next lesson, you will explore the Laravel folder structure in more detail.
1. Which command creates a new Laravel project using Composer?
2. Which file commonly contains Laravel web routes?
3. Where are Blade view files normally stored?