composer problems and SSL errors: OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed Failed to enable crypto

After having some hard time installing some packages with composer, i decided to give back some simple solutions for all of you.

First of all suppose you operate in a shared hosting environment where you are not able to mess with the openssl CA root certificates and change the paths.
So you can simply download locally (e.g. /home/kmak) this https://curl.haxx.se/ca/cacert.pem

After you install locally composer.phar you can create your composer.json by requiring your package:

e.g.

 php composer.phar require slim/slim

Then edit composer.json and add the following config section, so finally your composer.json will look like this:

{
    "config": {
        "cafile":"/home/kmak/cacert.pem"
    },
    "require": {
        "slim/slim": "^3.3"
    }
}

Now you can proceed like this:

 php composer.phar install

UPDATE:
If you encouter further SSL certificate errors due to git attempting to clone some project, then you can do this:

 git config --global http.sslCAInfo /home/kmak/cacert.pem

Until some time ago i was suggesting in this post to turn off git SSL certificate verifycation by setting the following environment variable:

 GIT_SSL_NO_VERIFY=TRUE php composer.phar install

This is really bad practise and your should remember that disabling SSL certificate verification is a major security issue and should be avoided.

Cheers.