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

[Bug]: Apache2: PHP: Cannot load extensions without being in LD_PRELOAD #13256

Closed
annpocoyo opened this issue Nov 19, 2022 · 8 comments · Fixed by #13771
Closed

[Bug]: Apache2: PHP: Cannot load extensions without being in LD_PRELOAD #13256

annpocoyo opened this issue Nov 19, 2022 · 8 comments · Fixed by #13771
Labels
bug report Something is not working properly system-level bug Bug is hidden somewhere in OS and can't be fixed

Comments

@annpocoyo
Copy link

annpocoyo commented Nov 19, 2022

Problem description

PHP cannot load extensions in php.ini, but only on Apache2, CLI works fine.
Linked to #5482 and #2479

What steps will reproduce the bug?

  1. Clean install Apache.
  2. Clean install PHP and php-apache extension
  3. Load PHP in Apache
  4. Load PHP extension in $PREFIX/lib/php.ini
  5. Start Apache

What is the expected behavior?

PHP extension loads successfully in both Apache and CLI

System information

termux-info:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=14825
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.scau.edu.cn/termux/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://mirrors.scau.edu.cn/termux/apt/termux-x11 x11 main
Updatable packages:
clang/stable 15.0.5 aarch64 [upgradable from: 15.0.4]
krb5/stable 1.20.1 aarch64 [upgradable from: 1.20-2]
libcompiler-rt/stable 15.0.5 aarch64 [upgradable from: 15.0.4]
libedit/stable 20221030-3.1-0 aarch64 [upgradable from: 20210910-3.1-0]
libllvm/stable 15.0.5 aarch64 [upgradable from: 15.0.4]
lld/stable 15.0.5 aarch64 [upgradable from: 15.0.4]
llvm/stable 15.0.5 aarch64 [upgradable from: 15.0.4]
nano/stable 7.0 aarch64 [upgradable from: 6.3]
termux-tools version:
1.31.1
Android version:
11
Kernel build information:
Linux localhost 4.19.157-perf+ #1 SMP PREEMPT Mon Aug 29 03:28:19 CDT 2022 aarch64 Android
Device manufacturer:
motorola
Device model:
moto g(9) play

Relevant portion of Apache error log:

[Sat Nov 19 10:43:13.695324 2022] [mpm_prefork:notice] [pid 30614] AH00169: caught SIGTERM, shutting down
PHP Warning:  Failed loading Zend extension 'opcache' (tried: /data/data/com.termux/files/usr/lib/php/opcache (dlopen failed: library "/data/data/com.termux/files/usr/lib/php/opcache" not found), /data/data/com.termux/files/usr/lib/php/opcache.so (dlopen failed: cannot locate symbol "zend_signal_globals" referenced by "/data/data/com.termux/files/usr/lib/php/opcache.so"...)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'imagick' (tried: /data/data/com.termux/files/usr/lib/php/imagick (dlopen failed: library "/data/data/com.termux/files/usr/lib/php/imagick" not found), /data/data/com.termux/files/usr/lib/php/imagick.so (dlopen failed: cannot locate symbol "core_globals" referenced by "/data/data/com.termux/files/usr/lib/php/imagick.so"...)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'redis' (tried: /data/data/com.termux/files/usr/lib/php/redis (dlopen failed: library "/data/data/com.termux/files/usr/lib/php/redis" not found), /data/data/com.termux/files/usr/lib/php/redis.so (dlopen failed: cannot locate symbol "compiler_globals" referenced by "/data/data/com.termux/files/usr/lib/php/redis.so"...)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /data/data/com.termux/files/usr/lib/php/sodium (dlopen failed: library "/data/data/com.termux/files/usr/lib/php/sodium" not found), /data/data/com.termux/files/usr/lib/php/sodium.so (dlopen failed: cannot locate symbol "zend_ce_exception" referenced by "/data/data/com.termux/files/usr/lib/php/sodium.so"...)) in Unknown on line 0
[Sat Nov 19 10:43:14.070410 2022] [mpm_prefork:notice] [pid 5457] AH00163: Apache/2.4.54 (Unix) PHP/8.1.12 OpenSSL/3.0.7 configured -- resuming normal operations
[Sat Nov 19 10:43:14.070503 2022] [core:notice] [pid 5457] AH00094: Command line: 'httpd -D NO_DETACH'
@annpocoyo annpocoyo added the bug report Something is not working properly label Nov 19, 2022
@xtkoba
Copy link
Contributor

xtkoba commented Nov 19, 2022

Due to notorious android/ndk#201. Similar to #2674 for Node.js.

[EDIT] Not exactly. [EDIT] Not sure but this seems to be the case.

@xtkoba xtkoba added the system-level bug Bug is hidden somewhere in OS and can't be fixed label Nov 25, 2022
@xtkoba
Copy link
Contributor

xtkoba commented Nov 25, 2022

It is quite non-trivial to fix this because these "undefined" symbols are defined either by $PREFIX/bin/php (in CLI) or $PREFIX/libexec/apache2/libphp.so (in Apache). This cannot be fixed unless there is a way to concentrate these symbols in only one shared object (say $PREFIX/lib/libphp.so).

[EDIT] In case if the wording was ambiguous, I meant only one shared object should define each of these symbols.

@annpocoyo
Copy link
Author

I know this is hard to fix because I myself have tried using patchelf to fix this but ended up braking either cli or apache, in the end I stocked with apache because I never use cli, but I still want to see if we can fix this.

@annpocoyo
Copy link
Author

The workaround specified of setting LD_PRELOAD to lib php.so brakes some things (Most notably running commands and DNS resolving for web requests.). This does not work for me so this issue will not be closed.

@xtkoba
Copy link
Contributor

xtkoba commented Dec 10, 2022

An easy workaround is to build these extensions without specifying shared. The only drawback is that this pulls in more dependencies than needed for some users. But this won't work for opcache as it is not a normal extension.

Another workaround is to build (or prepare for) two types of shared libraries, one is for CLI and the other is for Apache. The only major issue for this is where to place these shared libraries. Maybe $PREFIX/usr/lib/php-apache or something for Apache (as opposed to $PREFIX/usr/lib/php for CLI). Can Apache be made to aware of the new place for extensions?

@xtkoba
Copy link
Contributor

xtkoba commented Dec 10, 2022

For the latter, $PREFIX/lib/php seems to be hardcoded in $PREFIX/libexec/apache2/libphp.so, probably through EXTENSION_DIR:

export EXTENSION_DIR=$TERMUX_PREFIX/lib/php

A possible workaround for this is to build php-apache as a separate package, not as a subpackage of php. The drawback is a slight increase of maintainability maintenance costs, but probably we can tolerate it.

Another workaround is to hack the code base so that CLI and Apache can use different EXTENSION_DIR. Personally I prefer this because it is technically more interesting.

@annpocoyo
Copy link
Author

These solutions would close this issue. Thank you.

xtkoba added a commit that referenced this issue Dec 12, 2022
Extensions for PHP/Apache are packaged under the name of `php-apache-*`
and are installed under the directory `$PREFIX/lib/php-apache/`.

(Extensions under `$PREFIX/lib/php/` will not work with PHP/Apache.)

See also #13256.
termux-pacman-bot added a commit to termux-pacman/termux-packages that referenced this issue Dec 12, 2022
Extensions for PHP/Apache are packaged under the name of `php-apache-*`
and are installed under the directory `$PREFIX/lib/php-apache/`.

(Extensions under `$PREFIX/lib/php/` will not work with PHP/Apache.)

See also termux/termux-packages#13256.
@xtkoba
Copy link
Contributor

xtkoba commented Dec 12, 2022

If you encounter any problem with php (>= 8.2.0) or its subpackages php-*, then please open a new issue for that, instead of reusing this issue. Thanks.

@termux termux locked as resolved and limited conversation to collaborators Dec 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug report Something is not working properly system-level bug Bug is hidden somewhere in OS and can't be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants