π Getting Started with Laravel on XAMPP – A Beginner’s Guide
If you're a PHP developer or student using XAMPP and looking to dive into Laravel — the most popular PHP framework — you're in the right place! In this post, we’ll walk you through how to set up Laravel on XAMPP, understand its folder structure, and create simple routes including API and view responses.
π§ Step 1: Requirements
Before you begin, make sure you have the following installed:
- ✅ XAMPP (PHP 7.4 or higher)
- ✅ Composer – Dependency manager for PHP
- ✅ Laravel Installer (Optional)
π₯ Step 2: Installing Laravel in XAMPP htdocs
cd C:\xampp\htdocs
composer create-project laravel/laravel myapp
myapp is your Laravel project folder. You can name it
whatever you want.
Once installed, you’ll find your Laravel project inside:
C:\xampp\htdocs\myapp
π Step 3: Running Laravel with XAMPP
Laravel uses its own development server. Navigate into your project and run:
cd myapp
php artisan serve
You’ll see:
Starting Laravel development server: http://127.0.0.1:8000
OR if you want to run Laravel via XAMPP Apache, follow these steps:
-
Move the contents of
myapp/publicinto a folder inhtdocs(e.g.,htdocs/myapp/public). -
Set Laravel’s document root to
public/inhttpd-vhosts.conf. -
Update the
.envfile:APP_URL=http://localhost/myapp -
Update the paths in
index.phpinsidepublic/:require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
π Laravel Folder Structure Overview
π Route Examples in Laravel
1. ✅ Web Route – Simple Page
Open routes/web.php:
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
2. ✅ Web Route – Custom View
Route::get('/hello', function () {
return view('hello');
});
Create the file resources/views/hello.blade.php:
<!DOCTYPE html>
<html>
<head>
<title>Hello Page</title>
</head>
<body>
<h1>Hello from Laravel!</h1>
</body>
</html>
Visit: http://127.0.0.1:8000/hello
3. π API Route Example
Laravel’s API routes go inside routes/api.php:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/data', function () {
return response()->json([
'name' => 'Champak Roy',
'framework' => 'Laravel',
'version' => app()->version(),
]);
});
Visit: http://127.0.0.1:8000/api/data
4. π‘ API with Controller
Create a controller:
php artisan make:controller Api/DataController
Then open app/Http/Controllers/Api/DataController.php:
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
class DataController extends Controller
{
public function index()
{
return response()->json([
'status' => 'success',
'message' => 'This is coming from a controller!'
]);
}
}
In routes/api.php:
use App\Http\Controllers\Api\DataController;
Route::get('/info', [DataController::class, 'index']);
Visit: http://127.0.0.1:8000/api/info
π Conclusion
- ✅ Installed Laravel in XAMPP
- ✅ Understood the folder layout
- ✅ Created your first web route, view, and API
Laravel is a vast framework with incredible power. You can now build full-stack apps, REST APIs, admin dashboards, and more.
π§ Bonus Tip
- Use Postman or browser tools to test your APIs.
- Edit
.envto configure DB and app settings. - Use
php artisan route:listto list all routes.
0 Comments
Please comment