Setting Up Laravel
Let's get you up and running with Laravel. Before anything, make sure you have PHP 8.1 or higher and Composer installed on your machine. These are the only two requirements you need.
php -v
composer --version
Run those commands to verify. If they return version numbers, you're good to go.
Creating Your First Project
There are two ways to create a Laravel project. The first uses Composer directly:
composer create-project laravel/laravel my-app
The second uses the Laravel installer, which is faster after initial setup:
composer global require laravel/installer
laravel new my-app
Either way, you'll end up with a fresh Laravel project ready to go. The installer is convenient because it skips asking you a bunch of questions.
Try it Yourself โUnderstanding the .env File
Your .env file contains all your environment-specific configuration. Database credentials, app keys, mail settings โ everything goes here. Laravel reads this file automatically on startup.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:your-generated-key
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=
Never commit this file to version control. Laravel includes a .env.example file that developers can share.
Running Your Application
Starting the development server is dead simple. One command and your app is live:
php artisan serve
By default, it runs at http://localhost:8000. Open your browser and you should see the Laravel welcome page. That's it โ your first Laravel application is running.
The artisan command is Laravel's CLI tool. You'll use it constantly for generating code, running migrations, clearing caches, and much more.