Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Possible Fix] OpenSSL error: Can't install PHP 7.*, 5.* #131

Open
gfreitash opened this issue Jun 30, 2022 · 14 comments
Open

[Possible Fix] OpenSSL error: Can't install PHP 7.*, 5.* #131

gfreitash opened this issue Jun 30, 2022 · 14 comments

Comments

@gfreitash
Copy link

gfreitash commented Jun 30, 2022

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. 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 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 .

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 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.

@brunofunnie
Copy link

brunofunnie commented Jul 4, 2022

Nice tips worked like a charm, thanks.

I made some changes because I rather keep all the installs from asdf inside the asdf directory, but they are completely optional, more like a personal taste.

Firstly

I would change the openssl installation directory, since putting all the installation in a "/bin" suffix quite doesn't make sense, for me at least. So:

  • Before: $HOME/openssl-1.1.1i/bin
  • Then: $HOME/Apps/openssl-1.1.1i
    • I like to organize every piece of manually installed software in a dir called Apps inside my home dir

Secondly

Instead of removing the "install_composer" line I would just comment it and add a new line with:

echo $ASDF_INSTALL_PATH

Last but not least

Then I can take the destination from the last echo command and use it to install composer in the related php directory. Oh and don't forget to change to the php version you've just installed (Added the command below as well)

asdf local php 7.4.30
wget -O ~/Downloads/composer-setup.php https://getcomposer.org/installer
php ~/Downloads/composer-setup.php --install-dir=<path from $ASDF_INSTALL_PATH>/bin --filename=composer
asdf reshim

@DiegoSilva94
Copy link

the problem with composer can be solved by changing the php copy by curl

in the install file, look for the install_composer method and replace the line
$bin_path/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
with this
curl https://getcomposer.org/installer --output composer-setup.php

@ii02735
Copy link

ii02735 commented Feb 8, 2023

@DiegoSilva94 Thank you for your tip ! It helped me 👍
For anyone who has the following problem :

Unable to write keys.dev.pub to: $HOME/.composer

You should do :

mv ~/.composer ~/.composer.old

For a better explanation : https://stackoverflow.com/a/44698089

@99linesofcode
Copy link

99linesofcode commented Feb 16, 2023

Is anyone in a position to submit a PR for this? Or perhaps @smorimoto could take a stab at it so that asdf-php can once again be used to install older versions of PHP?

This is actually a build dependency issue and not necessarily the responsibility of someone working on this plugin to fix. It would probably be a good idea to have a discussion on this to determine to what extend this plugin is responsible for installing build dependencies. Especially in these scenario's where operating systems decide to no longer serve these packages from their repositories.

@cocoonkid
Copy link

Worked like a charm for me on arch linux!

Thanks so much!!!!!!!!!!

@xvladqt
Copy link

xvladqt commented Jun 20, 2023

Have same problem in arch, fix more easy

pacman -S openssl-1.1
export PKG_CONFIG_PATH=/usr/lib/openssl-1.1/pkgconfig

Install success(with composer)

@zastrixarundell
Copy link

Ubuntu 22.04 needed the package: libssl-dev to fix this issue.

@Pablo1Gustavo
Copy link

Pablo1Gustavo commented May 1, 2024

Hi Arch Linux bros, I encountered numerous problems trying to install PHP 7 with asdf. Switching to openssl-1.1 solved a specific error, but then I encountered C compilation errors during the installation. I resolved these by installing some missing libraries:
sudo pacman -S autoconf bison re2c pkg-config libxml2 sqlite zlib curl gd oniguruma postgresql-libs libzip

@danielemegna
Copy link

Also here, problems on Arch Linux with php 7.4 ✋

$ uname -a
Linux daniele-xps 6.6.34-1-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:00:06 UTC 2024 x86_64 GNU/Linux
$ openssl -v
OpenSSL 3.3.1 4 Jun 2024 (Library: OpenSSL 3.3.1 4 Jun 2024)
$ asdf install php 7.4.33
Determining configuration options...
Downloading source code...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 14.2M    0 14.2M    0     0  1972k      0 --:--:--  0:00:07 --:--:-- 2261k
Extracting source code...
Running buildconfig...
buildconf: Checking installation
buildconf: autoconf version 2.72 (ok)
buildconf: Forcing buildconf. The configure files will be regenerated.
buildconf: Cleaning cache and configure files
buildconf: Rebuilding configure
....
....
/usr/include/openssl/rsa.h:294:29: note: expected ‘RSA *’ {aka ‘struct rsa_st *’} but argument is of type ‘const struct rsa_st *’
  294 |                        RSA *rsa, int padding);
      |                        ~~~~~^~~
/tmp/tmp.GLgNeUNHJw/php-src-php-7.4.33/ext/openssl/openssl.c: In function ‘zif_openssl_public_decrypt’:
/tmp/tmp.GLgNeUNHJw/php-src-php-7.4.33/ext/openssl/openssl.c:5957:25: warning: ‘RSA_public_decrypt’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
 5957 |                         cryptedlen = RSA_public_decrypt((int)data_len,
      |                         ^~~~~~~~~~
/usr/include/openssl/rsa.h:299:5: note: declared here
  299 | int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
      |     ^~~~~~~~~~~~~~~~~~
/tmp/tmp.GLgNeUNHJw/php-src-php-7.4.33/ext/openssl/openssl.c:5960:41: warning: ‘EVP_PKEY_get0_RSA’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
 5960 |                                         EVP_PKEY_get0_RSA(pkey),
      |                                         ^~~~~~~~~~~~~~~~~
/usr/include/openssl/evp.h:1356:22: note: declared here
 1356 | const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
      |                      ^~~~~~~~~~~~~~~~~
/tmp/tmp.GLgNeUNHJw/php-src-php-7.4.33/ext/openssl/openssl.c:5960:41: warning: passing argument 4 of ‘RSA_public_decrypt’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 5960 |                                         EVP_PKEY_get0_RSA(pkey),
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/openssl/rsa.h:300:29: note: expected ‘RSA *’ {aka ‘struct rsa_st *’} but argument is of type ‘const struct rsa_st *’
  300 |                        RSA *rsa, int padding);
      |                        ~~~~~^~~
make: *** [Makefile:750: ext/openssl/openssl.lo] Error 1

Still (different) problems also installiing suggested packages, pointing old openssl pgkconfig and installing it again:

$ yay -S openssl-1.1 autoconf bison re2c pkg-config libxml2 sqlite zlib curl gd oniguruma postgresql-libs libzip
$ export PKG_CONFIG_PATH=/usr/lib/openssl-1.1/pkgconfig
$ asdf install php 7.4.33
Determining configuration options...
Downloading source code...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 14.2M    0 14.2M    0     0  1972k      0 --:--:--  0:00:07 --:--:-- 2261k
Extracting source code...
Running buildconfig...
buildconf: Checking installation
buildconf: autoconf version 2.72 (ok)
buildconf: Forcing buildconf. The configure files will be regenerated.
buildconf: Cleaning cache and configure files
buildconf: Rebuilding configure
...
...
/tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c: In function ‘zif_libxml_use_internal_errors’:
/tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c:1032:48: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
 1032 |         if (current_handler && current_handler == php_libxml_structured_error_handler) {
      |                                                ^~
/tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c:1050:49: error: passing argument 2 of ‘xmlSetStructuredErrorFunc’ from incompatible pointer type [-Wincompatible-pointer-types]
 1050 |                 xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler);
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                 |
      |                                                 void (*)(void *, xmlError *) {aka void (*)(void *, struct _xmlError *)}
In file included from /usr/include/libxml2/libxml/valid.h:15,
                 from /usr/include/libxml2/libxml/parser.h:17,
                 from /tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c:34:
/usr/include/libxml2/libxml/xmlerror.h:905:57: note: expected ‘xmlStructuredErrorFunc’ {aka ‘void (*)(void *, const struct _xmlError *)’} but argument is of type ‘void (*)(void *, xmlError *)’ {aka ‘void (*)(void *, struct _xmlError *)’}
  905 |                                  xmlStructuredErrorFunc handler);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c: In function ‘zif_libxml_get_last_error’:
/tmp/tmp.RArXBSXjWm/php-src-php-7.4.33/ext/libxml/libxml.c:1066:15: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 1066 |         error = xmlGetLastError();
      |               ^
make: *** [Makefile:748: ext/libxml/libxml.lo] Error 1
make: *** Waiting for unfinished jobs....

Any ideas ? 😢

@OctopusRage
Copy link

i had same issue like @danielemegna above, any update?

@Pablo1Gustavo
Copy link

test using a slightly older version of libxml2, 2.12 or even 2.9

@danielemegna
Copy link

i had same issue like @danielemegna above, any update?

Not from me. After many tries (lost in C compilation errors) I fell back to docker containers + remote interpreter configuration on IDE (devcontainsers or phpstorm remote docker interpreter).

@piyushchauhan2011
Copy link

piyushchauhan2011 commented Sep 13, 2024

For me this worked well

asdf plugin-add php https://github.com/asdf-community/asdf-php.git

Make sure to update the install file. It is located at $HOME/.asdf/plugins/php/bin

Edit using vim install and where it says local openssl_path=$(homebrew_package_path openssl@1.1) replace with local openssl_path=$(homebrew_package_path openssl@3) newer openssl version

Make sure to install required homebrew packages. You can check them here in other issue #65 (comment). I have to install extra brew package brew install libiconv

You can find the homebrew package list from here also: https://github.com/asdf-community/asdf-php/blob/master/.github/workflows/workflow.yml#L52

Install PHP with some configure options. Not sure why this is the case but I needed postgresql, so I have to add these extra options for pgsql, libiconv and openssl

PHP_CONFIGURE_OPTIONS="--with-pgsql --with-iconv=$(brew --prefix libiconv) --with-openssl=$(brew --prefix openssl)" asdf install php latest

@x-rush
Copy link

x-rush commented Jan 23, 2025

I need a PHP 7.4, and that is useful for me:

wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
tar -xzvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config --prefix=$HOME/build_lib/openssl-1.1.1w --openssldir=$HOME/build_lib/openssl-1.1.1w no-shared
make -j 8 
make install

export PHP_CONFIGURE_OPTIONS="--with-openssl=$HOME/build_lib/openssl-1.1.1w \
--with-curl --with-zlib --with-readline --with-gettext \
--with-jpeg-dir=/usr/lib/x86_64-linux-gnu --with-jpeg \
--with-png-dir=/usr/lib/x86_64-linux-gnu --with-png"
export PKG_CONFIG_PATH=$HOME/build_lib/openssl-1.1.1w/lib/pkgconfig

asdf install php 7.4.33
asdf global php 7.4.33

Then you will end up with PHP version 7.4.33, but there are some issues with composer.
Next 👇

# Download certificate https://curl.se/ca/cacert.pem
wget https://curl.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
echo "openssl.cafile=/usr/local/openssl/ssl/certs/cacert.pem" >> $(asdf where php)/conf.d/php.ini

# repeat the command for the install_composer method.
bin_path=$(asdf where php)/bin
expected_signature=$(curl -sL https://composer.github.io/installer.sig)
$bin_path/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$bin_path/php -r "if (hash_file('sha384', 'composer-setup.php') === '${expected_signature}') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$bin_path/php composer-setup.php --install-dir=$bin_path --filename=composer
$bin_path/php -r "unlink('composer-setup.php');"
$bin_path/composer --version

# since composer was installed manually, you need to refresh the shims.
asdf reshim

That's all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests