How to create larave...

How to create laravel project with composer in terminal.

Published: May 10, 2024

Last Updated: October 07, 2024

Laravel is a popular PHP framework for web application development. Please make sure you have PHP and Composer installed on your system before starting. Here’s how you can create a basic Laravel project:

Step 1: Install Laravel

  1. Open your command-line interface (e.g., Terminal on macOS, Command Prompt on Windows).
  2. Navigate to the directory where you want to create your Laravel project.
  3. Run the following command to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel your-project-name

Replace your-project-name with the name you want for your Laravel project.

Step 2: Configure Your Environment

After the installation is complete, navigate into your project directory:

cd your-project-name

Create a copy of the .env.example file and name it .env:

cp .env.example .env

Generate an application key:

php artisan key:generate

Step 3: Set Up the Database

Open the .env file in a text editor and configure your database connection settings. You need to set the DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD.

Run database migrations to create the necessary database tables:

php artisan migrate

Step 4: Start the Development Server

You can start a development server by running:

php artisan serve

This will start a local development server at http://localhost:8000.

Step 5: Create Your First Route and View

Open the routes/web.php file and define a route that points to a controller or a view. For example, you can create a route that returns a basic welcome view:

Route::get('/', function () {
return view('welcome');
});
 

Create a corresponding Blade view file in the resources/views directory. In this case, you can create a welcome.blade.php file.

Access your Laravel application in your web browser at http://localhost:8000. You should see the "Welcome to Laravel" page.

Congratulations! You’ve just created your first Laravel project. You can continue to build your application by defining routes, creating controllers, and adding functionality as needed. Laravel’s documentation is a valuable resource for learning more about its features and capabilities: Laravel Documentation.

Avatar of shahidul

Author

Hire Me
Md Shahidul Islam
Full-Stack Software Developer
As a full-stack developer, I've been working for over 5 years. I am from Bangladesh and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, WordPress, Vue, Javascript, Tailwind CSS and Bootstrap from the early stage. I believe in Hardworking and Consistency.

Follow me:

Recent Blogs

Maybe you will benefit to know

Why SEO is very important for your website?
Why SEO is very important for your website?
Read More
The Importance of a Portfolio Website
The Importance of a Portfolio Website
Read More
The Benefits and Uses of a Queue Management System to any business
The Benefits and Uses of a Queue Management System to any business
Read More