How to Install Laravel and Create a New Project on Windows

How to Install Laravel and Create a New Project on Windows

 How to Install Laravel and Create a New Project on Windows


If you're trying to run:

laravel new my-app

but see an error like:

'laravel' is not recognized as an internal or external command

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:

  1. Download XAMPP from Apache Friends.
  2. Install it and select PHP and MySQL during installation.
  3. 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.

  1. Download Composer from getcomposer.org.
  2. Run the installer and check the option to add Composer to system PATH.
  3. After installation, verify Composer is installed by opening Command Prompt (cmd) or PowerShell and running:
    composer -V
    If it displays a version number, Composer is installed successfully.

Step 3: Install Laravel Installer

Now, install Laravel globally using Composer:

composer global require laravel/installer

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)

  1. Open Run (Win + R), type sysdm.cpl, and press Enter.
  2. Go to the Advanced tab and click Environment Variables.
  3. Under System Variables, find and edit Path.
  4. Click New and add:
    C:\Users\YourUsername\AppData\Roaming\Composer\vendor\bin
  5. Click OK to save and restart your Command Prompt.

Now check if Laravel is installed correctly:

laravel --version

Step 4: Create a New Laravel Project

Once Laravel is installed, you can create a new project.

Option 1: Using Laravel Installer

laravel new my-app

Option 2: Using Composer

If laravel new doesn’t work, use Composer instead:

composer create-project --prefer-dist laravel/laravel my-app

Step 5: Navigate to Your Project and Start the Server

Move into your Laravel project directory:

cd my-app

Run the Laravel development server:

php artisan serve

This will start the Laravel server. Open your browser and visit:

http://127.0.0.1:8000

Step 6: (Optional) Install Laravel UI for React

If you want to use React with Laravel, install Laravel UI:

composer require laravel/ui

Then scaffold React:

php artisan ui react npm install && npm run dev

Conclusion

That's it! You’ve successfully installed Laravel on Windows and created a new project. Now, you can start building your web application. 

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close