2

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.

3
  • 1
    Did you try searching for your error? There are several existing answers, have you tried any of them? Updating Composer and PHP to the latest versions seems to be a common suggestion, have you tried at least that? Commented Nov 7 at 8:32
  • @Don'tPanic, yeah... tried updating composer, still doesn't work. Commented Nov 7 at 8:36
  • 1
    You have allow_self_signed setting configured to false, so this will not accept self-signed certificates. Commented Nov 7 at 9:09

1 Answer 1

1

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"
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

For the benefiet of future visitors - what did you change?
It appears that you have removed the ssl part altogether from the composer.json (in order to make it work) ?
I enabled "disable-tls" to true, and implement the "composer config -g cafile "C:/folder_name_example/cacert.pem", "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.