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
- Open your command-line interface (e.g., Terminal on macOS, Command Prompt on Windows).
- Navigate to the directory where you want to create your Laravel project.
- 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.