What Are We Doing in This Post?
Core PHP is done. Fourteen episodes of solid foundation. Now we install Laravel.
But here is the honest truth — Laravel installation on Windows 11 with XAMPP is not always one command and done. There are real errors that hit real beginners. In this episode we cover the complete installation process AND every error you might face, with exact fixes.
By the end of this episode, Laravel will be running on your machine and you will understand exactly why each step exists.
What You Need Before Starting
Make sure these are ready:
XAMPP installed at C:\xampp with Apache and MySQL working — covered in Episode 02.
PHP 8.2 — comes with XAMPP. Verify by opening Command Prompt and typing:
php -v
You should see PHP 8.2.x. If not, reinstall XAMPP from apachefriends.org.
Composer installed — covered in Episode 14. Verify:
composer --version
You should see Composer version 2.x.x.
Step 1 — Enable the ZIP Extension in PHP
This is the most commonly missed step on Windows. Composer needs PHP's zip extension to download and extract packages. Without it, nothing installs.
Open XAMPP Control Panel. In the Apache row, click Config, then click PHP (php.ini). The file opens in your editor.
Press Ctrl+F and search for:
;extension=zip
Remove the semicolon from the beginning of that line so it becomes:
extension=zip
Save the file with Ctrl+S.
In XAMPP Control Panel, click Stop next to Apache, then click Start again.
Verify the extension is now active — open Command Prompt and run:
php -m | findstr zip
If zip appears in the output, the extension is enabled. Move to Step 2.
If nothing appears, double check that you removed the semicolon from the correct line and that you restarted Apache after saving.
Step 2 — Fix Composer Security Advisory Block
By default, newer versions of Composer block packages that have known security advisories. Laravel 11's packages have some logged advisories — not dangerous for local development, but Composer refuses to install them unless you explicitly allow it.
Run this command once to disable the block globally:
composer config -g policy.advisories.block false
This setting applies to all future Composer operations on your machine. You only need to run it once.
Step 3 — Download Laravel Manually
The composer create-project command and the laravel new command both fail on PHP 8.2 with Windows 11 because the Laravel installer itself requires PHP 8.3. We bypass this by downloading Laravel directly as a ZIP file.
Open your browser and go to this URL:
https://github.com/laravel/laravel/archive/refs/tags/v11.0.0.zip
A ZIP file will download — around 35 KB.
Open File Explorer. Go to C:\xampp\htdocs. Extract the ZIP file here. You will get a folder called laravel-11.0.0. Rename it to myapp.
Your Laravel project folder is now at:
C:\xampp\htdocs\myapp
Step 4 — Update composer.json
The default composer.json that comes with the Laravel ZIP has strict version requirements that will conflict with Composer's package resolver. Replace the entire contents of C:\xampp\htdocs\myapp\composer.json with this:
{ "name": "laravel/laravel", "type": "project", "require": { "php": "^8.2", "laravel/framework": "^11.0" }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true, "allow-plugins": { "pestphp/pest-plugin": true, "php-http/discovery": true } }, "extra": { "laravel": { "dont-discover": [] } }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "minimum-stability": "stable", "prefer-stable": true }
Save the file.
Step 5 — Install Laravel Dependencies
Open PowerShell or Command Prompt. Navigate to your project folder:
cd C:\xampp\htdocs\myapp
Run:
composer install --ignore-platform-reqs
Composer will now download all Laravel dependencies — around 70 packages. This takes two to five minutes depending on your internet speed.
When it finishes you will see:
Generating optimized autoload files
That means all packages installed successfully.
Step 6 — Create the .env File and Generate App Key
Laravel needs a .env file for environment configuration. Run these commands one by one — in PowerShell use separate commands, not &&:
copy .env.example .env
php artisan key:generate
You will see:
Application key set successfully.
Step 7 — Configure the Database
Open C:\xampp\htdocs\myapp\.env in VS Code.
You will see a default SQLite configuration. We are using MySQL instead. Find the database section and replace it with this:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_myapp DB_USERNAME=root DB_PASSWORD= DB_COLLATION=utf8mb4_unicode_ci
The DB_COLLATION line is critical on XAMPP. Without it you will get this error:
SQLSTATE[HY000]: General error: 1273 Unknown collation: 'utf8mb4_0900_ai_ci'
This happens because XAMPP's MySQL is an older version that does not support the newer utf8mb4_0900_ai_ci collation that Laravel 11 uses by default. Setting it to utf8mb4_unicode_ci fixes it permanently.
Save the .env file.
Step 8 — Create the Database in phpMyAdmin
Make sure MySQL is running in XAMPP Control Panel. Since you changed Apache's port to 8080 in Episode 02, open phpMyAdmin at:
http://localhost:8080/phpmyadmin
In the left sidebar click New. In the database name field type:
laravel_myapp
Leave the collation as default and click Create.
We create a separate database for Laravel — keeping it separate from the phplearning database we used for Core PHP practice. Mixing them causes migration conflicts.
Step 9 — Run Migrations
Laravel comes with default migrations that create the users, cache, and jobs tables. Run them:
php artisan migrate
You should see:
INFO Preparing database.
Creating migration table .... DONE
INFO Running migrations.
0001_01_01_000000_create_users_table .... DONE
0001_01_01_000001_create_cache_table .... DONE
0001_01_01_000002_create_jobs_table .... DONE
All three migrations done means your database is connected and working perfectly.
Step 10 — Start the Laravel Server
php artisan serve
You will see:
INFO Server running on [http://127.0.0.1:8000].
Open your browser and go to:
http://127.0.0.1:8000
You will see the Laravel welcome page — dark background, Laravel logo, links to documentation and ecosystem tools.
Laravel is running.
Every Error You Might Face — And The Fix
Let us document every error that can appear during this process and exactly how to fix each one.
Error 1 — zip extension missing
The zip extension and unzip/7z commands are both missing, skipping.
Cause: PHP's zip extension is disabled in php.ini.
Fix: Open C:\xampp\php\php.ini, find ;extension=zip, remove the semicolon, save, restart Apache.
Error 2 — PHP version requirement
Cannot use laravel/laravel's latest version as it requires php ^8.3
Cause: Laravel 13 requires PHP 8.3. XAMPP currently ships with PHP 8.2.
Fix: Use the manual ZIP download method from Step 3 with Laravel 11, which fully supports PHP 8.2. Use --ignore-platform-reqs flag with Composer.
Error 3 — Security advisory block
found laravel/framework but these were not loaded, because they are affected by security advisories
Cause: Composer's advisory block feature prevents installation of packages with logged security notices.
Fix: Run composer config -g policy.advisories.block false once globally.
Error 4 — Laravel installer parse error
PHP Parse error: syntax error, unexpected token "->" in Command.php on line 681
Cause: The global laravel new installer requires PHP 8.3. Running it on PHP 8.2 causes this parse error.
Fix: Do not use laravel new. Use the manual ZIP download method instead.
Error 5 — Unknown collation
SQLSTATE[HY000]: General error: 1273 Unknown collation: 'utf8mb4_0900_ai_ci'
Cause: XAMPP's MySQL version does not support the utf8mb4_0900_ai_ci collation that Laravel 11 sets by default.
Fix: Add DB_COLLATION=utf8mb4_unicode_ci to your .env file.
Error 6 — SQLite database file does not exist
Database file at path [C:\xampp\htdocs\myapp\database\database.sqlite] does not exist.
Cause: Laravel defaults to SQLite and tries to find a sqlite file that was never created.
Fix: Switch to MySQL in .env by setting DB_CONNECTION=mysql and filling in the other DB values.
Error 7 — Table already exists
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
Cause: You pointed Laravel at a database that already has a users table — like the phplearning database from Core PHP practice.
Fix: Create a separate fresh database called laravel_myapp in phpMyAdmin and update DB_DATABASE in .env.
Error 8 — && not valid in PowerShell
The token '&&' is not a valid statement separator in this version.
Cause: PowerShell does not support && to chain commands like Command Prompt does.
Fix: Run each command on a separate line in PowerShell. Never chain with && in PowerShell.
Understanding the Folder Structure
Now that Laravel is running, let us understand what was created. Open C:\xampp\htdocs\myapp in VS Code.
myapp/
├── app/
│ ├── Http/
│ │ ├── Controllers/
│ │ └── Middleware/
│ ├── Models/
│ └── Providers/
├── bootstrap/
├── config/
├── database/
│ ├── factories/
│ ├── migrations/
│ └── seeders/
├── public/
├── resources/
│ └── views/
├── routes/
│ ├── web.php
│ └── api.php
├── storage/
├── vendor/
├── .env
├── artisan
└── composer.json
app/Http/Controllers/ — Every controller you write goes here. Controllers handle incoming requests and return responses.
app/Models/ — Every Eloquent model goes here. Each model represents one database table.
app/Http/Middleware/ — Middleware are gatekeepers that run before requests reach your controller. Authentication checks, rate limiting — all middleware.
config/ — All configuration files. They read values from .env using the env() helper.
database/migrations/ — Migration files that define your database table structure in PHP code. Run with php artisan migrate.
database/seeders/ — Files that insert test data into your database with one command.
public/ — The only folder exposed to the internet. public/index.php is the single entry point for every request. All your CSS, JS, and image files that the browser downloads go here.
resources/views/ — All Blade template files live here. These are your HTML files with .blade.php extension.
routes/web.php — Every URL your application responds to is defined here. Open it right now and you will see:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () { return view('welcome'); });
This one line is why you saw the Laravel welcome page. A GET request to / returns the welcome view.
.env — Environment configuration. Database credentials, API keys, debug mode. Never commit this file to version control.
vendor/ — All Composer packages. Never edit anything here manually.
artisan — Laravel's command line tool. You will use it constantly.
Your First Change — Proof That Everything Works
Open routes/web.php and replace everything with:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () { return "Laravel is working. The foundation is complete."; });
Route::get('/about', function () { return "This is the about page."; });
Save the file. Go to http://127.0.0.1:8000 — you see your message.
Go to http://127.0.0.1:8000/about — you see the about page.
Two URLs, two responses, zero file naming confusion. You defined the route — Laravel handled everything else.
Quick Reference — Commands You Will Use Every Day
php artisan serve
Starts the development server at http://127.0.0.1:8000
php artisan make:controller UserController
Creates a new controller file
php artisan make:model Product
Creates a new Eloquent model
php artisan make:migration create_products_table
Creates a new migration file
php artisan migrate
Runs all pending migrations
php artisan migrate:fresh
Drops all tables and reruns all migrations from scratch
php artisan route:list
Shows all registered routes in your application
php artisan tinker
Opens an interactive PHP shell with full Laravel access
php artisan cache:clear
Clears the application cache
What Did We Learn in This Post?
Laravel installation on Windows 11 with XAMPP requires enabling the zip extension, disabling Composer's advisory block, and using PHP version compatible installation methods.
The manual ZIP download of Laravel 11 with --ignore-platform-reqs is the most reliable method on PHP 8.2.
The DB_COLLATION=utf8mb4_unicode_ci setting in .env is essential to avoid collation errors with XAMPP's MySQL version.
Always create a separate database for Laravel — never point it at an existing database that has conflicting tables.
In PowerShell, always run commands one at a time — && chaining does not work.
The folder structure has clear separation of concerns — controllers in app/Http/Controllers, models in app/Models, views in resources/views, routes in routes/web.php.
php artisan serve starts the development server. The artisan command line tool is used throughout the entire Laravel development workflow.
What is Coming in Episode 16?
Now that Laravel is installed and running, we start using it properly.
Episode 16 covers routing in depth — route parameters, named routes, route groups, and middleware on routes. Then we build our first custom migration and create a real database table using Laravel's migration system. The actual Laravel development begins here.
See you in the next one.
Next Episode: Routing and Migrations — Defining URLs and Building Your Database With Code
This is Episode 15 of the PHP and Laravel — Zero to Hero series.
No comments:
Post a Comment