1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Calling Dotenv manually, rather than relying on autoload.php

Discussion in 'PHP' started by sarahk, Jan 28, 2020.

  1. #1
    I've managed to go this long without having to use git to manage source code but I want to use a library which will let me integrate with the Xero accounting system and I need to play by their rules.

    I'm on shared hosting with Plesk because the sites are very, very low traffic in a very, very targetted niche.

    So, I used Plesk to install the main git package and it installed the dependencies - however, the main git package didn't have Dotenv as a dependency. I don't want to fork because I can see the value in having them maintain their code.

    So, I've used Plesk to add Dotenv and my files are organised like this

    hosting/git/xero
    hosting/git/dotenv
    hosting/httpdocs/git/xero/vendor/... all the other packages

    My code calls hosting/httpdocs/git/xero/vendor/autoload.php and I'm not sure what it actually does but I can see that it doesn't load Dotenv.

    What do I call to get Dotenv loaded?

    upload_2020-1-29_15-46-19.png
     
    sarahk, Jan 28, 2020 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    You'll "need" command line access and NPM or YARN installed. Instructions right on dotenv's page.

    https://www.npmjs.com/package/dotenv

    Given it's a system level node.js package I'm surprised you were able to get this far just using Plesk... much less run ANY of this on shared hosting since most of them tell you "no" -- and sometimes even "f*** off" -- when it comes to even installing node.js on shared hosting plans.

    It's also a bit weird that a PHP codebase would rely on a NPM package that does what PHP's $_ENV already handles.

    Unless we're talking an entirely different dotenv... or PHP is trying to read .env files which... shouldn't be necessary for much of anything.
     
    deathshadow, Feb 1, 2020 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    different package.
    turns out it was only needed to get the api keys and then not used again - and they said you shouldn't use it in the production version of the code so I have no f'ing idea why they bothered in the first place. For all the effort of finding that package against editing a standard php file that can be required. I last messed with xero back in '14 and despaired of the html it spat out (id used multiple times etc) but hoping they've tidied up their act.
     
    sarahk, Feb 1, 2020 IP