phpcomposer-php

Composer issue when trying to install "phpoffice/phpspreadsheet". SSL certificate problem: self-signed certificate in certificate chain


I got this error:

Composer issue when trying to install "phpoffice/phpspreadsheet". SSL certificate problem: self-signed certificate in certificate chain  

When i was trying to install phpoffice/phpspreadsheet using the command

composer require phpoffice/phpspreadsheet

inside my CodeIgniter 4 project.

I then tried to use this command on the CMD because i thought i need an SSL certificate file.

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365

and used the "cert.pem" file on my composer.json like this, but it still doesn't work. The command above created 2 file, which is "cert.pem" and "key.pem".

{
"name": "codeigniter4/framework",
"description": "The CodeIgniter framework v4",
"license": "MIT",
"type": "project",
"homepage": "https://codeigniter.com",
"require": {
    "php": "^8.1",
},
"autoload": {
    "psr-4": {
        "CodeIgniter\\": "system/"
    },
    "exclude-from-classmap": [
        "**/Database/Migrations/**"
    ]
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true,
    "disable-tls": true,
    "secure-http": false,
    "options": {
        "ssl": {
            "verify_peer": false,
            "allow_self_signed": false,
            "cafile": "C:/key_for_composer/cert.pem",
            "local_cert": "C:/key_for_composer/cert.pem"
        }
    }
},
"scripts": {
    "test": "phpunit"
}

}

Doesn't work. I also tried this command:

composer config -g cafile "C:/key_for_composer/cacert.pem", 

i got the file cacert.pem from "https://curl.se/docs/caextract.html".

Still doesn't work.

Please help me with this issue. My Composer knowledge is quite lacking.


Solution

  • After doing the above (post's content) and then modifying the composer.json to this one, it seems to work now. Anyway, hope this helps others that experience this issue.

    {
        "name": "codeigniter4/framework",
        "description": "The CodeIgniter framework v4",
        "license": "MIT",
        "type": "project",
        "homepage": "https://codeigniter.com",
        "support": {
            "forum": "https://forum.codeigniter.com/",
            "source": "https://github.com/codeigniter4/CodeIgniter4",
            "slack": "https://codeigniterchat.slack.com"
        },
        "require": {
            "php": "^8.1",
            "ext-intl": "*",
            "ext-mbstring": "*",
            "guzzlehttp/guzzle": "^7.0",
            "laminas/laminas-escaper": "^2.17",
            "phpoffice/phpspreadsheet": "^5.2",
            "psr/log": "^3.0"
        },
        "require-dev": {
            "codeigniter/coding-standard": "^1.7",
            "fakerphp/faker": "^1.24",
            "friendsofphp/php-cs-fixer": "^3.47.1",
            "kint-php/kint": "^6.0",
            "mikey179/vfsstream": "^1.6.12",
            "nexusphp/cs-config": "^3.6",
            "phpunit/phpunit": "^10.5.16 || ^11.2",
            "predis/predis": "^3.0",
            "phpoffice/phpspreadsheet" : "^5.2"
        },
        "suggest": {
            "ext-curl": "If you use CURLRequest class",
            "ext-dom": "If you use TestResponse",
            "ext-exif": "If you run Image class tests",
            "ext-fileinfo": "Improves mime type detection for files",
            "ext-gd": "If you use Image class GDHandler",
            "ext-imagick": "If you use Image class ImageMagickHandler",
            "ext-libxml": "If you use TestResponse",
            "ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
            "ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
            "ext-mysqli": "If you use MySQL",
            "ext-oci8": "If you use Oracle Database",
            "ext-pgsql": "If you use PostgreSQL",
            "ext-readline": "Improves CLI::input() usability",
            "ext-redis": "If you use Cache class RedisHandler",
            "ext-simplexml": "If you format XML",
            "ext-sodium": "If you use Encryption SodiumHandler",
            "ext-sqlite3": "If you use SQLite3",
            "ext-sqlsrv": "If you use SQL Server",
            "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()"
        },
        "autoload": {
            "psr-4": {
                "CodeIgniter\\": "system/"
            },
            "exclude-from-classmap": [
                "**/Database/Migrations/**"
            ]
        },
        "config": {
            "optimize-autoloader": true,
            "preferred-install": "dist",
            "sort-packages": true,
            "disable-tls": false,
            "secure-http": false
        },
        "scripts": {
            "test": "phpunit"
        }
    }