CST463 · S7 CSE
Setting up a Laravel project
Requirements, installation via Composer, environment configuration and the directory structure.
Source: laravel_setup.docx — course material by Kiran V.K., published here so it is readable without a Google account.
Introduction to Laravel Setup
Setting up a Laravel project is the first step in developing a Laravel application. This section provides a comprehensive guide on how to install and configure a basic Laravel project. Laravel is a popular PHP framework known for its elegant syntax and robust features. It simplifies many common tasks in web development, making it a preferred choice for many developers.
Requirements for Laravel Installation
- Before installing Laravel, ensure that your system meets the following requirements:
- PHP 7.3 or higher.
- Composer: A dependency manager for PHP.
- Web Server: Such as Apache or Nginx.
- Database: MySQL, PostgreSQL, or SQLite.
Installing Laravel
- Laravel can be installed in various ways, but the most common method is via Composer.
- Open a terminal or command prompt.
- Run the command:
composer create-project --prefer-dist laravel/laravel yourProjectName - This command downloads Laravel and sets up a new project named 'yourProjectName'.
Configuring the Environment
- After installation, configure the application environment.
- Navigate to the project directory.
- Rename the
.env.examplefile to.env. - Customize the
.envfile with your database and other environment settings. - Generate an application key using
php artisan key:generate.
Directory Structure Overview
- Understanding the directory structure is crucial for Laravel development.
app/: Contains the core code of your application.resources/views/: Where Blade template files are stored.routes/: Contains all of the route definitions.- Other directories include
config/,public/, anddatabase/.
Laravel Project Directory Structure
Root Directory
app/: Contains the core code of your application. Subdirectories include Models and Http (Controllers).bootstrap/: Contains files that bootstrap the framework and configure autoloading. Theapp.phpfile bootstraps the application.config/: Contains all application's configuration files, likedatabase.phpfor database settings.database/: Contains database-related files, including migrations, model factories, and seeds.public/: The entry point for all requests. Contains assets like images, JavaScript, and CSS files.resources/: Contains views, raw assets (LESS, SASS, JavaScript), and localization files. Theviewssubdirectory holds Blade templates.routes/: Contains all route definitions. Includesweb.php,api.php,console.php, andchannels.php.storage/: Used for storing compiled Blade templates, file-based sessions, file caches, and other framework-generated files.tests/: Contains automated tests (unit and feature tests). PHPUnit is configured out of the box.vendor/: Contains Composer dependencies.
Key Files in the Root Directory
.env: The application's environment configuration file for setting environment-specific variables.artisan: The Laravel command line tool used for tasks like migrations and seeding.composer.jsonandcomposer.lock: Used by Composer to manage dependencies.