Laravel is the most popular PHP framework for building modern web applications. Before you write routes or models, you need a reliable local environment with PHP 8.2+, Composer, and the Laravel installer or create-project command ready to go.
System Requirements and PHP Setup
Laravel 11 requires PHP 8.2 or higher with extensions such as BCMath, Ctype, cURL, DOM, Fileinfo, JSON, Mbstring, OpenSSL, PCRE, PDO, Tokenizer, and XML.
On Ubuntu you can install PHP and common extensions with apt, while macOS developers often use Laravel Herd or Homebrew for a batteries-included setup.
Step 1: Verify PHP version and extensions
Open a terminal and run php -v to confirm you are on PHP 8.2 or newer. Laravel will refuse to install cleanly on unsupported versions, so fix this before proceeding.
Run php -m and scan the output for required extensions like pdo_mysql, mbstring, and openssl. Missing extensions cause obscure errors during composer install or when serving the app.
php -v
php -m | grep -E 'pdo|mbstring|openssl'
Step 2: Install Composer globally
Composer is Laravel's dependency manager. Download the installer from getcomposer.org or use your package manager so the composer command is available everywhere in your shell.
After installation, run composer –version to verify. Composer will download Laravel and hundreds of packages into vendor/ for every new project.
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Step 3: Choose MySQL, PostgreSQL, or SQLite
Laravel supports multiple databases out of the box. For local tutorials SQLite is fastest because it needs no separate server process.
Create an empty database if you use MySQL or PostgreSQL. You will reference the connection details later in the .env file when configuring DB_CONNECTION and DB_DATABASE.
Step 4: Optional: Node.js for frontend assets
Laravel uses Vite for compiling CSS and JavaScript. Install Node.js 18+ and npm so you can run npm install and npm run dev during development.
You can defer frontend tooling until you need Blade layouts with compiled assets, but having Node ready prevents surprises when Breeze or Jetstream scaffolds login pages.
Creating Your First Laravel Project
The fastest way to start is composer create-project laravel/laravel my-app or the global laravel new my-app command if you installed the Laravel installer.
Artisan is Laravel's CLI and becomes your daily companion for migrations, seeders, queues, and custom commands.
Step 1: Scaffold with Composer
Navigate to your projects directory and run composer create-project laravel/laravel blog-demo. Composer resolves dependencies and generates the full directory structure including app/, routes/, and config/.
When the command finishes, cd into blog-demo and list files. You should see artisan, composer.json, .env.example, and the public/ folder that serves as the web root.
composer create-project laravel/laravel blog-demo
cd blog-demo
Step 2: Generate an application key
Laravel encrypts sessions and cookies using APP_KEY in .env. Copy .env.example to .env if it does not exist, then run php artisan key:generate.
The key:generate command writes a random 32-byte key into .env. Never commit production keys to version control; each environment should have its own unique key.
cp .env.example .env
php artisan key:generate
Step 3: Configure database connection
Open .env and set DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD to match your local database. For SQLite, create database/database.sqlite and set DB_CONNECTION=sqlite.
Run php artisan migrate to confirm connectivity. A successful migration creates the users, cache, and jobs tables that ship with the default Laravel skeleton.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=blog_demo
Step 4: Start the development server
Laravel includes a lightweight development server. Run php artisan serve and visit http://127.0.0.1:8000 in your browser to see the welcome page.
For concurrent workers during API development, consider Laravel Herd, Valet, or Sail with Docker. The built-in server is perfect for tutorials and local testing.
php artisan serve
php artisan migrate
Project Structure and Daily Workflow
Understanding Laravel's conventions saves hours of confusion. Routes live in routes/web.php and routes/api.php, controllers in app/Http/Controllers, and views in resources/views.
Configuration files in config/ read values from .env, keeping secrets out of source code while allowing per-environment overrides.
Step 1: Explore routes and the front controller
All HTTP requests enter through public/index.php, which boots the application container and dispatches to the router. Open routes/web.php to see the default welcome route closure.
Named routes, route groups, and middleware are added here as your app grows. Keeping routes organized by feature or module prevents a single enormous file.
Route::get('/', function () {
return view('welcome');
});
Step 2: Use Artisan for code generation
Run php artisan list to see available commands. Generators like make:controller, make:model, and make:migration create boilerplate following PSR-4 namespaces under app/.
Custom Artisan commands can automate deployments or data imports. The scheduler in routes/console.php runs recurring tasks when triggered by a server cron entry.
php artisan make:controller PostController
php artisan make:model Post -m
Step 3: Environment-specific configuration
Never hard-code API keys or database passwords. Use env('MAIL_HOST') inside config files, then set MAIL_HOST in .env for each environment.
Run php artisan config:cache in production to merge configuration into a single cached file for performance. During local development, config:clear ensures .env changes take effect immediately.
php artisan config:clear
php artisan config:cache
Step 4: Version control best practices
Initialize git in your project root and ensure .env, vendor/, and node_modules/ are listed in .gitignore. Commit composer.lock so teammates install identical dependency versions.
Tag releases and document PHP and Laravel versions in README.md. When upgrading Laravel, follow the official upgrade guide and run php artisan test after each step.
git init
git add .
git commit -m 'Initial Laravel skeleton'
Aadyanex delivers Laravel projects with standardized setup scripts, CI pipelines, and documented environments so your team ships features instead of fighting configuration.
