Create Laravel 11 project from scratch

  • avatar
  • 5.1K Views
  • 2 Likes
  • 5 mins read

Laravel is a PHP web application framework that's open-source and designed for building web applications following the Model-View-Controller (MVC) architectural pattern. It was created back in 2011 and has become one of the most widely used PHP frameworks for web development.

Laravel offers developers numerous powerful features and tools. These include a straightforward and expressive syntax, built-in database migration and schema management, automated testing capabilities, and a robust ecosystem of third-party packages. Among its key features are its powerful routing engine, which allows developers to easily define application routes, and its comprehensive ORM (Object-Relational Mapping) system, which simplifies working with databases and models.

Additionally, Laravel includes a templating engine called Blade, which simplifies the creation of dynamic, reusable views for applications, along with a built-in authentication system for managing user authentication and authorization.

Prerequisites

Laravel uses Composer to manage its dependencies. Explore our step-by-step guide for installing Composer 2 on your computer.

Installation

Assuming Composer is already installed on your system, you can initiate a new Laravel project directly through Composer. Executing this command will generate a fresh project within a directory named laravel11_project at the current location and automatically install required dependencies:

composer create-project laravel/laravel:^11.0 laravel11_project

Configuring Laravel

Laravel needs almost no additional configuration out of the box. You're ready to begin development right away! However, it's advisable to review the config/app.php file and its accompanying documentation. This file includes various options which you may want to customize according to your application's requirements.

Environment variables

Environment variables serve as repositories for sensitive data such as passwords, credentials, and other confidential information that should not be hard-coded directly into the source code. They are essential for configuring variables or details that may vary between different environments. Laravel offers an illustrative example of how the initial environment file should be structured in the .env document. This file must be adjusted according to your specific requirements and configuration settings.

Databases and Migrations

Upon creating your Laravel application, you may want to store data in a database. By default, the .env configuration file of your application specifies that Laravel will interact with a SQLite database. Laravel automatically generates a database/database.sqlite file and executes migrations to establish the required database tables.

If you opt to utilize a different database driver, such as MySQL or PostgreSQL, you can modify your .env configuration file accordingly. For instance, to switch to MySQL, update the DB_* variables in your .env configuration file and run your application's database migrations:

php artisan migrate

Using Laravel

After configuring the application, you can launch Laravel's local development server. To begin, navigate to the project directory and use the following artisan command to initiate the server:

php artisan serve

While the server is running, the terminal will be blocked and will provide the URL needed to access the application from any browser installed on your system.

Usually, the URL will appear similar to http://127.0.0.1:8000.

Laravel Artisan serve

To unlock the terminal and stop the execution use the Ctrl+C combination on our keyboard.

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.