Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How To Install and Use PHP Composer on Debian 11

    How To Install and Use PHP Composer on Debian 11

    RahulBy RahulSeptember 28, 20214 Mins ReadUpdated:February 16, 2022

    PHP Composer is basically a dependency management tool for PHP applications. It provides hassle-free installation of PHP modules for the applications. The composer keeps track of all the modules required for the application and installs them with a single command. It also allows users to keep modules updated. You can easily install all the required packages using Composer. The composer maintains a list of required packages in a JSON file called composer.json.

    Composer is a similar tool to npm for Node.js, pip for Python, and bundler for ROR. Composer 2 is the latest available version for your system with enhanced performance. We will use that version to install on our system.

    This tutorial helps you to install and use PHP composer on Debian 11 Bullseye Linux system.

    Prerequisites

    • Shell access to a running Debian system with sudo privilege.
    • Install PHP 5.3 or higher version on Debain.
    • All newly installed systems recommended to follow initial server setup with Debian 11

    Installing PHP Composer on Debian

    A PHP script is provided by the official team to configure the composer on your system. You can download it with curl or wget command-line utility. Also, you can download it with the PHP script.

    Open a terminal and run:

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

    A composer-setup.php file will be created in current directory. Now execute this PHP script to install the composer at the desired location. Use --install-dir to set the binary location and --filename to set the binary name. You can install composer globally accessible for all users and projects or install locally for a specific project.

    • To install composer globally, type:
      php composer-setup.php --install-dir=/usr/local/bin --filename=composer
      chmod +x /usr/local/bin/composer
      
    • You can also install composer under the specific application. This is helpful for shared hosting environments, where you don’t have sudo or root access. To install composer locally for a specific project, type:
      cd /path/to/php-application && mkdir -p bin 
      php composer-setup.php --install-dir=bin --filename=composer
      chmod +x bin/composer
      

      Change /path/to/php-application with the actually application directory.

    To see the installed composer version execute binary with -v command parameter.

    composer --version
    
    Output:
    Composer version 2.2.6 2022-02-04 17:00:38

    Upgrade PHP Composer

    The PHP composer has the ability to self-upgrade to the latest versions. If the composer is already installed on your system, just type the below command to upgrade PHP composer to the latest version.

    composer self-update
    

    In my case, I already have latest version of composer. So receive the following message on terminal:

    Output:
    You are already using the latest available Composer version 2.2.6 (stable channel).

    Working with PHP Composer

    You have already installed and configured the composer on your system. Composer will help you to manage modules for your application. For example, to install a new module for your application.

    Switch to the PHP application.

    cd /path/to/php-application 
    

    Run the following command to install psr/log module in the application.

    composer require psr/log
    
    Output:
    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

    Composer will automatically create or update composer.json file at application root directory. Now, the application can use the functionality provided by the module.

    The above command will install the latest version of the module. You can also define the module version you want to install for your application. If the module is already installed, it will automatically downgrade/upgrade package to the specified version.

    composer require psr/log=1.0
    

    The module no longer required can be removed with the following command.

    composer remove psr/log
    

    All the above commands also update composer.json file accordingly.

    Conclusion

    In this tutorial, you have found instructions to install composer on a Debian Linux system. You can install composer globally to allow access to all users and applications. Also, you can install composer for a specific directory.

    composer Debian 11 PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install MariaDB on Debian 11
    Next Article 10 Best Linux Screen Recording Tools in 2022

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Install Oracle VirtualBox on Debian 11

    2 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.