• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using composer to install thirdparty library

#1
Hi,
I am maybe asking "stupid" question but can someone help me with installing thirdparty library using composer.
First, I never used composer as I always install scripts manual (CI 4 is installed in manual way too). I know that it is used for installing and updating scripts but that is all.

So now I need to use https://github.com/ScoLib/cfscrape as part of my script is scraping data from other sources which sometimes are protected with Cloudflare DDoS protection.

 I have to run this command:
Code:
$ composer require cfscrape/cfscrape

But I don't know how and where. I guess that I have to login to my VPS via SSH and run it. Also have no idea where it would put files after running this command. Can it brake CI 4 folder structure or something. 

Any help is welcome.

Edit:
OK, I figure it out how to use composer: login to VPS and run "composer" command.
But is there anything that I should edit like config files or something to tell composer where to install libraries according to CI4 filder structure
Reply

#2
this is always a good read: https://getcomposer.org/

Now you mention vps but lets separate where your app is being hosted for a minute. From my playing around with CI4 the appstarter, seems to lend itself to best suit using composer.

you can either set up composer locally in a dev direcectory or globally.

i'm on slackware Linux so i downloaded composer.phar and moved it to /usr/local/bin/ and made a link so i just run "composer" to use it. i think you have to use php composer.phar <> if you don't do that - read above link docs .

Now if you have your web in development locally on your PC and use composer, zip up and load to server ; if it works on your local it should work live on your server.

To use composer , for example i cd from a terminal to inside app root and for example run something like.

$ composer require spipu/html2pdf

Then i see in vendor directory and sub directory called "spipu" . When i look in composer.json file located root i now see:

Code:
"require": {
        "php": ">=7.2",
        "codeigniter4/framework": "^4",
        "spipu/html2pdf": "^5.2",
        "twbs/bootstrap": "^4.5"
    }

Now i can now run composer using "composer install" "composer update". The whole point of composer is that it simply installs stuff , deps and keeps things up to date.Composer install from memory should install the deps of software you downloaded.

In terms of how does it know how to use say spipu well, the stuff you downloaded will be auto-loaded automatically by autoload.php.

If you messed about , removed stuff and need to tell composer to update, you can run "composer dump", it should then display something like xx classes ..acknowledged or words to that effect.



if i want to update everything i cd into root of app directory and just run:

Code:
composer update


if i see there there is a new release of codeigniter and only want to update that i can run:


Code:
composer update codeigniter4/framework
Reply

#3
captain-sensible tnx for reply.
I did visit composer web page to try figure it out and I did in some way but I am not sure how it will play along with CI4.

So lets clarify few thing:
1) I am running VPS on which I have 5 non related projects, and on of them are this Codeigniter 4
2) I tried to login via SSH to my server and run "composer" command which showed me that composer is installed and ready to use
3) I would like to install  cfscrape only to my Codeigniter 4 project and not others on server as I don't need it anywhere else
4) My CI4 framework is not installed via composer but I installed it manual so I don't know if paths and other important things are set correctly for installing new libraries via composer

-----------------------------
So I figure it out that if I want to install something with Composer only in specifi folder I need to run composer in that project, righ? 
1) login to server
2) cd web/my_project
3) composer
4) run command
5) -it installs something in vendor folder somwhere under /my_project....

is this correct logic?

Under CI 4 structure I don't know where is vendor folder and how to tell composer to install it there.
I see that i have composer.json file in root of my project. Is there need to edit it first?
Reply

#4
Your correct in method but i'm saying do this on local project , then just upload manually


i don't have my own vps or server and there is no way (i think ) that they would allow me to run composer on a shared server .
Your right in principal; i guess give it a go if you have access permissions and you are prepared to fix if something doen't go right.



Maybe others would chip in on this who have more experience.




But this is my general approach : Always have a version control of project running locally.Even trying to edit code on a live web via cpanel can lead to a cold sweat when things go wrong in my experience.


I use apache on slackware and separate projects via virtual host and use 127.0.0.2 -> 127.0.0.6 to access each , or via their created domain.

When everything is working , then upload it manually just uploading in zip format via cpanel.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.