So I'm following your directions on this page:
https://urs.earthdata.nasa.gov/documentation/for_users/data_access/php
And the netrc file I created works fine via command line (ubuntu):
curl -O -b <path to cookies file> -c <path to cookies file> -L -n https://opendap.earthdata.nasa.gov/collections/.....
But it doesn't when using the php-curl script example described in the link above. When I use curl via command line and then use the php-curl script then the latter works, but only because authentication has already been performed.
So I'm wondering where this netrc file should actually reside to get the php-curl script to work. I doubt /home/ubuntu is proper place for it when utilized by php-curl.
access denied when using netrc via php-curl on apache
Re: access denied when using netrc via php-curl on apache
For the record, i'm not a PHP practitioner.
The .netrc file should be in the home directory of whomever is running the script. if that is the "ubuntu" user, then it should go there (/home/ubuntu/.netrc). Seeing as how this is working for curl on your command line, but not via php, my only guess would be not specifying:
in your code.
If that's not the case, please post your code snippet here, so we can look at the details. That might help.
The .netrc file should be in the home directory of whomever is running the script. if that is the "ubuntu" user, then it should go there (/home/ubuntu/.netrc). Seeing as how this is working for curl on your command line, but not via php, my only guess would be not specifying:
Code: Select all
curl_setopt($ch, CURLOPT_NETRC, true);
in your code.
If that's not the case, please post your code snippet here, so we can look at the details. That might help.
Re: access denied when using netrc via php-curl on apache
Solution: PHP code is run by Apache user (www-data on Ubuntu), so I had to move the netrc file to /home/www-data/, and add this curl option to my PHP code:
curl_setopt($ch, CURLOPT_NETRC_FILE, '/home/www-data/.netrc');
curl_setopt($ch, CURLOPT_NETRC_FILE, '/home/www-data/.netrc');