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

n8n public API rate limits: cấu hình và xử lý lỗi 429

Hướng dẫn vận hành giới hạn public API n8n trên self-host: bật theo API key, chọn ngưỡng đọc/ghi, theo dõi header và xử lý 429 mà

MCP Claude Code: kết nối công cụ và kiểm soát quyền

Hướng dẫn kết nối MCP trong Claude Code qua HTTP hoặc stdio, chọn cấu hình cá nhân hay chia sẻ với team, kiểm tra trạng thái

Claude Skills + Projects: xây quy trình AI tự vận hành

Hướng dẫn ghép prompt, Projects, Skills và scheduled tasks thành workflow Claude tự vận hành cho team dev và agency nhỏ.

Git status và git diff: cách xem file đã thay đổi

Hai lệnh cần chạy trước mọi commit: git status để biết file nào đang untracked, modified hay staged; git diff để xem nội dung thay đổi

Subagent Claude Code: chia việc cho agent phụ an toàn

Hướng dẫn dùng subagent trong Claude Code: tạo file agent trong .claude/agents, siết quyền bằng tools và permissionMode, cô lập bằng worktree, và chọn model để

Skills trong Claude Code: biến quy trình thành lệnh tái dùng

Hướng dẫn dùng skills trong Claude Code: cấu trúc SKILL.md, vị trí lưu cho cá nhân và team, kiểm soát ai được gọi skill, và các

Plan mode Claude Code: bắt AI lập kế hoạch trước khi viết code

Bài giải thích plan mode trong Claude Code: cách bật bằng Shift+Tab hoặc /plan, Claude được làm gì khi chỉ-đọc, checklist đọc plan trước khi duyệt,

Checkpoint trong Claude Code: quay lại khi AI sửa hỏng code

Bài giải thích cơ chế checkpoint của Claude Code, cách dùng /rewind để khôi phục code và hội thoại, những trường hợp checkpoint không cứu được,

Permission mode trong Claude Code: chọn mức quyền an toàn

Bài giải thích 6 permission mode của Claude Code, cách đổi chế độ bằng Shift+Tab và cờ khởi động, cùng nguyên tắc chọn mức quyền an

Sửa code bằng Claude Code: quy trình an toàn cho người mới

Bài hướng dẫn quy trình sửa code bằng Claude Code an toàn cho người mới: cách viết yêu cầu, duyệt quyền, kiểm tra thay đổi, kiểm

CLAUDE.md là gì? Cách ghi quy tắc dự án để Claude Code làm đúng

Bài giải thích CLAUDE.md là gì, file này load từ đâu, nên ghi nội dung nào và cách bảo trì để Claude Code làm đúng quy

7 lệnh Claude Code cần biết: /help, /clear, /compact và cách dùng

Bài hướng dẫn 7 lệnh Claude Code quan trọng nhất cho người mới bắt đầu, kèm ví dụ thực tế và thời điểm nên dùng từng