Starting Laravel

Getting Started with Laravel on XAMPP

🌀 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:

  1. Move the contents of myapp/public into a folder in htdocs (e.g., htdocs/myapp/public).
  2. Set Laravel’s document root to public/ in httpd-vhosts.conf.
  3. Update the .env file:
    APP_URL=http://localhost/myapp
  4. Update the paths in index.php inside public/:
    require __DIR__.'/../vendor/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';

📁 Laravel Folder Structure Overview

myapp/ ├── app/ │ ├── Console/ │ ├── Exceptions/ │ ├── Http/ │ │ ├── Controllers/ │ │ └── Middleware/ ├── bootstrap/ ├── config/ ├── database/ │ ├── migrations/ ├── public/ │ └── index.php ├── resources/ │ ├── views/ │ └── css/js/ ├── routes/ │ ├── web.php <-- For web routes │ └── api.php <-- For API routes ├── storage/ ├── tests/ ├── .env └── artisan

📌 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 .env to configure DB and app settings.
  • Use php artisan route:list to list all routes.

Post a Comment

0 Comments

Me