How to Install Laravel: Step-by-Step Guide for Beginners
To install
Laravel, first ensure you have PHP and Composer installed. Then run composer create-project laravel/laravel project-name in your terminal to create a new Laravel project.Syntax
The main command to install Laravel is:
composer create-project laravel/laravel project-nameHere:
composeris the PHP package manager.create-projecttells Composer to create a new project.laravel/laravelis the Laravel package.project-nameis the folder name for your new Laravel app.
bash
composer create-project laravel/laravel project-name
Example
This example shows how to install Laravel in a folder named myapp. It downloads Laravel and all dependencies.
bash
composer create-project laravel/laravel myapp
Output
Installing laravel/laravel (v10.x.x): Downloading...
Created project in myapp
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> @php artisan key:generate
Application key set successfully.
Common Pitfalls
Common mistakes when installing Laravel include:
- Not having
PHPorComposerinstalled or in your system PATH. - Using an outdated PHP version (Laravel 10 requires PHP 8.1 or higher).
- Running the command without internet connection.
- Trying to install inside a folder that already exists with files.
Always check your PHP version with php -v and Composer with composer -V before installing.
Quick Reference
Summary tips for installing Laravel:
- Install
PHP 8.1+andComposerfirst. - Run
composer create-project laravel/laravel your-folder. - Navigate to your project folder and run
php artisan serveto start the server. - Use
php artisan key:generateif the app key is missing.
Key Takeaways
Ensure PHP 8.1 or higher and Composer are installed before starting.
Use the command 'composer create-project laravel/laravel project-name' to install Laravel.
Check your PHP and Composer versions to avoid installation errors.
Run 'php artisan serve' inside your project folder to start the development server.
Avoid installing Laravel inside folders with existing files to prevent conflicts.