• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / MAMP PHP cURL and SSL

MAMP PHP cURL and SSL

I currently develop PHP based websites on a Mac using MAMP. When testing the Interspire Email Marketer API on a local version of a site posting data through to an https:// URL with cURL, I discovered that the version of cURL on MAMP has some issues with certs and SSL.

Original code

My original code posted some XML through to an https URL like so:

$ch = curl_init('https://www.example.com/example-api.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result = @curl_exec($ch);

The post was failing and all that was being returned into $result was false. Running this line of code after the above:

echo '<pre>', curl_error($ch);

produced this error message:

SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

My solution

I found a forum on the MAMP website which had a whole bunch of instructions about getting updated certificate files and so on, but the simplest solution was to simply not check the cert. I don’t need to have it checked because it’s a site I trust (being one of my own partner sites).

To disable the SSL checking add this line:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

The revised piece of code in its entirety now looks like this:

$ch = curl_init(IEM_APIURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = @curl_exec($ch);

Check Out These Related posts:

  1. PHP class for using the Google Analytics API
  2. Apache – Permission denied: Failed to acquire SSL session cache lock
  3. Submitting a form post with PHP and CURL
  4. PHP CURL and Cookies

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap