{"id":1004,"date":"2021-12-07T08:08:04","date_gmt":"2021-12-07T08:08:04","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2021\/12\/07\/5792078-how-to-use-composer-at-hostinger\/"},"modified":"2026-03-16T12:12:09","modified_gmt":"2026-03-16T12:12:09","slug":"5792078-how-to-use-composer-at-hostinger","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/5792078-how-to-use-composer-at-hostinger\/","title":{"rendered":"How to Use Composer at Hostinger"},"content":{"rendered":"<p class=\"no-margin\">PHP Composer is a tool that can help you manage and organize the external libraries and packages used in PHP projects, making it easy to add, update, or remove packages as needed.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_7eb4b9f5ce\">How to Check the Composer Version<\/h2><p class=\"no-margin\">Both <b>Composer 1 <\/b>(deprecated) and <b>Composer 2 are already pre-installed<\/b> on our Web Premium, Web Business, and Cloud plans. You can verify the installed versions <b><a href=\"\/support\/1583245-how-can-i-log-in-to-my-account-via-ssh\" target=\"_blank\" class=\"intercom-content-link\">via SSH<\/a> <\/b>by running these commands:<\/p><ul>\n<li>\n<p class=\"no-margin\">For Composer, type <code>composer<\/code>. You will get the following result:<\/p>\n<p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"https:\/\/blog.hostinger.io\/pt\/support\/wp-content\/uploads\/sites\/59\/2022\/07\/dbd8e7fc-1ef7-4496-8f6e-fde59a2294f2.jpg\" alt=\"The installed Composer 1 version on your hosting environment\"><\/div>\n<p class=\"no-margin\">&#8203;<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Similarly, you can type <code>composer2<\/code> for the Composer 2 version:<\/p>\n<p>&#8203;<\/p>\n<div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"https:\/\/blog.hostinger.io\/pt\/support\/wp-content\/uploads\/sites\/59\/2022\/07\/d82a98fc-9692-4476-9db3-5c417876e786.jpg\" alt=\"The installed Composer 2 version on your hosting environment\"><\/div>\n<\/li>\n<\/ul><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">In both cases, the command-line template will be shown below the Composer version, as well as a list of available <b>options <\/b>and <b>commands<\/b>.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_54b6ba7f7c\">How to Install a Package Using Composer<\/h2><ol>\n<li>\n<p class=\"no-margin\">Go to the <b><a href=\"https:\/\/packagist.org\/\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Packagist<\/a> <\/b>repository and find the PHP package you want to install. Keep this page open for reference<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Access your hosting environment <b><a href=\"\/support\/1583245-how-can-i-log-in-to-my-account-via-ssh\" target=\"_blank\" class=\"intercom-content-link\">using SSH<\/a><\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Use the <code>cd<\/code> command to navigate to the desired directory on your hosting. Consider that <b>each package needs to be installed separately on every website<\/b> or project where you will need it<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Copy the command from Packagist and <b>paste it onto the terminal<\/b>. This will either create the <b>composer.json<\/b>, <b>composer.lock<\/b> files and the <b>vendor<\/b> directory or update them if they already exist<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Proceed to test the installed package by creating or modifying your relevant PHP files<\/p>\n<\/li>\n<\/ol><div class=\"intercom-interblocks-callout\" style=\"background-color: #e3e7fa80;border-color: #334bfa33\">\n<p class=\"no-margin\">If your hosting uses <b><a href=\"\/support\/5920192-how-to-check-the-php-version\" target=\"_blank\" class=\"intercom-content-link\">PHP version<\/a><\/b> <b>8.0 or higher<\/b>, use <b>composer2<\/b> instead of <b>composer<\/b>, like this: <code>composer2 [command]<\/code><\/p>\n<\/div><p class=\"no-margin\">\n<\/p><h3 id=\"h_81cce9b843\">Example<\/h3><p class=\"no-margin\">Let&rsquo;s use <b>PHPMailer <\/b>as an example. Open the <b><a href=\"https:\/\/packagist.org\/packages\/phpmailer\/phpmailer\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Packagist repository<\/a><\/b> to find the installation command:<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"https:\/\/blog.hostinger.io\/pt\/support\/wp-content\/uploads\/sites\/59\/2022\/07\/255bb82f-cd16-4b2d-acfa-f8716d7d72a5.jpg\" alt=\"The composer command to install phpmailer on your hosting\"><\/div><p class=\"no-margin\">Now, on your SSH terminal, navigate to the website&rsquo;s root folder. In this case, for <b>domain.tld<\/b>, the <code>cd<\/code> command will be as follows:<\/p><p class=\"no-margin\">\n<\/p><pre><code>cd domains\/domain.tld\/public_html\/<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Once you&rsquo;ve reached the desired location, enter the composer command from Packagist. Since support for Composer 1 is deprecated, the <b>composer2<\/b> command will be used instead:<\/p><p class=\"no-margin\">\n<\/p><pre><code>composer2 require phpmailer\/phpmailer<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">The output will look similar to this:<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"https:\/\/blog.hostinger.io\/pt\/support\/wp-content\/uploads\/sites\/59\/2022\/07\/0e8f8f2e-5549-4193-a452-fcf1fe28a182.jpg\" alt=\"A terminal window showing the output of a successful phpmailer installation using composer2\"><\/div><p class=\"no-margin\">That&rsquo;s it &ndash; PHPMailer is successfully installed for <b>domain.tld<\/b>. You can verify it because the <b>vendor\/phpmailer<\/b> directory will be created.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">For installing it in another project, return to the <b>domains<\/b> directory using the command <code>cd ..\/..<\/code> then navigate to the <b>public_html<\/b> directory of the new domain, such as <b>website.tld<\/b>:<\/p><p class=\"no-margin\">\n<\/p><pre><code>cd website.tld\/public_html\/<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Repeat the installation process as before. In case you encounter any issues, check this article: <b><a href=\"\/support\/5792082-how-to-solve-the-most-common-composer-issues\" target=\"_blank\" class=\"intercom-content-link\">Solving Common Composer Errors<\/a><\/b>.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\"><b>Additional Resources<\/b><\/p><ul>\n<li>\n<p class=\"no-margin\">Check the following tutorial for a comprehensive PHPMailer guide: <b><a href=\"https:\/\/www.hostinger.com\/tutorials\/send-emails-using-php-mail#Understanding_PHPMailer_Components\" target=\"_blank\" class=\"intercom-content-link\">How to Send Emails with PHP Mailer<\/a><\/b><\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Using Composer with on Web and Cloud hosting plans at Hostinger<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[235],"tags":[],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-ssh-connection-and-ssh-keys"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/5792078-how-to-use-composer-at-hostinger\/","default":1},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/support\/5792078-como-usar-composer-en-hostinger\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/support\/5792078-comment-utiliser-composer-chez-hostinger\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/support\/5792078-bagaimana-cara-menggunakan-composer-di-hostinger\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/br\/support\/5792078-como-usar-o-composer-no-hostinger\/","default":0},{"locale":"uk-UA","link":"https:\/\/www.hostinger.com\/ua\/support\/5792078----composer--hosti\/","default":0}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=1004"}],"version-history":[{"count":1,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":4069,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1004\/revisions\/4069"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}