Laravel for Beginners: Setting up the development environment (Chapter 2)

Nội dung

I. Introduction

Having a properly configured development environment is crucial for building and testing Laravel applications. In this article, we will cover the steps to set up the Laravel development environment on your local machine. The steps to set up the Laravel development environment include installing PHP, a web server, and a database, as well as installing XAMPP, Laravel, and configuring the development environment.

II. Requirements

Before setting up the Laravel development environment, you need to make sure that the following requirements are met:

  • PHP >= 7.1.3
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension
  • A web server such as Apache or Nginx
  • A database such as MySQL, PostgreSQL, or SQLite

In addition to MySQL, PostgreSQL, and SQLite, Laravel also supports other databases such as Microsoft SQL Server, Oracle Database, and MongoDB.

III. Installing XAMPP

What is XAMPP:

XAMPP is a free and open-source software that provides an easy way to install Apache, PHP, and other components required to run Laravel. It includes a package of web server applications such as Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages. XAMPP makes it easy to set up a local web server environment, allowing developers to test their applications and websites on their local machine before deploying them to a production server.

XAMPP Window

Downloading and installing XAMPP:

You can download XAMPP from the official website at https://www.apachefriends.org/index.html. The installation process is straightforward and similar to installing any other software on your machine.

Verifying the installation of XAMPP

To verify the installation of XAMPP, open your web browser and navigate to http://localhost/ or http://127.0.0.1/. If XAMPP is installed correctly, you should see the XAMPP welcome page.

IV. Installing Laravel

Using Composer:

The recommended way to install Laravel is using the Composer dependency manager. You can install Laravel by running the following command in the terminal:

$ composer create-project --prefer-dist laravel/laravel blog

Using Laravel Installer:

Alternatively, you can install Laravel using the Laravel installer tool. This tool helps you quickly create a new Laravel project. To install Laravel using the Laravel installer, run the following command in the terminal:

$ laravel new blog

V. Configuring the development environment

Environment variables: Laravel uses environment variables to store configuration settings, such as the database credentials. You can find the environment variables in the .env file located in the root of your Laravel project.

Database configuration: To configure the database in Laravel, you need to specify the database credentials in the .env file. You can do this by updating the following lines:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Virtual Host Configuration: If you want to run Laravel on a virtual host, you can configure it by adding the following code to your Apache virtual host configuration file:

<VirtualHost *:80>
    ServerName laravel.local
    DocumentRoot "path/to/laravel/public"
    <Directory "path/to/laravel/public">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

VI. Conclusion

Recap of what was covered In this article, we covered the steps to set up the Laravel development environment on your local machine. We discussed the requirements, including PHP, a web server, and a database, and walked through the process of installing XAMPP, Laravel, and configuring the development environment.

Importance of a properly configured development environment Having a properly configured development environment is essential for building and testing Laravel applications. With a properly configured environment, you can focus on developing your application without worrying about technical issues.

Resources for further learning There are many resources available for further learning, including the Laravel official documentation at https://laravel.com/docs and online tutorials and courses.

Anthony Nguyễn

Cây bút chính tại VietnamTutor

Bài viết cùng chuyên mục

Nâng Cấp Laravel 13: Checklist 10 Bước Không Thể Bỏ Qua 2026

Hướng dẫn nâng cấp Laravel 13 chi tiết với checklist 10 bước. Từ kiểm tra PHP 8.3, cập nhật dependencies, đến xử lý lỗi thường gặp

Hardening Laravel Production: Checklist Bảo Mật Toàn Diện 2026

Checklist hardening Laravel production toàn diện. Từ cấu hình server, database, SSL đến security headers, rate limiting và monitoring.

Authentication & Authorization Trong Laravel: Hướng Dẫn A-Z 2026

Hướng dẫn chi tiết cách xây dựng hệ thống Authentication (xác thực) và Authorization (phân quyền) trong Laravel với Breeze, Fortify, Sanctum, Policies và Gates.

Bảo Mật Laravel: 10 Lỗi Phổ Biến & Cách Phòng 2026

Hướng dẫn 10 lỗi bảo mật phổ biến nhất trong Laravel và cách phòng tránh hiệu quả. Từ XSS, SQL injection đến authentication vulnerabilities.

Migration PHP Attributes Laravel 13: Hướng Dẫn Chi Tiết

Cách chuyển đổi từ protected properties sang PHP Attributes trong Laravel 13 với hướng dẫn từng bước và code examples chi tiết.

Laravel 13 Có Gì Mới? Tổng Hợp Tính Năng Mới 2026

Laravel 13 ra mắt ngày 17/3/2026 với PHP 8.3, PHP Attributes, AI SDK và nhiều cải tiến. Khám phá chi tiết các tính năng mới của

Kubernetes for Beginners 2026: Hướng Dẫn Từ A-Z

Kubernetes (K8s) là nền tảng container orchestration phổ biến nhất hiện nay. Bài hướng dẫn này sẽ giúp bạn hiểu Kubernetes là gì, kiến trúc cơ

Docker Compose Best Practices 2026: 10 Tips Quan Trọng

Docker Compose giúp bạn quản lý multi-container applications dễ dàng hơn. Bài viết này tổng hợp 10 best practices quan trọng nhất để sử dụng Docker

Lỗ hổng RCE (CVE-2025-55182) trên React, Next.js?

Cảnh báo khẩn cấp: React2Shell (CVE-2025-55182) gây RCE nghiêm trọng cho React/Next.js. Nắm cơ chế, dấu hiệu & phòng thủ cấp bách để bảo vệ ứng

Dead-Letter Queue: Giải pháp cứu cánh cho tin nhắn lỗi hệ thống

DLQ là chìa khóa quản lý tin nhắn lỗi hiệu quả trong hệ thống phân tán. Đảm bảo tin nhắn không bị mất, tăng độ tin

Lập trình viên: Xây doanh nghiệp một người, kiếm 10.000 USD/tháng

Lập trình viên: Khám phá khung làm việc để xây dựng doanh nghiệp một người, kiếm 10.000 USD/tháng. Biến kỹ năng code thành cỗ máy tiền,