PHP Composer – Install Dependency

Greetings – Now we are testing your great new Hosting product :slight_smile:

#1) Please confirm “PHP Composer” is pre-installed into our new WP site?

#2) Could you provide instructions on exactly how to install a dependency package via composer? We are brand new to composer, so how do we run the “require” command found here:

composer require zendesk/zendesk_api_client_php

Do we need to connect via SSH and run the command above from BASH CLI ?

GOAL: We need to install this PHP Dependency Library:

https://packagist.org/packages/zendesk/zendesk_api_client_php

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey VirtualArtists ,

    Yes it’s exactly as easy as you said :slight_smile: . You simply connect to your environment via SSH and then you have 2 options:

    Either run “composer require zendesk/zendesk_api_client_php” on the necessary folder that the composer.json & vendors should be added.

    Or, create a composer.json file first and run “composer install” from the same folder that you placed composer.json.

    I’m not entirely sure what you’re trying to achieve here or why exactly is this package needed, could you please explain further? Usually if a plugin needs it it should be already including it with it’s code, it’s unusual to ask users to install dependencies on their own :slight_smile: .

    Please note that the commands might not be working right away, we’re currently doing some updates regarding our SSH and composer as we had noticed some issues, I will inform you when they will be fully available :slight_smile: .

    Regards,

    Konstantinos

  • SoftArt
    • The Incredible Code Injector

    Thanks for quick and clear response – to clarify further:

    I’m not entirely sure what you’re trying to achieve here or why exactly is this package needed, could you please explain further?

    Our code team is actually developing our own custom plugin to integrate with ZenDesk API. This is not a commercial plugin, rather for our internal use only. ZenDesk will only provide official support for this API integration IF we use their “PHP API Client” located here:

    https://packagist.org/packages/zendesk/zendesk_api_client_php

    We are coders, but generally new to “PHP Composer”. We chose WPMU hosting – for many reasons – but specifically because you already had “PHP Composer” installed, which allows us to get up and running quickly :slight_smile:

    The only question now is exactly WHERE / Which Folder to install composer packages into?

    I think we want the resulting “vendor” folder in the ROOT of the website, so we can use this exact code below:

    // load Composer
    require 'vendor/autoload.php';

    use ZendeskAPIHttpClient as ZendeskAPI;

    Can you confirm the code above expects the “vendor” folder to be in the ROOT website folder “public_html” ?

    To use the exact code above, in which folder should we run this command?

    composer require zendesk/zendesk_api_client_php

    Please note that the commands might not be working right away, we’re currently doing some updates regarding our SSH and composer as we had noticed some issues, I will inform you when they will be fully available

    Yes, please let us know after you have completed your hosting updates, and let us know when your platform is ready for us to try running the above “composer require” command?

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Perfect VirtualArtists , thank you for clarifying :slight_smile: .

    Okay so let me explain how you can do this since you're creating your own plugin.

    Let's say you have your plugin into wp-content/my-plugin/ .

    First of all to load the libraries you should add the

    // load Composer
    require_once ( __DIR__ . '/vendor/autoload.php' );
    use ZendeskAPIHttpClient as ZendeskAPI;

    Into your plugins code, that could be on the general loading Class, or the main plugin file or anywhere that you would need the dependencies to load first, that's up for you to decide :slight_smile: .

    Then you have to see if you want to "carry" that dependency and any other "with" the plugin or not, this means to choose if you want to have it inside your plugin folder or not. This will determine when to run the composer require zendesk/zendesk_api_client_php command as it will create all the necessary files on that folder.

    As an example if you want it in your plugin you can login via ssh and then:

    $ cd ~/site/public_html/wp-content/my-plugin/
    $ composer require zendesk/zendesk_api_client_php

    It will create the necessary files, a composer.json, a composer.lock and the /vendor/ folder with all needed dependencies as shown here:

    You can do the same in a different folder, just change the path of the require_once to point to the correct one that has the autoload.php :slight_smile: .

    Usually all dependencies go "inside" the plugins at a folder named "lib" or something similar so if you want to move that plugin on another installation you don't have to redo the above steps, especially if there's no access to CLI/Composer there you will already have all the needed files.

    I don't recommend running it on public_html as they are not WP related files so better to have them somewhere "close" to your plugin to avoid any issues or confusion in the future.

    I'll let you know when everything is ready on our side as well so you can start your process :slight_smile: .

    Regards,

    Konstantinos

  • SoftArt
    • The Incredible Code Injector

    Hi – Many thanks for your last post above, very clear and helpful :slight_smile:

    We will need more time to study, but overall now we are much more clear on how and where to install composer.

    I don’t recommend running it on public_html as they are not WP related files so better to have them somewhere “close” to your plugin to avoid any issues or confusion in the future.

    I agree with you, that it makes the most sense to keep composer (vendor folder) installed “with the plugin”, i.e. in the same plugin folder.

    I’ll let you know when everything is ready on our side as well so you can start your process

    Yes, please let us know when your Hosting SSH + Composer are Updated, so we can start our process.

    Great Support :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.