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.
Before you begin, make sure you have the following installed:
htdocscd 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
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:
myapp/public into a folder in
htdocs (e.g., htdocs/myapp/public).
public/ in
httpd-vhosts.conf.
.env file:
APP_URL=http://localhost/myapp
index.php inside public/:
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
Open routes/web.php:
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
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
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
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
Laravel is a vast framework with incredible power. You can now build full-stack apps, REST APIs, admin dashboards, and more.
.env to configure DB and app settings.php artisan route:list to list all routes.