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

Quy trình vibe coding 7 bước: từ ý tưởng đến prototype

Quy trình vibe coding hiệu quả bắt đầu từ giả thuyết kinh doanh, không phải prompt dài. Bài viết hướng dẫn 7 bước từ brief, dữ

Vibe coding cho doanh nghiệp: việc nào nên làm bằng AI?

Vibe coding cho doanh nghiệp hữu ích khi cần thử prototype, dashboard hoặc automation nhỏ. Bài viết giúp bạn phân loại use case theo mức rủi

AI viết code nhanh hơn review: kiểm soát thế nào?

Khi AI viết code nhanh hơn khả năng review của team, doanh nghiệp cần đổi cách kiểm soát chất lượng. Bài viết đưa ra framework thực

Git detached HEAD là gì? Cách thoát an toàn

Bài viết này giải thích detached HEAD trong Git, cách nhận biết trạng thái này và các bước thoát ra an toàn mà không mất code.

Rủi ro vibe coding: 9 lỗi khiến prototype khó vận hành

Bài viết này chỉ ra 9 rủi ro phổ biến khi vibe coding và cách kiểm soát để prototype không biến thành gánh nặng vận hành.

Vibe coding là gì? Cách thử ý tưởng phần mềm bằng AI

Vibe coding giúp chủ doanh nghiệp biến ý tưởng phần mềm thành prototype nhanh hơn bằng AI. Bài viết này chỉ ra khi nào nên thử,

GitHub Actions CI/CD: quy trình deploy website an toàn

Hướng dẫn xây pipeline GitHub Actions CI/CD cho website: build, test, cache dependency, đóng artifact, deploy staging/production và quản lý secret an toàn.

.gitignore không hoạt động: nguyên nhân và cách sửa

Bài viết giúp bạn kiểm tra vì sao .gitignore không hoạt động, sửa lỗi file đã tracked và dùng git check-ignore để debug pattern.

Git push bị rejected: cách sửa non-fast-forward

Bài viết giải thích vì sao git push bị rejected, cách đọc lỗi non-fast-forward và quy trình xử lý an toàn trước khi push lại.

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