Install Laravel Project getting started with Laravel

Install Laravel

Steps to create a Laravel project from start to finish:

Install Laravel:

To install Laravel, you need to have PHP and Composer installed on your machine. If you don’t have them, you can download and install them from their official websites. Once you have PHP and Composer installed, you can open a terminal or command prompt and run the following command to install Laravel globally:

   composer global require laravel/installer

Create a new Laravel project:

After installing Laravel, you can create a new project by running the following command in your terminal or command prompt:

   laravel new myproject

This command will create a new Laravel project in a folder named myproject.

Configure database:

After creating a new Laravel project, you need to configure the database connection in the .env file. Open the .env file and set the following variables according to your database settings:


Run migrations:

Laravel provides an easy way to create database tables and modify them using migrations. To create the required tables, you need to run the following command:

   php artisan migrate

This command will create the required tables in your database.

Create a new controller:

A controller is responsible for handling incoming HTTP requests and returning responses. To create a new controller, you can run the following command:

   php artisan make:controller MyController

This command will create a new controller named MyController in the app/Http/Controllers directory.

Create a new route:

A route maps a URL to a specific controller action. To create a new route, you can open the routes/web.php file and add the following code:

   Route::get('/myroute', 'MyController@myaction');

This code maps the URL /myroute to the myaction method of the MyController controller.

Create a new view:

A view is responsible for displaying the data returned by the controller to the user. To create a new view, you can create a new file in the resources/views directory and add the following code:

           <title>My Page</title>
           <h1>Welcome to my page!</h1>
           <p>{{ $message }}</p>

This code creates a simple HTML page that displays a message passed by the controller.

Modify the controller action:

In the MyController controller, you need to modify the myaction method to return the view with the message. Add the following code to the method:

   public function myaction()
       $message = 'Hello, world!';
       return view('myview', compact('message'));

This code sets the message variable and returns the myview view with the message.

Test the application:

To test the application, you can run the following command in your terminal or command prompt:

   php artisan serve

This command starts a local development server, and you can access the application by visiting http://localhost:8000/myroute in your web browser.

Congratulations, you have created a new Laravel project from start to finish!

Our Recommendation

Avatar of Akhand Pratap Singh

Akhand Pratap Singh

Greetings and a warm welcome to my website! I am Akhand Pratap Singh, a dedicated professional web developer and passionate blogger.

Related Post


Subscribe for latest updates

We don't spam.