How to Install Laravel and Create a New Project on Windows
but see an error like:
Then Laravel is not installed globally on your system. Follow this step-by-step guide to install Laravel and start a new project on Windows.
Step 1: Install XAMPP (Optional but Recommended)
Laravel requires PHP and a database (like MySQL). If you don’t have PHP and MySQL installed, install XAMPP:
- Download XAMPP from Apache Friends.
- Install it and select PHP and MySQL during installation.
- Start Apache and MySQL from the XAMPP Control Panel.
If you already have PHP installed, skip this step.
Step 2: Install Composer
Laravel requires Composer, a PHP dependency manager.
- Download Composer from getcomposer.org.
- Run the installer and check the option to add Composer to system PATH.
- After installation, verify Composer is installed by opening Command Prompt (cmd) or PowerShell and running:
If it displays a version number, Composer is installed successfully.
Step 3: Install Laravel Installer
Now, install Laravel globally using Composer:
Next, you must add Composer’s global bin directory to your system's PATH so you can use laravel
commands everywhere.
Add Composer to PATH (If Laravel Command Not Found)
- Open Run (
Win + R
), type sysdm.cpl, and press Enter. - Go to the Advanced tab and click Environment Variables.
- Under System Variables, find and edit Path.
- Click New and add:
- Click OK to save and restart your Command Prompt.
Now check if Laravel is installed correctly:
Step 4: Create a New Laravel Project
Once Laravel is installed, you can create a new project.
Option 1: Using Laravel Installer
Option 2: Using Composer
If laravel new
doesn’t work, use Composer instead:
Step 5: Navigate to Your Project and Start the Server
Move into your Laravel project directory:
Run the Laravel development server:
This will start the Laravel server. Open your browser and visit:
Step 6: (Optional) Install Laravel UI for React
If you want to use React with Laravel, install Laravel UI:
Then scaffold React:
Conclusion
That's it! You’ve successfully installed Laravel on Windows and created a new project. Now, you can start building your web application.