ChenXiu Posted August 28, 2021 Share Posted August 28, 2021 I go to GitHub and see a package I like. I download said package to my Ubuntu Server. How do I install it using Composer? NO, this is not a "I just discovered GitHub today and, by the way, what's Composer?" question.RATHER, this is YEARS of google-searching frustration, and YEARS of NEVER being able to figure out how the hell to use Composer, in spite of hours upon hours upon days upon weeks upon months of research. Whoever invented composer........... hmm. Sitting in my Ubuntu directory is an unzipped package I downloaded from Github. Lets call it "doghouse_master.api" Inside of doghouse_master.api is the README.md which has never made sense. There is also a composer.json in there. And there is a "lib" directory. I also have Composer installed on my Ubuntu server, so I can begin commandlines with the word "composer......." Would someone be kind enough to tell me what might be the next step? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/ Share on other sites More sharing options...
Strider64 Posted August 28, 2021 Share Posted August 28, 2021 (edited) This deals with auto loading classes in php, but it should help you -> https://phpenthusiast.com/blog/how-to-autoload-with-composer or this which is probably more what you are looking for https://phpenthusiast.com/blog/how-to-use-packagist-and-composer A great resource for composer - https://getcomposer.org/ Composer has been around for awhile. Edited August 28, 2021 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/#findComment-1589422 Share on other sites More sharing options...
kicken Posted August 28, 2021 Share Posted August 28, 2021 4 hours ago, ChenXiu said: I go to GitHub and see a package I like. I download said package to my Ubuntu Server. The idea behind composer is that you don't download the package from github. You add the package name to your composer.json file as a requirement and let composer download it for you. The package name is often the same as the github repository, but not always. Check the package's composer.json file for the name you need. If the package doesn't install after adding the name to your composer.json file, then it may not listed on packagist.org. If that's the case, you need to also add the github repository to your composer.json file's list of repositories so it can find the package to download it. The whole idea behind using something like composer is that you should never need to manually download and install your libraries. You just add them to the list (and optionally the version requirement) and let composer handle everything for you. Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/#findComment-1589428 Share on other sites More sharing options...
requinix Posted August 28, 2021 Share Posted August 28, 2021 5 hours ago, ChenXiu said: NO, this is not a "I just discovered GitHub today and, by the way, what's Composer?" question.RATHER, this is YEARS of google-searching frustration, and YEARS of NEVER being able to figure out how the hell to use Composer, in spite of hours upon hours upon days upon weeks upon months of research. You've spent "months" and "years" trying to understand Composer and never found out about composer require? Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/#findComment-1589433 Share on other sites More sharing options...
ChenXiu Posted August 28, 2021 Author Share Posted August 28, 2021 (edited) 6 hours ago, Strider64 said: or this which is probably more 49 minutes ago, requinix said: found out about composer require? Ha! I been around da' block! I wear a T-Shirt that says "Composer" on the front and "Require" on the back! So, seriously, I have tried "composer require......" at least 100 times (over the years I've found at least 100 things on GitHub I've wanted to try). IT NEVER WORKS! So, giving you an example (to prove that I'm not an armchair complainer that doesn't lift a finger), here is what I did: 1.) I downloaded a package today called doghouse-master-api.zip. 2.) I sent it to my Ubuntu server. 3.) I unzipped it. 4.) Now I'm cd'd into my home directory and there is now a directory in there called "doghouse-master-api" 5.) I ran the command "composer require doghouse-master-api" 6.) An ugly apocalyptic crimson rectangle appears (they use crimson just to freak me out) with the error message:[Composer\Downloader\TransportException] The "https://api.github.com/repos/git_user_id/git_repo_id" file could not be downloaded (HTTP/2 404 ) 7.) Like always, I google the error message and it says to run "composer config -g repo.packagist composer https://packagist.org" 8.) Like always, this, and any other suggestion, doesn't work. 9.) I try the 2nd suggestion: "add such-and-such to your composer.json file" 10.) WHAT "composer.json" file? I didn't put no composer.json file in there.... 11.) I check, and sure enough there is a composer.json file there with just { } in it. So I stick what they said I should stick in there, so now it looks like:{"repositories": [ { "type": "composer", "url": "https://packagist.org" }, { "packagist": false } ] } 12.) I run "composer require doghouse-master-api" again. 13.) Now I get ANOTHER error message that says "could not find matching package of doghouse-master-api" 14.) I realize that I put a "packagist.org" url in my composer.json file. I'M NOT USING PACKAGIST the stupid computer should know that. 15.) I then re-read the clumsy "README.md" in my package. It says to put this in it.{ "repositories": [ { "type": "vcs", "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" } ], "require": { "GIT_USER_ID/GIT_REPO_ID": "*@dev" } } 16.) "Aaah! There's my answer" I think in my mind. 17.) WRONG! I get another apocalypse that says I can't use capital letters even thought that's what the damn README.md says. 18.) I change it to lower case. 19.) I get YET ANOTHER error message:[Composer\Downloader\TransportException] The "https://api.github.com/repos/git_user_id/git_repo_id" file could not be downloaded (HTTP/2 404 ) 20.) And that concludes another day of several hours buried in Composer hell. I think in my mind "All this stuff is so stupid it's a ridiculous thing for stupid people that didn't learn PHP back in the 90's like I did and they need their stupid back forward slash autoload dependancy public class private class backslash nonsense because they're too dumb to write the 2 lines of code to get the job done and they learned PHP from a dumb teacher in a dumb college and all this stupid program that I'm trying to download needs is probably about 2 lines of code buried somewhere within it if I could just find it." 21.) And then I go and watch Anime and relax, and chalk up another wasted day of "trying to make Composer work." I'm going to watch Anime now. 😀 Edited August 28, 2021 by ChenXiu Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/#findComment-1589436 Share on other sites More sharing options...
kicken Posted August 29, 2021 Share Posted August 29, 2021 1 hour ago, ChenXiu said: IT NEVER WORKS! As I said, you're doing it wrong, from step 1. Downloading the library is the "old" way of managing your libraries, there's no need for downloading it manually if you're using composer. If you want to use composer then you need to start by creating your own composer.json file for your project. Use composer init to create your initial json file. mkdir chenxiu-doghouse cd chenxiu-doghouse composer init Then you require the library you want to use by it's identifier. It's identifier should exist in its composer.json file. The name may also be mentioned in the readme or found on packagist.org. composer require doghouse/doghouse-master-api If the library is not listed on packagist.org (ie, private/proprietary library) then you may need to add the repositories entry into your composer.json file before you can require it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313615-composer-how/#findComment-1589438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.