使用MAMP+PHP上传文件至AWS S3遇cURL错误60(SSL证书问题)
Hey there, let's work through this SSL certificate problem you're hitting when trying to upload files to AWS S3 using MAMP. I've dealt with this exact issue a few times, so here are actionable steps to get it sorted:
1. Double-Check You're Editing the Right php.ini File
MAMP has multiple php.ini files (one for Apache, one for CLI), and it's easy to modify the wrong one. To confirm which file your Apache instance is using:
- Create a simple PHP file in your htdocs folder with:
<?php phpinfo(); ?> - Run it in your browser, look for the Loaded Configuration File line. This is the exact
php.iniyou need to edit. Make sure yourcurl.cainfosetting is added here.
2. Verify Your cacert.pem File is Valid
Sometimes the downloaded certificate file gets corrupted or truncated. Open C:\MAMP\bin\php\php7.2.10\extras\ssl\cacert.pem in a text editor—you should see a long list of SSL certificates (each starting with -----BEGIN CERTIFICATE----- and ending with -----END CERTIFICATE-----). If it's empty or looks incomplete, re-download the latest version of the certificate bundle.
3. Fix File Permissions for cacert.pem
MAMP's Apache process might not have permission to read the certificate file:
- On Windows: Right-click the
cacert.pemfile → Properties → Security → Add "Everyone" with Read permissions. - On Mac: Open Terminal, navigate to the ssl folder, and run
chmod 644 cacert.pemto give read access to all users.
4. Force the AWS SDK to Use the Certificate
If the php.ini change still isn't taking effect, you can directly specify the certificate path in your S3 client initialization. Update your code like this:
use Aws\S3\Exception\S3Exception; // Don't forget to add this use statement! // Connect to AWS try { $s3 = Aws\S3\S3Client::factory( array( 'credentials' => array( 'key' => $IAM_KEY, 'secret' => $IAM_SECRET ), 'version' => 'latest', 'region' => 'eu-west-2', 'http' => array( 'verify' => 'C:\MAMP\bin\php\php7.2.10\extras\ssl\cacert.pem' ) ) ); } catch (Exception $e) { die("Error: " . $e->getMessage()); }
This bypasses the system-level PHP config and tells the AWS SDK exactly where to find the valid certificate.
5. Restart MAMP Apache
After making any changes to php.ini or file permissions, always restart MAMP's Apache server. Config changes won't apply until the server is reloaded.
Quick Side Note
You might also want to fix the exception handling in your code: you're catching S3Exception but haven't imported the class, which will throw an error if the exception is triggered. Adding the use Aws\S3\Exception\S3Exception; line (as shown above) will fix that.
内容的提问来源于stack exchange,提问作者Hamzah Amer

