Home > LAMP, Web Development > PHP 5.6 and Self Signed Certificates for Soap, file_get_contents

PHP 5.6 and Self Signed Certificates for Soap, file_get_contents

Operating System: CentOS 7
PHP: 5.6

This is only for local machine and local development – use at your own risk

I a using a self signed SSL certificate on my local development machine and many functions in PHP refuse to work with self signed certificates.
Some of the functions are

  • file_get_contents()
  • fopen()
  • SoapClient()

my domain name for local machine: localhost
my Self Signed SSL certificate in PEM format: localhost.crt

If i use any of these functions to access a HTTPS resource, the calls fail with invalid certificate
eg file_get_contentc(“https://localhost/test.csv”); will fail

the easiest method is to force add your self signed certificate to the trusted ca-authority in the operating system and openssl

# this should already be installed if you have openssl installed
yum -y install ca-certificates

# copy your self signed cert to the /etc/pki/ca-trust/source/anchors - change certificate path as necessary
cp /etc/pki/tls/certs/localhost.crt /etc/pki/ca-trust/source/anchors

# update
sudo update-ca-trust

now SoapClient, file_get_contents and fopen should work without problems

Other way to do it is to manually send in the stream_context to each of the calls like here


  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: