In this lesson, you will learn how to prepare your computer for Laravel development, install the required tools, create a Laravel project, and run your first Laravel application.
We will use PHP, Composer, a terminal, and a code editor. The exact PHP and extension requirements depend on the Laravel version you install.
Before installing Laravel, prepare these tools:
Laravel also requires particular PHP extensions. Check the requirements for the specific Laravel version you plan to install.
Installation overview:
Install PHP
|
v
Install Composer
|
v
Create Laravel Project
|
v
Start Development Server
|
v
Open Laravel in Browser
On Windows, you can install PHP using a package such as XAMPP or install PHP separately.
Option A: Using XAMPP
For example, the PHP executable may be located at:
C:\xampp\php\php.exe
To run PHP commands from any directory, add the appropriate PHP folder to your Windows PATH environment variable.
Verify PHP installation:
Open Command Prompt or PowerShell and run:
php -v
A successful installation displays the PHP version.
If Windows reports that php is not
recognized, verify the PATH setting or run PHP using
its full executable path.
Laravel depends on PHP extensions for features such as database connections, encryption, HTTP requests, and string processing.
Check the PHP version:
php -v
List installed PHP extensions:
php -m
Review the requirements for your Laravel version. Commonly required extensions include:
The exact list can vary by Laravel release. Do not assume that every extension listed here is required by every version.
If an extension is missing, enable or install it according to your PHP distribution's instructions.
Composer manages PHP packages and their dependencies. Laravel uses Composer to install framework files and other required libraries.
Windows installation:
Verify Composer:
composer --version
The command should display the installed Composer version.
Check the PHP executable:
where php
On Windows, this command shows the PHP executable paths that are available through PATH.
Make sure Composer uses a compatible PHP installation. If multiple PHP versions are installed, a version mismatch can prevent Laravel installation.
Once PHP and Composer are ready, open a terminal in the directory where you want to create your project.
Using Composer:
composer create-project laravel/laravel my-laravel-app
This command creates a directory named
my-laravel-app and installs a Laravel
application with its dependencies.
Enter the project directory:
cd my-laravel-app
Open the project in Visual Studio Code:
code .
The code . command works if the Visual
Studio Code command-line tool is available in PATH.
Composer generally installs the latest compatible Laravel release when no version constraint is specified. Follow the requirements for the release you intend to teach or deploy.
After installation, Laravel creates a project with several folders and configuration files.
my-laravel-app/
|
|-- app/
|-- bootstrap/
|-- config/
|-- database/
|-- public/
|-- resources/
|-- routes/
|-- storage/
|-- tests/
|-- vendor/
|
|-- .env
|-- artisan
|-- composer.json
|-- composer.lock
Important folders and files:
app/ — application classes, including models and controllers.bootstrap/ — application bootstrapping files.config/ — application configuration files.database/ — migrations, seeders, and factories.public/ — web entry point and public assets.resources/ — views and frontend source resources.routes/ — route definitions.storage/ — logs, cache, and generated files.vendor/ — Composer-installed dependencies..env — environment-specific settings.artisan — Laravel command-line entry point.
Do not publish your .env file or expose
its database passwords and application secrets.
Move into your project directory and run Laravel's development server.
cd my-laravel-app
php artisan serve
The terminal displays a local URL, commonly:
http://127.0.0.1:8000
Open the URL displayed by your terminal in a web browser. You should see the Laravel welcome page if the installation completed successfully.
Useful Artisan commands:
php artisan --version
php artisan list
php artisan route:list
These commands show the Laravel version, available Artisan commands, and registered application routes.
The Artisan development server is intended for local development, not as a production web server.
Laravel routes are commonly defined in
routes/web.php.
Example:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
return 'Hello from Laravel!';
});
Save the code in routes/web.php, keeping
any existing route definitions you still need.
Visit this URL while the development server is running:
http://127.0.0.1:8000/hello
Expected output:
Hello from Laravel!
The Route::get() method registers a route
that responds to GET requests at the specified path.
You will learn more about routing in Lesson 6.
Problem 1: PHP command not found
Ensure that the PHP installation directory is added to PATH, then open a new terminal.
Problem 2: Composer command not found
Verify the Composer installation and PATH settings. Restart the terminal after installation.
Problem 3: PHP version is incompatible
Check the requirements of the Laravel version you are installing and ensure the CLI PHP version is compatible.
Problem 4: Required extension is missing
Run php -m and enable or install the
missing extension for the PHP executable Composer uses.
Problem 5: Project installation fails
Read the Composer error message. Check PHP compatibility, network connectivity, extension requirements, and filesystem permissions.
Problem 6: Laravel page does not open
Confirm that php artisan serve is running
and open the exact local URL displayed in the terminal.
Practice task: Install Laravel, create
a project named student-app, run the
development server, and create a /hello
route.
1. Which tool manages PHP dependencies for Laravel?
2. Which command starts Laravel's local development server?
3. Which file commonly contains Laravel web routes?