Skip to content
youhoc
  • Pages
    • Home
    • Modern App Guidelines
    • Linux
      • Day 1: Linux Distributions & Navigation
      • Day 2: User Management
      • Day 3: File Permission & Ownership
      • Day 4: Package Management
      • Day 5: Services Management
    • Javascript
      • JS The Weird Part
        • Execution Context
        • Types & Operators
        • Objects & Functions
        • Error Handling & Strict Mode
        • Typescript, ES6, Tra
      • Modern JS
        • JS in the Browser
        • Data Storage JSON
        • Modern JS
        • Advanced Objects & Methods
        • Webpack & Babel
        • Async
      • jQuery
        • In-depth Analysis of jQuery
      • React-ready JS
        • Arrow Function
        • Template Literals
        • Logical AND, OR, Ternary, Nullish Operators
        • Destructuring & Rest Operator
        • Array Method
        • Immutability and Spread Operator
        • Promises, Async/Await, Callback
    • PHP
      • gruntJS
      • icon picker
        composer
      • MySQL
    • Docker
      • Container Basics
      • Container Networking
      • Container Image
      • Container Volume & Persistent Data
      • Dockerfile
      • Docker Compose
      • Docker Registry
    • Node.js
      • 1. Installing & Exploring
      • 2. Core Modules
      • 3. Get User Input
      • File System & Input Arguments
      • 5. Express Web Server
      • 6. Deploy to Heroku & Github
      • Authentication
      • 7. Databases
      • 8. Rest API
    • ReactJS
      • React from Andrew
        • Summary from Next
        • 1. Basics
        • 2. React Components
        • 3. Webpack
        • 4. Styling with SCSS
        • 5. React Router
        • 6. React Hook
      • Modern React From The Beginning
        • Intro to JSX
        • Vite Build Tools
        • Basic Component Creation
        • Component State
        • Props & Component Composition
        • useState with Inputs & Form Submission
        • useEffect, useRef & Local Storage
        • Async / Await and Http Request in React
        • React Router: Declarative Mode
        • ContextAPI
        • React Router: Framework Mode
          • File-routing & HTML Layouts
          • Server-side Data Query
          • Links & Navigation
          • Loaders
    • Typescript
      • Type User vs UserProp
    • Payload CMS

composer

Package Management for PHP (giống npm của Node.js)
Cài đặt composer
Đảm bảo version PHP tối thiếu trên máy là 7
Đang đứng ở đâu thì sẽ download setup file ở đó.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Cài đặt composer ở thư mục đang đứng
php composer-setup.php
Để chạy composer global thì copy composer.phar vào thư mục /usr/local/bin/composer
sudo mv composer.phar /usr/local/bin/composer
Di chuyển đến thư mục project, chạy init để tạo JSON config file
composer init
- làm theo hướng dẫn để tạo composer.json config file
Thử cài Google Analytics API và carbon (package quản lý Date & Time)
Cách 1: dùng câu lệnh composer require
composer require nesbot/carbon
Lưu ý: composer.lock để khoá, ghi chú version mà phiên bản đang sử dụng
Lưu ý: Nhớ git ignore vendor khi commit project files

Cách 2: thêm package và version trong file cấu hình
"require": {
"google/apiclient": "^2.0",
"nesbot/carbon": "^2.46",
"swiftmailer/swiftmailer": "^6.2.7"
}
Sau đó chạy composer install để tự install những package chưa có trong vendor
composer install
Lưu ý: khi cài bằng cách 2, thì có thể composer.lock không được cập nhật version hiện hành của những vendor đang xài.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Lưu ý: KHÔNG CHẠY composer update bởi vì sẽ update hết tất package lên version mới nhất. Để update file composer.lock thì xoá đi rồi chạy lại câu lệnh composer install.


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.