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

Git reset revert restore: chọn lệnh đúng

Bài viết so sánh git reset, git revert và git restore theo mục đích sử dụng: sửa staging area, khôi phục file, undo commit chưa push

Git commit vào nhánh sai: cách chuyển an toàn

Bài viết hướng dẫn xử lý git commit vào nhánh sai theo từng tình huống: commit chưa push, đã push, nhiều commit liên tiếp hoặc branch

TypeScript cho website doanh nghiệp: API, form và lỗi

TypeScript cho website doanh nghiệp đáng dùng khi bạn cần kiểm soát API contract, form schema, CMS payload và cấu hình môi trường. Bài này giúp

React Server Components performance: khi nào nên dùng?

React Server Components performance không phải phép màu. Bài này giúp bạn biết khi nào RSC giảm JavaScript thật, khi nào làm kiến trúc phức tạp

Git commit nhầm file: bỏ file khỏi commit an toàn

Bài viết hướng dẫn xử lý git commit nhầm file theo từng tình huống: chưa commit, đã commit chưa push, đã push lên remote, hoặc lỡ

Git reflog: khôi phục commit đã mất an toàn

Bài viết hướng dẫn dùng git reflog để khôi phục commit đã mất sau reset, rebase, amend hoặc xóa nhánh. Bạn sẽ biết cách đọc reflog,

Git pull bị conflict: cách sửa không mất code

Bài viết hướng dẫn cách xử lý git pull bị conflict theo từng bước: kiểm tra trạng thái, sửa file xung đột, test lại và hoàn

Next.js production performance: chọn SSR, SSG, ISR hay Edge

Bài viết giúp developer và tech lead chọn cách render phù hợp để tối ưu Next.js production performance mà không làm kiến trúc phức tạp quá

Nâng cấp Laravel 13: Checklist 10 bước cần kiểm tra

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 cần làm

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

Authentication và authorization trong Laravel: Cách phân biệt

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 và cách phòng tránh

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.