简体   繁体   中英

Install a package using composer. How? Where?

I'm fairly new to PHP and Composer and used Linux 20 years ago. I'm developing a website on a shared hosted server (Hostinger) and trying to install a package from Cardinity (they take VISA payments). I want to use this package from my website which I've hand written in HTML/PHP/MySQL etc.

The instruction from cardinity is to execute the following (from https://github.com/cardinity/cardinity-sdk-php ):

$ php composer.phar require cardinity/cardinity-sdk-php

I've changed this to:

$ php /usr/local/bin/composer.phar require cardinity/cardinity-sdk-php

So that it runs without error.

I have two questions which are:

  1. Am I right in thinking that composer will locate and download the package (and sub-packages it requires) for me? I don't have to do anything other than execute this line?

  2. In which directory do I execute this?

My website is in /home/u123456789/public_html . I've executed the above statement in /home/u123456789/public_html and ended up with composer.json and composer.lock files in that directory, as well as a vendor folder. However, my website doesn't pick up the package. When I execute a simple test.php file with the following code in (as advised by Cardinity):

use Cardinity\Client;
$client = Client::create([
    'consumerKey' => 'YOUR_CONSUMER_KEY',
    'consumerSecret' => 'YOUR_CONSUMER_SECRET',
]);

I get the error: Fatal error: Class 'Cardinity\\Client' not found in /home/u123456789/public_html/dev/test.php on line 32 which is on the Client::create line. My test.php file is in the directory /home/u123456789/public_html/dev .

Does test.php have to be in the same directory as composer.json , composer.lock and vendor ?

Please try and make it a bit harder for hackers and place items not as per documentation and in properties that follow your own naming convention.

Also add a security measure if some one does try to access the "default". Someone having your keys as do some real harm with a refund.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM