If you are a beginner and want to learn Laravel on Windows, you can use XAMPP to set up your local development environment.
In this tutorial, you will learn how to install Laravel on Windows using XAMPP, configure PHP and Composer, create a Laravel project, connect MySQL, and run your first Laravel application.
What Is Laravel?
Laravel is an open-source PHP framework designed to make web application development easier, faster, and more organized.
It follows the Model-View-Controller (MVC) architecture and provides built-in tools for handling common development tasks.
Some important Laravel features include:
- MVC architecture.
- Routing and controllers.
- Blade templating engine.
- Authentication and authorization.
- Database migrations.
- Eloquent ORM.
- REST API development.
- Form validation.
- Middleware.
- Security features.
Laravel is commonly used to develop business websites, eCommerce platforms, CRM systems, admin dashboards, booking applications, and SaaS platforms.
What Is XAMPP?
XAMPP is a free local development environment that provides the services needed to run PHP applications on your computer.
It includes:
- Apache – Web server.
- MariaDB – Database server.
- PHP – Server-side programming language.
- phpMyAdmin – Database management interface.
XAMPP allows developers to create and test PHP applications locally without purchasing hosting or deploying a website to the internet.
Download XAMPP: https://www.apachefriends.org/
Requirements to Install Laravel on Windows
Before installing Laravel, make sure your computer has the following software:
| Software | Purpose |
|---|---|
| Windows 10 or 11 | Operating system |
| XAMPP | PHP and database environment |
| PHP 8.3 or higher | Required for Laravel 13 |
| Composer | PHP dependency manager |
| Visual Studio Code | Code editor |
| Node.js and npm | Front-end asset management |
Important: This tutorial uses Laravel 13. Laravel 13 requires PHP 8.3 or higher. Check your XAMPP PHP version before creating the project. If your XAMPP installation has an older PHP version, install a compatible XAMPP release or configure a separate supported PHP version for Composer.
Step 1: Download and Install XAMPP
First, download XAMPP for Windows.
- Visit https://www.apachefriends.org/download.html.
- Download a XAMPP version with PHP 8.3 or higher.
- Run the downloaded installer.
- Select Apache, MySQL/MariaDB, PHP, and phpMyAdmin.
- Install XAMPP in the following directory:
C:\xampp
6. Complete the installation.
After installation, open the XAMPP Control Panel.
Start the following services:
- Apache
- MySQL
If both services start successfully, your local PHP and database environment is ready.
To verify XAMPP, open your browser and visit:
http://localhost/
You should see the XAMPP dashboard.
Step 2: Check the PHP Version
Laravel requires a supported PHP version to run properly.
Open Command Prompt or PowerShell and execute:
php -v
You should see the PHP version installed on your system.
For Laravel 13, the PHP version must be 8.3 or higher.
If you get the following error:
'php' is not recognized as an internal or external command
You need to add the XAMPP PHP directory to your Windows PATH environment variable.
Add XAMPP PHP to Windows PATH
- Search for Environment Variables in Windows.
- Open Edit the system environment variables.
- Click Environment Variables.
- Under System variables, select
Path. - Click Edit.
- Click New and add:
C:\xampp\php
- Save the changes.
- Close and reopen Command Prompt.
Now execute:
php -v
You should see the PHP version from your XAMPP installation.
Important: If you have multiple PHP installations, Windows may use a different PHP executable. Run this command to check:
where php
Make sure the XAMPP PHP executable is the one being used when you run Composer.
Step 3: Configure PHP Extensions
Laravel and its dependencies require certain PHP extensions.
Open the following file:
C:\xampp\php\php.ini
Search for the following extensions:
extension=curl extension=fileinfo extension=mbstring extension=openssl extension=pdo_mysql extension=zip extension=xml extension=intl
If any required extension is commented out with a semicolon, remove the semicolon.
For example:
;extension=mbstring
Change it to:
extension=mbstring
Save the file.
Restart Apache from the XAMPP Control Panel so that Apache loads the updated PHP configuration.
To check whether an extension is enabled in your command-line PHP configuration, execute:
php -m
Check that the required extensions are listed.
Note: Command-line PHP and Apache PHP can use different php.ini files if multiple PHP installations are present. Check the active CLI configuration using:
php --ini
Step 4: Install Composer on Windows
Composer is a dependency manager for PHP. Laravel uses Composer to download and manage the framework and its packages.
To install Composer:
- Visit https://getcomposer.org/download/.
- Download
Composer-Setup.exe. - Run the installer.
- When prompted to select the PHP executable, choose:
C:\xampp\php\php.exe
- Complete the installation.
- Close and reopen Command Prompt.
Verify the installation:
composer -V
You should see the installed Composer version.
If Composer reports a PHP version different from your XAMPP version, check the PHP executable selected during Composer installation.
Step 5: Create a New Laravel Project
Now that PHP and Composer are installed, you can create your first Laravel project.
Open Command Prompt or PowerShell.
Navigate to the folder where you want to store your Laravel projects.
For example:
cd C:\xampp\htdocs
Execute the following Composer command:
composer create-project laravel/laravel my-laravel-app
This command will:
- Download the Laravel application.
- Install the required Composer packages.
- Create the Laravel project directory.
- Generate the application structure.
- Prepare the application environment.
Wait until Composer finishes installing all dependencies.
Your Laravel project will be created inside:
C:\xampp\htdocs\my-laravel-app
You can also create a project in another directory outside htdocs if you plan to run it using Laravel's built-in development server.
Step 6: Open the Laravel Project in Visual Studio Code
After creating your Laravel application, open it in Visual Studio Code.
You can execute:
cd my-laravel-app code .
If the code command is unavailable, open Visual Studio Code manually and select:
File → Open Folder → my-laravel-app
You should see the following Laravel project structure:
my-laravel-app/ │ ├── app/ ├── bootstrap/ ├── config/ ├── database/ ├── public/ ├── resources/ ├── routes/ ├── storage/ ├── tests/ ├── vendor/ │ ├── .env ├── artisan ├── composer.json ├── package.json └── vite.config.js
Some important directories:
app/– Application logic, models, and other PHP classes.bootstrap/– Framework bootstrapping files.config/– Application configuration files.database/– Migrations, seeders, and factories.public/– Public entry point and assets.resources/– Blade templates, CSS, and JavaScript source files.routes/– Application route definitions.storage/– Logs, cache, and uploaded or generated files.vendor/– Composer dependencies.
Step 7: Generate the Laravel Application Key
Laravel uses an application encryption key to protect encrypted data and application sessions.
Open the terminal inside your Laravel project directory and execute:
php artisan key:generate
Laravel will automatically update the APP_KEY value in your .env file.
You should see a success message confirming that the application key was generated.
Step 8: Create a MySQL Database Using phpMyAdmin
Now let's connect Laravel to the XAMPP database server.
First, open your browser and visit:
http://localhost/phpmyadmin
Follow these steps:
- Open phpMyAdmin.
- Click the New option.
- Enter the database name:
laravel_db
- Select a suitable collation, such as
utf8mb4_unicode_ci. - Click Create.
Your database is now ready.
Step 9: Configure Laravel Database Connection
Open the .env file in your Laravel project.
Find the database configuration and update it as follows:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_db DB_USERNAME=root DB_PASSWORD=
These are common default XAMPP local database settings. If you have configured a database password or changed the MySQL/MariaDB port, update the values accordingly.
Save the .env file.
Step 10: Run Laravel Database Migrations
Laravel uses migrations to create and modify database tables.
Open the terminal inside your Laravel project directory and execute:
php artisan migrate
Laravel will create the default database tables required by the application.
If the migration completes successfully, your Laravel application is connected to the database.
You can verify the created tables by opening phpMyAdmin and selecting laravel_db.
Step 11: Run the Laravel Application
You are now ready to run your first Laravel application.
Open Command Prompt inside the project directory:
php artisan serve
You should see output similar to:
INFO Server running on [http://127.0.0.1:8000].
Open your browser and visit:
http://127.0.0.1:8000
You should see the Laravel welcome page.
<em>Congratulations! Your Laravel application is running successfully on Windows.</em>
Step 12: Run Front-End Assets Using Node.js and npm
Modern Laravel projects use Vite to manage and compile front-end assets.
If your project includes a package.json file, install Node.js from:
After installation, verify Node.js and npm:
node -v npm -v
Navigate to your Laravel project directory and execute:
npm install
To compile the front-end assets for development, run:
npm run dev
Keep this terminal running while developing.
To generate production-ready assets, execute:
npm run build
Step 13: Create Your First Laravel Route
Let's create a simple route to understand how Laravel works.
Open:
routes/web.php
Add the following code:
use Illuminate\Support\Facades\Route;
Route::get('/welcome', function () {
return 'Welcome to Laravel Development!';
});Save the file and visit:
http://127.0.0.1:8000/welcome
You should see:
Welcome to Laravel Development!
This is your first Laravel route.
Step 14: Run Laravel Using Apache in XAMPP (Optional)
You can also configure Apache to serve your Laravel project.
However, Laravel's built-in development server using php artisan serve is usually easier for beginners.
If you want to use Apache, configure a virtual host so that its document root points to the Laravel project's public directory.
For example, add the following configuration to your Apache virtual hosts file:
<VirtualHost *:80>
ServerName laravel.local
DocumentRoot "C:/xampp/htdocs/my-laravel-app/public"
<Directory "C:/xampp/htdocs/my-laravel-app/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>Also make sure Apache's virtual hosts configuration is enabled and that mod_rewrite is active.
Add this entry to the Windows hosts file, usually located at:
C:\Windows\System32\drivers\etc\hosts
Add:
127.0.0.1 laravel.local
Restart Apache and visit:
http://laravel.local
Security note: Apache's document root must point to the Laravel public directory, not the project root. Never expose .env, vendor, storage, or other internal application directories through the web server.
Common Laravel Installation Errors and Solutions
1. PHP Version Error
You may encounter an error such as:
Your Composer dependencies require a PHP version >= 8.3.0. You are running 8.2.x.
Solution:
- Check the PHP version using
php -v. - Run
where phpto identify the executable being used. - Install a compatible PHP version.
- Make sure Composer uses the correct PHP executable.
- Restart your terminal and try again.
2. Composer Is Not Recognized
Error:
'composer' is not recognized as an internal or external command.
Solution:
- Install Composer using the official Windows installer.
- Check whether Composer was added to the Windows PATH.
- Restart Command Prompt or PowerShell.
- Execute
composer -Vagain.
3. PHP Extension Missing
You may see an error indicating that a required PHP extension is missing.
Solution:
- Open
C:\xampp\php\php.ini. - Enable the required extension.
- Save the file.
- Restart Apache if needed.
- Check CLI extensions using
php -m. - Run the Composer installation command again.
4. MySQL Connection Error
You may encounter:
SQLSTATE[HY000] [2002] Connection refused
Solution:
- Start MySQL from the XAMPP Control Panel.
- Check the database name.
- Verify the database username and password.
- Check whether MySQL/MariaDB is running on port 3306.
- Clear cached Laravel configuration:
php artisan config:clear
5. Apache Port 80 Already in Use
Apache may fail to start because another application is using port 80.
Solution:
- Check which application is using port 80.
- Stop the conflicting service or configure Apache to use another port.
- Restart Apache.
6. Laravel Application Key Missing
If you see an application key error, execute:
php artisan key:generate
Useful Laravel Artisan Commands for Beginners
Here are some commonly used Laravel commands:
| Command | Purpose |
|---|---|
| php artisan serve | Start the local development server |
| php artisan key:generate | Generate application encryption key |
| php artisan migrate | Run database migrations |
| php artisan make:model User | Create a model |
| php artisan make:controller UserController | Create a controller |
| php artisan make:migration create_posts_table | Create a migration |
| php artisan route:list | Display application routes |
| php artisan config:clear | Clear configuration cache |
| php artisan cache:clear | Clear application cache |
| php artisan optimize:clear | Clear Laravel optimization caches |
Frequently Asked Questions
1. Can I install Laravel using XAMPP?
Yes. You can use XAMPP to provide PHP and MySQL/MariaDB for Laravel development. You also need Composer to install Laravel and its dependencies.
2. Which PHP version is required for Laravel 13?
Laravel 13 requires PHP 8.3 or higher. Always check the official Laravel documentation for the requirements of the version you intend to install.
3. Do I need Composer to install Laravel?
Yes. Composer is used to download Laravel and manage its PHP dependencies.
4. Where should I install Laravel in XAMPP?
You can create your Laravel project inside C:\xampp\htdocs. Alternatively, you can store it outside the XAMPP directory and run it using Laravel's built-in development server.
5. Can I run Laravel without starting Apache?
Yes. You can run Laravel using:
php artisan serve
This starts Laravel's built-in development server. You can still use the XAMPP MySQL/MariaDB service for your database.
6. Can I use phpMyAdmin with Laravel?
Yes. You can use phpMyAdmin to create databases, view tables, manage records, and inspect your Laravel database.
7. Can I use Visual Studio Code for Laravel development?
Yes. Visual Studio Code is a popular code editor for Laravel development. You can use extensions for PHP, Blade templates, Laravel Artisan commands, and code formatting.
8. Is XAMPP enough for Laravel development?
XAMPP provides the local PHP and database environment, but you also need Composer. Modern Laravel projects may additionally require Node.js and npm to compile front-end assets.
9. Can I install Laravel 12 using XAMPP?
Yes. You can install Laravel 12 using Composer if your PHP version meets the requirements of that Laravel release. Check the official documentation before selecting a framework version.
10. Can I host a Laravel project online after developing it using XAMPP?
Yes. You can deploy your Laravel application to a compatible hosting server. Make sure the server meets Laravel's PHP and extension requirements, and configure the web server to serve the application's public directory.
Conclusion
Installing Laravel on Windows using XAMPP is a practical way to begin PHP framework development.
By installing XAMPP, configuring PHP, setting up Composer, creating a Laravel project, and connecting a database, you can build and test Laravel applications on your local computer.
Once your environment is ready, start learning Laravel routes, controllers, models, Blade templates, database migrations, and CRUD operations.
Practice by building small projects and gradually move towards complete web applications.
Learn More About Web Development
At 2K Web Solutions, we share practical tutorials and resources covering PHP, Laravel, WordPress, MySQL, web development, and SEO.
Explore more tutorials and improve your web development skills.
Need a custom Laravel application? Explore our [Website Development Services](https://2kwebsolutions.com/website-development-services).