Tychoash
Tychoash

Reputation: 11

How to fix a cURL error 60: SSL certificate problem using a PutObject in AWS

First and foremost, I am a total noob when it comes to using Amazon's SDK for PHP so bare with me. I am trying to follow along with a video tutorial on how to upload a file to an AWS S3 bucket using PHP and the AWS SDK.

I have all of the correct information to start the process but I get the following error when trying to upload the file on my localhost instance:

Error uploading files: Error executing "PutObject" on "https://bregg.s3.amazonaws.com/uploadme.txt"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://bregg.s3.amazonaws.com/uploadme.txt

Why is AWS looking for a SSL local issuer cert on my dev laptop?

Many thanks in advance for any help!

This error happens after I hit the upload button on the webpage.

Upvotes: 1

Views: 1923

Answers (1)

engr.ukairo
engr.ukairo

Reputation: 68

cURL is looking for an ssl certificate in your local installation. There are two ways to solve the issue. It depends on the one you prefer.

Option 1

If you are using Laravel, tell your software not to use https when uploading to AWS s3 disk. To do this, head over to config/filesystems.php and add 'scheme' => 'http', in 's3' array. Assuming you have a fresh laravel installation, your new s3 array will now look like below:

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
        'endpoint' => env('AWS_ENDPOINT'),
        'scheme'  => 'http',
    ],

That is all you need to do. Go ahead and upload your file.

Option 2

Download cacert.pem and update your php.ini.

To do this, head over to https://curl.haxx.se/ca/cacert.pem and download the cacert.pem file. Copy the file to your php version folder (on Windows, this might look like C:\wamp64\bin\php\php8.3.0 or wherever you installed your WAMP or Xampp). After that, note the location of the file.

Go to your your php.ini file and search for the line containing curl.cainfo.

Update that line to curl.cainfo = "C:\wamp\bin\php\php7.2.3\cacert.pem".

Go ahead and upload your files.

Note:

The above two methods are just for development purposes only. Option 1 actually disables the need for ssl in your requests to AWS while option 2 does not replace the need for an actual SSL Certificate. While going to production, remember to disable option 1 and get your website secured with an SSL certificate.

Upvotes: 2

Related Questions