dqk94069 2018-03-28 13:33
浏览 124
已采纳

全局PHP安装包:apt-get vs composer

I found there are two options to install PHP package globally in Linux (Ubuntu 16.04):

  1. Using composer:

    composer global require symfony/finder
    

    The package will be located at ~/.config/composer/vendor/

    enter image description here

  2. Using apt-get:

    apt-get install php-symfony-finder
    

    The package will be located at /usr/share/php/

    enter image description here

    This directory /usr/share/php/ is also in default PHPs include_path (I have PHP 7.2)

    enter image description here


There are several questions I have:

Why would I want to install package globally ?

I know it's useful to install php tools globally, like phpunit - It has binary file and it allows you to run tests everywhere, so you don't have to install it in every project. But what about symfony/finder for example ? What is particular use of this package installed globally ?

What is the difference between 1 and 2 option ?

Does it have any different use cases or different effects ?

  • 写回答

1条回答 默认 最新

  • dph58509 2018-03-28 14:19
    关注

    Why would I want to install package globally ?

    Normally, these are dependencies you want to use in almost every project, because they are available at a system level you can use them without duplicating their dependencies in every application you create.

    For example, in my case I have php_md, php_cs for code formatting, phpunit for testing.

    What is the difference between 1 and 2 option ?

    Both are package managers, they make sure every package installed has the correct dependencies, so their core functionality is similar.

    Now, they have several differences:

    • Their focus in the packages they manage, composer is specific for php based packages but apt-get is for Linux and more system level oriented.
    • Their package database, composer uses packagist and apt-get uses a selection of repositories and ppas (you can find them in /var/lib/apt/lists/).
    • The package selection, since composer is specialized in php you can expect a wider variety in anything php related.

    In conclusion, you can clearly make it work with both, but I would recommend you to keep everything php related on composer, unifying them under the same manager.

    Any other difference or correction I've overlooked is welcome.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?