Setting Up Laravel (Composer & Artisan)
Create a Laravel project and meet artisan — the command-line assistant you’ll use daily.
What you will learn
- Install with Composer
- Run the dev server
- Use artisan commands
Create a project
Laravel uses Composer (PHP’s package manager, like npm for PHP). Create a new app, then start it.
# install Composer first (getcomposer.org), then:
composer create-project laravel/laravel myapp
cd myapp
php artisan serve
# open http://localhost:8000Let us read those four lines: composer create-project laravel/laravel myapp downloads a fresh Laravel app into a new folder called myapp. cd myapp moves into that folder. php artisan serve starts a small built-in web server so you can see your app. The last line is just a comment reminding you which address to open.
Note: Output:
INFO Server running on [http://127.0.0.1:8000].
Leave this terminal running and open http://localhost:8000 in your browser — you will see Laravel’s welcome page. Press Ctrl+C to stop the server.
Artisan — your assistant
php artisan is Laravel’s command-line tool. It generates code, runs migrations, clears caches and more.
php artisan make:controller ProductController
php artisan make:model Product -m # model + migration
php artisan migrate # run database migrations
php artisan route:list # see all routesEach line asks artisan to do one job for you: make:controller creates a new controller file, make:model Product -m creates a model and its migration (the -m flag means "with migration"), migrate builds your tables in the database, and route:list prints every route in your app so you can check your URLs. You type these in the terminal, not in a browser.
Note: Key folders: routes/web.php (routes), app/Http/Controllers (controllers), app/Models (models), resources/views (Blade templates), database/migrations (table definitions).
Q. What is "artisan" in Laravel?
✍️ Practice
- Create a Laravel project and run
php artisan serve. - Use artisan to generate a controller and a model.
🏠 Homework
- Explore the project folders and note what each key folder holds.