Otu esi etinye & Jiri PHP Composer na Debian 11 Bullseye

Onye na-ede ihe bụ onye njikwa ngwugwu ngwa-ọkwa maka asụsụ mmemme PHP yiri NPM maka Node.Js ma ọ bụ PIP maka Python. Onye na-ede egwú na-enye usoro ọkọlọtọ maka ijikwa ndabere niile nke ngwanrọ PHP na ụlọ akwụkwọ ndị achọrọ site na nbudata ngwugwu PHP niile nke ọrụ gị yana ijikwa ha maka gị. Ọtụtụ usoro PHP ọgbara ọhụrụ na-eji ya dị ka Laravel, Drupal, Magento na Symfony.

N'ime nkuzi na-esonụ, ị ga-amụta otu esi ebudata na wụnye onye na-ede egwú, yana ụfọdụ dị mkpa ka esi arụ ọrụ na onye na-ede egwú na Debian 11 Bullseye.

Prerequisites

  • OS akwadoro: Nnenna 11 Bullseye
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ihe ùgwù or ohere mgbọrọgwụ (su Command).
  • Ngwungwu achọrọ: wget, PHP 5.3 ma ọ bụ karịa

Na-emelite Sistemụ Ọrụ

Melite gi Debian 11 Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo apt update && sudo apt upgrade

Mgbọrọgwụ ma ọ bụ Sudo Access

Site na ndabara, mgbe ị mepụtara akaụntụ gị na mmalite na Debian ma e jiri ya tụnyere nkesa ndị ọzọ, ọ naghị enweta ọkwa sudoers ozugbo. Ị ga-enwerịrị ike ịnweta ya mgbọrọgwụ paswọọdụ iji iwu su ma ọ bụ gaa na nkuzi nkuzi anyị Otu esi etinye onye ọrụ na Sudoers na Debian.


Advertisement


Wụnye nrụpụ

Achọrọ ngwugwu ndị a iji budata onye na-ede egwú na maka ojiji n'ọdịnihu. Rịba ama, ọ bụrụ na ị na-eji ụdị PHP a kapịrị ọnụ, ị ga-achọ ịhazigharị ngwugwu PHP dị n'okpuru ka ọ dabara na ụdị ahụ. Dịka ọmụmaatụ, ịwụnye PHP 8.0 ga-abụ php8.0-mbstring.

sudo apt install curl wget php-common php-cli php-gd php-mysql php-curl php-intl php-mbstring php-bcmath php-imap php-xml php-zip git unzip

Tinye PHP Composer

Ndị otu na-ede egwú emela akwụkwọ edemede PHP gọọmentị iji wụnye na hazie PHP Composer na sistemụ gị. Ị nwere ike ibudata nke a site na ịga na download page ma ọ bụ imepe ọdụ Debian gị wee mee ihe ndị a.

Usoro PHP:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 

Ụzọ WGET:

wget -O composer-setup.php https://getcomposer.org/installer

Ugbu a na setup.php ebudatara, ọ bụ oge ịwụnye onye na-ede egwú. Nke a nwere ike ịbụ n'ụzọ abụọ dị iche iche, otu nke ị nwere ike iwunye onye na-ede egwú n'ụwa nile, ma ọ bụ nke abụọ ọzọ nke bụ ịwụnye kwa ndabere ngwa PHP.

Iji wụnye zuru ụwa ọnụ:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer
chmod +x /usr/local/bin/composer

Iji wụnye kwa ngwa:

cd /example-project/php-application && mkdir -p bin 
php composer-setup.php --install-dir=bin --filename=composer
chmod +x bin/composer

Dị ka ọ dị n'elu, ị ga-achọ ịnyagharịa na ndekọ ọrụ PHP wee mepụta ndekọ ndekọ maka onye na-ede PHP ka arụnyere.

Ozugbo emechara, gosi na etinyere onye na-ede ihe na nke wuru na ụdị ọ bụ.

composer --version
Composer version 2.1.8 2021-09-15 13:55:14

Ugbu a nwalee nwụnye onye dere gị site na iji iwu a:

composer

Ihe atụ mmepụta:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.8 2021-09-15 13:55:14

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                Shows a short information about Composer.
  archive              Creates an archive of this composer package.
  browse               Opens the package's repository URL or homepage in your browser.
  cc                   Clears composer's internal package cache.
  check-platform-reqs  Check that platform requirements are satisfied.
  clear-cache          Clears composer's internal package cache.
  clearcache           Clears composer's internal package cache.
  config               Sets config options.
  create-project       Creates new project from a package into given directory.
  depends              Shows which packages cause the given package to be installed.
  diagnose             Diagnoses the system to identify common errors.
  dump-autoload        Dumps the autoloader.
  dumpautoload         Dumps the autoloader.
  exec                 Executes a vendored binary/script.
  fund                 Discover how to help fund the maintenance of your dependencies.
  global               Allows running commands in the global composer dir ($COMPOSER_HOME).
  help                 Displays help for a command
  home                 Opens the package's repository URL or homepage in your browser.
  i                    Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  info                 Shows information about packages.
  init                 Creates a basic composer.json file in current directory.
  install              Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses             Shows information about licenses of dependencies.
  list                 Lists commands
  outdated             Shows a list of installed packages that have updates available, including their latest version.
  prohibits            Shows which packages prevent the given package from being installed.
  reinstall            Uninstalls and reinstalls the given package names
  remove               Removes a package from the require or require-dev.
  require              Adds required packages to your composer.json and installs them.
  run                  Runs the scripts defined in composer.json.
  run-script           Runs the scripts defined in composer.json.
  search               Searches for packages.
  self-update          Updates composer.phar to the latest version.
  selfupdate           Updates composer.phar to the latest version.
  show                 Shows information about packages.
  status               Shows a list of locally modified packages.
  suggests             Shows package suggestions.
  u                    Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  update               Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  upgrade              Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate             Validates a composer.json and composer.lock.
  why                  Shows which packages cause the given package to be installed.
  why-not              Shows which packages prevent the given package from being installed.

Advertisement


Otu esi arụ ọrụ na PHP Composer

Nkuzi a ga-egosi gị ụfọdụ ọrụ dị mkpa mgbe etinyere onye na-ede PHP iji nwalee ọrụ ya.

Mbụ, mepụta ndekọ ọrụ gị:

mkdir ~/composer-test
cd ~/composer-test

Na-esote, chọta ngwugwu si Onye ngwugwu, ma ọ bụ ọzọ jiri ihe atụ nkuzi wee mee iwu a ka ịmalite faịlụ composer.json ọhụrụ wee wụnye ngwugwu carbon:

composer require psr/log

Ihe atụ mmepụta:

Using version ^1.1 for psr/log
./composer.json has been created
Running composer update psr/log
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking psr/log (1.1.4)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading psr/log (1.1.4)
  - Installing psr/log (1.1.4): Extracting archive
Generating autoload files

Dị ka n'elu, onye na-ede egwú ga-emepụta na-akpaghị aka ma melite faịlụ composer.json yana ndabere achọrọ. N'aka nke ọzọ, ịnwere ike ịwụnye ma ọ bụ wetuo ngwugwu dị na nọmba ụdịdị.

Ihe Nlereanya:

composer require psr/log=1.0

N'ime akwụkwọ ndekọ aha, ị nwere ike depụta faịlụ na akwụkwọ ndekọ aha dị n'ime ya site na iji ls iwu:

ls -l

Ihe atụ mmepụta:

./composer.json has been updated
Running composer update psr/log
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Downgrading psr/log (1.1.4 => 1.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading psr/log (1.0.0)
  - Downgrading psr/log (1.1.4 => 1.0.0): Extracting archive
Generating autoload files

Nhazi nke usoro na faịlụ ndị edepụtara.

  • onye dere.json - Faịlụ emepụtara maka ọrụ yana ndabere PHP niile.
  • dere - Faịlụ nwere ndepụta ngwugwu na ụdị niile.
  • ere - Akwụkwọ ndekọ ebe ebudatara ma tinye ihe ndabere.

Site na oru ngo gị, ị nwere ike ịchọrọ ma ọ bụ chọọ imelite ihe ndabere, ma enwere ike ime nke a na-agba ọsọ na-esonụ:

composer update

Ihe atụ mmepụta:

Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files

Dịka ị na-ahụ n'elu, ọ nweghị ihe ndabere chọrọ imelite. Ọ bụrụ na enwere, usoro a ga-amalite.

Ọ bụrụ na ịchọghị modul ahụ, ị ​​nwere ike wepu ya na iwu wepụ iwu nke onye dere ya:

composer remove psr/log

Ihe atụ mmepụta:

./composer.json has been updated
Running composer update psr/log
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
  - Removing psr/log (1.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 1 removal
  - Removing psr/log (1.0.0)
Generating autoload files

Mgbe ị na-ewepụ ngwugwu, dị ka ọ dị na ịwụnye, iwepụ ga-emelite faịlụ composer.json ozugbo. Ị nwere ike nyochaa nke a site na iji iwu cat.

cat composer.json

Ọmụmaatụ tupu iwepụ ngwugwu psr/log:

{
    "require": {
        "psr/log": "1.0"
    }
}

Ọmụmaatụ mgbe e wepụrụ ngwugwu psr/log:

{
}

Otu esi kwalite PHP Composer

Akụkụ dị mma nke onye na-ede PHP bụ na ọ nwere ike ịkwalite onwe ya gaa na ụdị kwụsiri ike kachasị ọhụrụ dị. Gbaa iwu a ka ịkwalite.

composer self-update

Ihe atụ mmepụta:

You are already using the latest available Composer version 2.1.8 (stable channel).

Dị ka ekwuru n'elu, onye na-ede akwụkwọ PHP adịlarị na ụdị kachasị ọhụrụ. Agbanyeghị, ọ bụrụ nkwalite dị, a ga-akpali gị ịkwalite.


Advertisement


Okwu na mmechi

Ị mụtala otu esi etinye onye na-ede PHP na usoro Debian 11 Bullseye gị yana ụfọdụ ọrụ na nkuzi. N'ozuzu, onye na-ede egwú bụ ngwá ọrụ mara mma na-ewu ewu, na obi abụọ adịghị ya na ị ga-ezute nke a dị ka onye mmepụta. Otu n'ime uru kachasị mma nke inwe onye na-ede egwú bụ na ọ na-emekọ ihe ndabere PHP na ntọala ọ bụla. Ị nwere ike ịnwe ọtụtụ ọrụ n'otu igwe nke dabere na ịwụnye ụdị PHP dị iche iche.

Ahapụ a Comment