The article is intended to explain how to Create Laravel PHP first project. Laravel is a famous PHP MVC framework for web development. MVC is the architectural design pattern where we have three main components. Model deals with everything related to databases, Controllers manages the business logic and views displays the data to users. Development in this way is scalable, reusable and robust. Laravel has a lot of others features like eloquent, migrations, middleware’s, etc which makes it a must to learn framework for web development. In todays article, we will be looking at how to setup environment and create our first Laravel project.
Install Composer to setup Laravel first Project
Composer is a package manager or you can say dependency manager for your project. It will allow you to install dependencies and manage them. We will use composer to create our first Laravel Project.
Visit here to install composer on your computer.
Install XAMPP local host
Now it’s time to download a localhost server on our system. I will be demonstrating the tutorial using Xampp server but you can download any localhost server you want. Visit here to download the XAMPP server. Once downloaded, install the server on your system. It’s required to create a database to connect with our Laravel application. After installation, openXAMPP control panel and run Apache and MySQL services.
Create first Laravel Project
Now in this section, we will use composer to create Create Laravel PHP first project. First Create a directory anywhere on your system. Then inside the directory, open a PowerShell window and run the composer command. The Composer command to create Laravel projectis shared below.
composer create-project laravel/laravel project_name
Open the project in any code editor when created. I prefer to use visual studio code.
Setup the database in phpmyadmin
Now create a database in phpMyAdmin. I am creating a database with name “example” just to demonstrate this step. Once database is created, go to
.env file in your laravel project and configure it with your database name.
.env file is a file containing environment variables in a key value pair. One line represent one key value pair. It’s accessible within the project using
Run default migrations
Migrations are useful feature of Laravel and it helps specify the database schema. When we run
php artisan migrate command in Laravel, it runs the migration files and create the database tables for us.
Laravel project is created with some default migrations files which runs when you run
php artisan migrate command. Artisan is Laravel’s command line interface which provides many useful command creating ease in development.
That’s it. We are all set now. To view your created project, run
php artisan serve command.
This commands starts a development server for you on port 8000. You can view your project by opening the URL in your browser.
That’s it. We have created our first project in Laravel. I hope this article was informative to you.