asdf-community / asdf-community/asdf-php
[Possible Fix] OpenSSL error: Can't install PHP 7.*, 5.*
- Dominant language
- Shell
- Stars
- 256
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
### Summary
It seems that many people are struggling to install older versions of PHP since OpenSSL is now on version 3. And so was I. After some digging I found this (possible) fix to issues like #129, #127, #125 and so on.
This same issue also happens with PHPBrew, and they have a fix for it, as you can see [here](https://github.com/phpbrew/phpbrew/issues/1263#issuecomment-1140375871). To adapt this fix for asdf is not really that hard. The fix involves compiling OpenSSL 1.1 (for php 7.4) from source and then using this locally compiled OpenSSL to execute the asdf php installation.
### Fix
#### First
you should download and compile the OpenSSL's source. For php 7 this should be exactly the same as described in the phpbrew issue, where this fix is from (see below).
```
cd $HOME
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xzf $HOME/openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./Configure --prefix=$HOME/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
make -j 8
make install
```
However, if I'm not wrong, there are at least some version of php 5 that require openssl 1.0.2 to compile properly. In [OpenSSL website ](https://www.openssl.org/source/) you can see that versions below and including 1.0.2 are out of support and their usage is discouraged. Nevertheless, you can still get them from [here ](https://www.openssl.org/source/old/).
#### Next
you use the fresh compiled openssl to compile php with asdf
`export PKG_CONFIG_PATH=$HOME/openssl-1.1.1i/bin/lib/pkgconfig && asdf install php 7.4.30`
#### After that
you may or may not have another error when installing composer. It look something like:
```
PHP Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in Command line code on line 1
PHP Warning: copy(): Failed to enable crypto in Command line code on line 1
PHP Warning: copy(https://install.phpcomposer.com/installer): failed to open stream: operation failed in Command line code on line 1
```
There is a [fix ](https://stdworkflow.com/929/installing-composer-prompts-php-warning-copy-ssl-operation-failed-with-code-1-openssl-error-messages)that involves downloading and applying some certificate. Though it didn't work for me, it might work for you:
##### Download certificate
```
# Download certificate http://curl.haxx.se/ca/cacert.pem
wget http://curl.haxx.se/ca/cacert.pem
# Or use the web page to download and upload to linux
mkdir -p /usr/local/openssl/ssl/certs/
mv cacert.pem /usr/local/openssl/ssl/certs/cacert.pem
```
##### Modify php.ini
```
;openssl.capath=
openssl.cafile=/usr/local/openssl/ssl/certs/cacert.pem
```
**_What worked for me:_**
I went into `~/.asdf/plugins/php/bin` and removed the last line in `install`:
`install_composer "$ASDF_INSTALL_PATH"`
Then, after the installation with `export PKG_CONFIG_PATH=$HOME/openssl-1.1.1i/bin/lib/pkgconfig && asdf install php 7.4.30` I manually installed composer globally with
```
wget -O composer-setup.php https://getcomposer.org/installer
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
```
### In the end
I hope that this can help you to get asdf-php back to its normal functioning.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in ~/.asdf/plugins/php/bin/install, especially the install_composer "$ASDF_INSTALL_PATH" entry, and reproduce `asdf install php 7.4.30` with OpenSSL 3. Compare the PHPBrew workaround linked in the issue and verify that older PHP versions install successfully without manually removing Composer installation or configuring certificates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, shell
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100