Skip to content

PHP Installation fails on Ubuntu 22.04 WSL2 #1280

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

Closed
7ahery opened this issue Dec 11, 2022 · 7 comments
Closed

PHP Installation fails on Ubuntu 22.04 WSL2 #1280

7ahery opened this issue Dec 11, 2022 · 7 comments
Assignees

Comments

@7ahery
Copy link

7ahery commented Dec 11, 2022

Error 🔴

Running phpbrew on Ubuntu 22.04 WSL2, when I try to install any PHP version lower than 8.0 I get various errors related to OpenSSL. My take is that this is most likely related to OpenSSL 3 being the default in Ubuntu 22.04 but lower PHP versions need OpenSSL 1.1.1 to build.

Here are the errors:

Error: Configure failed:
The last 5 lines in the log file:
checking for Kerberos support... no

checking whether to use system default cipher list instead of hardcoded value... no

checking for RAND_egd... no

checking for pkg-config... /usr/bin/pkg-config

configure: error: Cannot find OpenSSL's libraries
Error: Make failed:
/usr/include/openssl/rsa.h:289:29: note: expected ‘RSA *’ {aka ‘struct rsa_st *’} but argument is of type ‘const struct rsa_st *’

  289 |                        RSA *rsa, int padding);

      |                        ~~~~~^~~

make: *** [Makefile:631: ext/openssl/openssl.lo] Error 1

Solution (Partial - Please read this comment)

Use At Your Own Risk

This was the only way I was able to fix these errors.

  1. Remove current (version 3) OpenSSL: sudo apt remove openssl
  2. Download OpenSSL 1.1.1 source, extract the .tar.gz file and build/install OpenSSL:
    1. cd to OpenSSL source folder.
    2. make config file executable: chmod +x config
    3. run config: ./config
    4. build the source: make
    5. run tests to make sure the built source is OK: make test
    6. install the built OpenSSL: sudo make install
  3. Now install your PHP version with the following command: phpbrew install 7.0 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl which essentially tells the installed PHP version to use the OpenSSL path you provide.

! Important Note ! You can not have two versions of OpenSSL activated simultaneously. With this approach you are eliminating OpenSSL 3 lib from Ubuntu 22.04 so please make sure you know what you are doing.

To uninstall OpenSSL 1.1.1, cd to OpenSSL source folder and run sudo make uninstall.
To install back OpenSSL 3, first remove OpenSSL 1.1.1 and then run: sudo apt install openssl.

Note: When installing PHP 5.6 you may face a curl error easy.h should be in <curl-dir>/include/curl/. In that case please check out this answer.

@theofidry
Copy link
Contributor

@7ahery on OSX with homebrew (and I think you could have the same with Ubuntu), you can also build with +openssl=<path-to-openssl1.1>

@7ahery
Copy link
Author

7ahery commented Dec 11, 2022

@theofidry The issue is that when I build with +openssl=/usr/include/openssl I get:

configure: error: Cannot find OpenSSL's <evp.h>

But evp.h is available at /usr/include/openssl, don't know why this happens.

@theofidry
Copy link
Contributor

@7ahery I think that's because you specific the include directory of the OpenSSL installation. When I do $brew --prefix openssl@1.1, it points to the directory containing bin, include, lib, share & co.

@7ahery
Copy link
Author

7ahery commented Dec 11, 2022

@theofidry I think the same can not be said for Ubuntu as OpenSSL bin, include, lib etc. are in different folders in /usr/local. I think this is a phpbrew incompatibility with Linux.

Even when I build and install OpenSSL 1.1.1 manually in a single folder, with bin, include, lib etc. available in one folder, I get configure: error: Cannot find OpenSSL's libraries error and if I point it to lib folder it will throw error configure: error: Cannot find OpenSSL's <evp.h>

@7ahery
Copy link
Author

7ahery commented Dec 11, 2022

I just found out that although you are able to install PHP<8.0 with the solution I provided above, Only PHP 7.4 will correctly recognize OpenSSL and work, anything lower will throw an error indicating OpenSSL Extension is not installed. This error will be obvious when for example you run a composer install command.

So this is not completely and reliably solved on Ubuntu 22.04. We need a way to retain Ubuntu 22.04 default OpenSSL but be able to install PHP versions lower than 8.0.

@7ahery 7ahery changed the title PHP Installation fails on Ubuntu 22.04 WSL2 [SOLVED] PHP Installation fails on Ubuntu 22.04 WSL2 Dec 11, 2022
@7ahery
Copy link
Author

7ahery commented Dec 11, 2022

I can confirm that phpbrew can install any PHP version>=5.6 without any issue on Ubuntu 20.04. So this is definitely an issue related to Ubuntu 22.04.

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

No branches or pull requests

3 participants