Jump to content

PHP composer errors, openssl issue . Cannot install phpspreadsheet. Ubuntu20.04


Recommended Posts

Trying to use composer to install phpspreadsheet on a php project I am working on for a client. Since phpspreadsheet requires php >= 7.2 I installed multiple versions of php (5.6, 7.1,2,3,4, 8.0) on my Linux drive (ubuntu 20.04.2 LTS focal).
I uninstalled an Ampps server because it only had php7.1. Apache2 was already installed. I installed mysql-server 8.0 after some difficulties (until I purged the ampps installation), and configured the server myself. It serves a website using a database with minor problems related to the old PHPExcel module.

Composer did install globally, and I did initialize a basic composer.json in my webroot directory. A ```/vendor``` dir was created containing a ```/composer``` dir, but no phpspreadsheet folder, and many errors detailed below.

My most recent composer.json file is shown at the bottom of this post for reference.

If I run ```$ composer diagnose``` from the web root dir in the terminal I got the following error:
```
[Composer\Exception\NoSslException]                                                                        
The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable
this error, at your own risk, by setting the 'disable-tls' option to true.
```
Attempts to run ```$ composer update``` or ```upgrade``` stall with the same error.

When, as suggested, I configure composer to run without SSL/TLS using ```$ composer config -g -- disable-tls true``` I get the following, in full technicolor, lots of red 🙂 :
```
You are running Composer with SSL/TLS protection disabled.
Checking composer.json: OK
Checking platform settings: FAIL

The openssl extension is missing, which means that secure HTTPS transfers
are impossible.
If possible you should enable it or recompile php with --with-openssl

The zlib extension is not loaded, this can slow down Composer a lot.
If possible, enable it or recompile php with --with-zlib

A php.ini file does not exist. You will have to create one.
If you can not modify the ini file, you can also run `php -d option=value`
to modify ini values on the fly. You can use -d multiple times.

Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "https://repo.packagist.org
/packages.json" file could not be downloaded: Unable to find the wrapper
"https" - did you forget to enable it when you configured PHP?
failed to open stream: No such file or directory

Composer is configured to disable SSL/TLS protection. This will leave
remote HTTPS requests vulnerable to Man-In-The-Middle attacks.
Checking github.com rate limit: FAIL
[Composer\Downloader\TransportException] The "https://api.github.com
/rate_limit" file could not be downloaded: Unable to find the wrapper
"https" - did you forget to enable it when you configured PHP?
failed to open stream: No such file or directory

Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: <I removed the public keys here and below>
Dev Public Key Fingerprint:
OK
Checking composer version: Warning: Accessing getcomposer.org over http which is an insecure protocol.
OK

Composer version: 2.0.14
PHP version: 7.4.16
PHP binary path: /usr/local/bin/php

OpenSSL version: missing
cURL version: missing, using php streams fallback, which reduces performance
zip: extension not loaded, unzip present
```

To answer some of the points in the errors:
1. Openssl IS installed, using snaps, in non standard locations. From the browser the php function ```loaded_extension('openssl')``` returns true. Based on advice from https://www.php.net/manual/en/imap.requirements.php I made a symlink from where I found the openssl file as:
```$ ln -s /usr/bin/openssl /usr/local/ssl``` and similarly ```$ ln -s /usr/local/ssl/include /usr/include/openssl```.

2. Based on advice from Luke Welling's books I installed JPEG, PNG, IMAP and zlib libraries.

3. To address the php.ini "missing" issue, from the terminal I got:
```
john@john-desktop:~$ php7.4 -i | grep -i openssl
Warning: PHP Startup: Unable to load dynamic library 'openssl' (tried:
/usr/lib/php/20190902/openssl (/usr/lib/php/20190902/openssl: cannot open
 shared object file: No such file or directory), /usr/lib/php/20190902
/openssl.so (/usr/lib/php/20190902/openssl.so: cannot open shared object
file: No such file or directory)) in Unknown on line 0

SSL Version => OpenSSL/1.1.1f
libSSH Version => libssh/0.9.3/openssl/zlib
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1f  31 Mar 2020
OpenSSL Header Version => OpenSSL 1.1.1f  31 Mar 2020
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => no value => no value
openssl.capath => no value => no value
Native OpenSSL support => enabled
```
Perhaps my symlinks are wrong? Some configuration seems wrong but I am not sure how to fix it.

I do have php.ini files. For php7.4 the main one that phpinfo() shows is loading (in the browser) is in ```/etc/php/7.4/fpm/```. I have left this unaltered but added a ```phpcustomjl.ini``` file (with priority 01) in ```/etc/php/7.4/mods-enabled/``` which is symlinked by the system from ```/etc/php/7.4/fpm/conf.d/```. It shows up in phpinfo() from the browser among the Additional .ini files parsed. I learned to use ```$ sudo systemctl restart php7.4-fpm``` after making changes to it, so that these changes take effect. The relevant lines from the .ini file are:
```
extension=zlib
;extension=/usr/lib/ssl
;extension=/usr/bin/openssl
extension=openssl
;extension=php_openssl
```

```$ php7.4 --ini``` shows that this file is loaded in the cli. It outputs:
```
Warning: PHP Startup: Unable to load dynamic library 'openssl' (tried: /usr/lib/php/20190902/openssl (/usr/lib/php/20190902/openssl: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/openssl.so (/usr/lib/php/20190902/openssl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Warning: Module 'curl' already loaded in Unknown on line 0
Configuration File (php.ini) Path: /etc/php/7.4/cli
Loaded Configuration File:         /etc/php/7.4/cli/php.ini
Scan for additional .ini files in: /etc/php/7.4/cli/conf.d
Additional .ini files parsed:      /etc/php/7.4/cli/conf.d/01-phpcustomjl.ini,
```
This shows that the custom ini file is being read from the cli, so some setting in it must be faulty perhaps?


4. When I run ```$ php -v``` in the terminal I get ```PHP 7.4.16 (cli)```. In the browser when I want to enable php7.4 (as it is currently) I use a ```.htaccess``` file in the web root, with ```SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"``` in a <FilesMatch> directive.

**Possible Approaches**

A. Should I recompile php7.4 --with-openssl, or --with-zlib.

B. Should I uninstall openssl snap installs, then reinstall using apt, possibly specifying the location with --withopenssldir or similar?

C. In my php.ini or the phpcustomjl.ini should I point to some openssl file or dir, as there is no openssl.so file on my system. (There was in the Ampps server which I uninstalled as I could not upgrade php beyond 7.1 on it).

D. Should I give up on setting up my own LAMP dev server and just get an all-in-one LAMP server instead? Is there one that will allow me to install php7.4 and later 8.0? Xamp works on linux but has MariaDB instead of MySQL, which is different to the remote server.

I hope I have enough details for someone to figure out the problem, or suggest any strategies. Until then I am stuck!  Any help or ideas you can offer would be greatly appreciated. 🙂

John

 

 

My most recent composer.json file:
```
{
    "name": "john/t.cga.it8",
    "description": "cga website",
    "type": "project",
    "license": "proprietary",
    "authors": [
        {
            "name": "John Loughran",
            "email": "example@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {}
}
```

Link to comment
Share on other sites

Dear requinix,

Thanks for your reply. In the end I have solved the problem. I have so many separate installations of php installed that composer did not know in which one to look for openssl or for php.ini.

The output way below shows that from the CLI the php command was looking in a dir where no php.ini file existed (/usr/local/lib), while the php7.4 command looked in the right place.

I did uninstall and reinstall openssl and composer and was about to start on php when I tried the commands below.

Now I am able to use composer properly with no errors from my project dir simply by typing

project-dir$ php7.4 /home/john/bin/composer update

instead of

project-dir$ composer update

Thanks again for your help. One major headache over!  🙂
 

 

john@john-desktop:~$ php -i | grep -w ini

Configuration File (php.ini) Path => /usr/local/lib

Scan this dir for additional .ini files => (none)

Additional .ini files parsed => (none)

user_ini.filename => .user.ini => .user.ini

 

john@john-desktop:~$ php7.4 -i | grep -w ini

Configuration File (php.ini) Path => /etc/php/7.4/cli

Loaded Configuration File => /etc/php/7.4/cli/php.ini

Scan this dir for additional .ini files => /etc/php/7.4/cli/conf.d

Additional .ini files parsed => /etc/php/7.4/cli/conf.d/01-phpcustomjl.ini,

/etc/php/7.4/cli/conf.d/10-mysqlnd.ini,

…./php/7.4/cli/conf.d/20-zip.ini

user_ini.filename => .user.ini => .user.ini

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.