access denied when using netrc via php-curl on apache

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
nebules
Posts: 2
Joined: Tue May 16, 2023 5:33 pm America/New_York
Answers: 0

access denied when using netrc via php-curl on apache

by nebules » Tue May 16, 2023 5:36 pm America/New_York

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.

Tags:

mgangl
Posts: 1
Joined: Thu May 27, 2021 2:52 pm America/New_York
Answers: 0

Re: access denied when using netrc via php-curl on apache

by mgangl » Thu May 18, 2023 12:47 pm America/New_York

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:

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.

nebules
Posts: 2
Joined: Tue May 16, 2023 5:33 pm America/New_York
Answers: 0

Re: access denied when using netrc via php-curl on apache

by nebules » Thu Aug 03, 2023 10:45 am America/New_York

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');

Post Reply