{"id":11475,"date":"2021-10-29T10:47:51","date_gmt":"2021-10-29T10:47:51","guid":{"rendered":"https:\/\/linuxways.net\/?p=11475"},"modified":"2021-10-29T10:47:51","modified_gmt":"2021-10-29T10:47:51","slug":"how-to-install-php-composer-on-centos-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-install-php-composer-on-centos-8\/","title":{"rendered":"How to Install PHP Composer on CentOS 8"},"content":{"rendered":"<p>PHP Composer is a dependency manager used for managing all PHP project\u2019s dependencies. It pulls all the needed PHP packages on which a project depends and manages them in a good way.\u00a0 The composer is used in all modern platforms and PHP frameworks such as Magento 2, Laravel, Drupal, and Symfony. We will go through all steps for composer installation on CentOS 8 system in this tutorial. We elaborated two methods for PHP composer installation in this tutorial with proper implementation. Let us discuss both methods.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>The PHP should install on your CentOS 8 distribution. You can also <a href=\"https:\/\/linuxways.net\/de\/centos\/how-to-install-php-7-4-on-centos-8\/\">install PHP on CentOS 8<\/a> from this URL.<\/p>\n<p>Root or sudo privileges are needed for running the installation commands.<\/p>\n<h2><strong>Install PHP composer on CentOS 8<\/strong><\/h2>\n<p>By implementing the following steps, we can install PHP composer on CentOS 8 system:<\/p>\n<h3><strong>Step 1: Install Required Dependencies<\/strong><\/h3>\n<p>First, update all system packages and then, install all necessary dependencies including the PHP command-line interface package on CentOS 8 system by running the below-mentioned command:<\/p>\n<pre>$ sudo dnf install php-cli php-json php-zip wget unzip<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1107\" height=\"657\" class=\"wp-image-11476\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-524.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-524.png 1107w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-524-300x178.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-524-1024x608.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-524-768x456.png 768w\" sizes=\"auto, (max-width: 1107px) 100vw, 1107px\" \/><\/p>\n<h3><strong>Step 2: Download Composer Installer<\/strong><\/h3>\n<p>Once the all above packages are downloaded, download the PHP composer installer script by using the following command:<\/p>\n<pre>$ php -r \"copy('https:\/\/getcomposer.org\/installer', 'composer-setup.php');\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1196\" height=\"84\" class=\"wp-image-11477\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-525.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-525.png 1196w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-525-300x21.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-525-1024x72.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-525-768x54.png 768w\" sizes=\"auto, (max-width: 1196px) 100vw, 1196px\" \/><\/p>\n<p>After executing the above-mentioned command \u2018composer-setup.php&#8217; file is to be downloaded into the current working directory.<\/p>\n<h3><strong>Step 3: Verify data integrity<\/strong><\/h3>\n<p>Download the latest composer installer using the following wget command from the Github Composer\u2019s page and store it into a \u2018Hash\u2019 variable:<\/p>\n<pre>$ HASH=\"$(wget -q -O - https:\/\/composer.github.io\/installer.sig)\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1191\" height=\"60\" class=\"wp-image-11478\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-526.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-526.png 1191w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-526-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-526-1024x52.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-526-768x39.png 768w\" sizes=\"auto, (max-width: 1191px) 100vw, 1191px\" \/><\/p>\n<p>Now, verify that the installation script is either running or not by typing the below-mentioned command on the terminal:<\/p>\n<pre>$ php -r \"if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1192\" height=\"143\" class=\"wp-image-11479\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-527.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-527.png 1192w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-527-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-527-1024x123.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-527-768x92.png 768w\" sizes=\"auto, (max-width: 1192px) 100vw, 1192px\" \/><\/p>\n<p>If after comparison, the hashes match it means the installer is verified and the following message will show on the terminal:<\/p>\n<p>In another case, it shows a message \u2018Installer corrupted\u2019. Once your installer script identity is verified, move to the next step.<\/p>\n<h3><strong>Step 4: Install Composer<\/strong><\/h3>\n<p>In this step, you will install php composer on your system\u00a0 by running the below-mentioned command:<\/p>\n<pre>$ sudo php composer-setup.php --install-dir=\/usr\/local\/bin --filename=composer<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1201\" height=\"271\" class=\"wp-image-11480\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-528.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-528.png 1201w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-528-300x68.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-528-1024x231.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-528-768x173.png 768w\" sizes=\"auto, (max-width: 1201px) 100vw, 1201px\" \/><\/p>\n<p>The above command installs the PHP composer as system-wide and every user can use this command for composer installation. The following output receives on the terminal after executing the above command:<\/p>\n<p>Now, verify the composer installation by displaying the installed version on the terminal window as follows:<\/p>\n<pre>$ composer -V<\/pre>\n<p>You will see that installed version displayed on the screen as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1196\" height=\"98\" class=\"wp-image-11481\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-529.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-529.png 1196w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-529-300x25.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-529-1024x84.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-529-768x63.png 768w\" sizes=\"auto, (max-width: 1196px) 100vw, 1196px\" \/><\/p>\n<p>The installation of PHP composer is completed at this point on your CentOS 8 system. Now, start the composer and use it.<\/p>\n<h2><strong>Alternative method: Install PHP composer using a quick way<\/strong><\/h2>\n<p>This method provides the quick method for Composer installation on CentOS 8 system. Perform the following few steps to install PHP composer:<\/p>\n<p><strong>Step 1.<\/strong> Install required PHP, zip, unzip and curl packages by using the following command:<\/p>\n<pre>$ sudo dnf install php-cli php-json php-zip curl unzip<\/pre>\n<p><strong>Step 2.<\/strong> Using the curl command, download the composer installer.<\/p>\n<pre>$ curl -sS https:\/\/getcomposer.org\/installer |php<\/pre>\n<p><strong>Step 3.<\/strong> Now, Move all files of php Composer into the \u2018\/usr\/local\/bin\u2019 directory by running the below-mentioned command:<\/p>\n<pre>$ sudo mv composer.phar \/usr\/local\/bin\/composer<\/pre>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>We installed the PHP composer in this article on CentOS 8 system. We discuss two different methods for composer installation on CentOS 8. You can choose a method from both that more suits your needs.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>PHP Composer is a dependency manager used for managing all PHP project\u2019s dependencies. It pulls all the needed PHP packages on which a project depends and manages them&hellip;<\/p>","protected":false},"author":1,"featured_media":11701,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[93,70],"class_list":["post-11475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-centos-8","tag-php"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=11475"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11475\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/11701"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=11475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=11475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=11475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}