termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.65k stars 2.91k forks source link

[Bug]: Apache php-pgsql not work #17779

Open MadMapMaker opened 10 months ago

MadMapMaker commented 10 months ago

Problem description

Hello everyone, I have this problem: I have installed postgresql on termux which works, I have installed apache which works, I have installed the php-pgsql extension which if launched from the terminal (a simple php with a pg_connect) does not give an error, but if it is called from apache it does not work. Furthermore, if I launch php -i from the terminal it tells me that the extension exists, whereas if I launch phpInfo() from Apache it does not see it (see the images). The php.ini file it loads ($PREFIX/lib/php.ini) is apparently the same. What am I doing wrong?

What steps will reproduce the bug?

resultt of php -i

pdo_sqlite

PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.42.0

pgsql

PostgreSQL Support => enabled
PostgreSQL (libpq) Version => 15.3
Multibyte character support => enabled
Active Persistent Links => 0
Active Links => 0
Directive => Local Value => Master Value
pgsql.allow_persistent => On => Onpgsql.auto_reset_persistent => Off => Off
pgsql.ignore_notice => Off => Off
pgsql.log_notice => Off => Off
pgsql.max_links => Unlimited => Unlimited
pgsql.max_persistent => Unlimited => Unlimited

Phar

Phar: PHP Archive support => enabled
Phar API version => 1.1.1
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => enabled
OpenSSL support => enabled

result of phpInfo() in apache via chrome

phpino

What is the expected behavior?

No response

System information

termux-info:

Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=17432
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.sau.edu.cn/termux/apt/termux-main stable main
Updatable packages:
All packages up to date
termux-tools version:
1.39.0
Android version:
11
Kernel build information:
Linux localhost 4.9.227-perf-23850358 #1 SMP PREEMPT Tue Mar 14 15:54:33 KST 2023 aarch64 Android
Device manufacturer:
samsung
Device model:
SM-T295
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
eppesuig commented 10 months ago

Hello, I just reproduced the problem and found the source error message. It is something related to the binary format of shared objects, similar to the one of issue #10129. In fact the error message is:

PHP Startup: Unable to load dynamic library 'pdo_pgsql.so' (tried: /data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so (dlopen failed: empty/missing DT_HASH/DT_GNU_HASH in "/data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so" (new hash type from the future?)), /data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so.so (dlopen failed: library "/data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so.so" not found)) in Unknown on line 0

The same error message appears for extension pgsql.so and pdo_pgsql.so.

According to the previously referred issue, the problem migth be on the toolchain used for building the package, so I tried to compile the php package on the device itself.

Sadly, I found another problem when compiling php. Its configure command fails with error:

[...]
checking if we're at 64-bit platform... yes
checking for iconv support... yes
checking for iconv... yes
checking if iconv is glibc's... no
checking if using GNU libiconv... no
checking if iconv is Konstantin Chuguev's... no
checking if using IBM iconv... no
checking if iconv supports errno... no
configure: error: iconv does not support errno

and this is due to libiconv not being the libc one.

So, how should I proceed now? Is there a version of libc iconv for termux?

Thank you, Giuseppe

eppesuig commented 10 months ago

The complete error message wrote by configure on its config.log is:

configure:44279: checking if iconv supports errno
configure:44309: cc -o conftest  -I/data/data/com.termux/files/home/.termux-build/php/host-build/ext/date/lib -I/data/data/com.termux/files/home/.termux-build/php/src/ext/date/lib -g -O2 -fvisibility=hidden  -D_GNU_SOURCE   conftest.c -lrt -lm  >&5
ld.lld: error: undefined symbol: libiconv_open
>>> referenced by conftest.c:230
>>>               /data/data/com.termux/files/usr/tmp/conftest-7ae90c.o:(main)

ld.lld: error: undefined symbol: libiconv_close
>>> referenced by conftest.c:238
>>>               /data/data/com.termux/files/usr/tmp/conftest-7ae90c.o:(main)
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
configure:44309: $? = 1
configure: program exited with status 1
truboxl commented 10 months ago

You may refer https://github.com/termux/termux-packages/tree/master/packages/php for the full build script (build.sh) and its patches. We use libiconv package as a dependency.

eppesuig commented 10 months ago

Hello @truboxl , you are right. The problem is that libconv on the device toolchain is different than the one on the crossbuilder platform.

On the device it is:

~ $ iconv --version
iconv (GNU libiconv 1.17)
Copyright (C) 2000-2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.

while, on the crosscompiler, it is:

builder@499d206ad7a4:~/termux-packages$ iconv --version
iconv (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

As you see, the second one is from glibc, while the first one is from GNU. And, as explained in a php bug report, the only working iconv for php 8 compiling is the one from glibc.

So, the php package is currently not buildable on the device itself, and the crosscompiled version does not load php extensions when running in apache.

I dont know what could be the simplest solution among:

  1. fixing the upstrem problem and accepting any iconv version
  2. building glibc iconv in termux
  3. finding the source of the original problem, about shared library header

Any sugggestion?

Thank you, Giuseppe

eppesuig commented 10 months ago

I better digged into the problem and found that this errno thing is a red herring.

The real problem is that libiconv is not passed to the linker when compiling any conftest source, and this happens since the include file iconv.h is not correctly found by the configure script. And this lead to all iconv checks fails:

[...]
checking if we're at 64-bit platform... yes
checking for iconv support... yes
checking for iconv... yes
checking if iconv is glibc's... no
checking if using GNU libiconv... no
checking if iconv is Konstantin Chuguev's... no
checking if using IBM iconv... no
checking if iconv supports errno... no
configure: error: iconv does not support errno

I tried to add -liconv to LD_FLAGS in build.sh script, but it did not fixed the problem.

romanovj commented 9 months ago

no need to recompile everything

cd ext/pgsql
#in your case 
#cd ~/.termux-build/php/src/ext/pgsql
phpize
nano ./configure

change PGSQL_SEARCH_PATHS="/usr... to PGSQL_SEARCH_PATHS="/data/data/com.termux/files/usr /data/data/com.termux/files/usr/local /data/data/com.termux/files/usr/local/pgsql"

./configure
make

cp ./libs/pgsql.so /data/data/com.termux/files/usr/lib/php-apache

Do the same for pdo_pgslq

patch libs

cd /data/data/com.termux/files/usr/lib/php-apache
patchelf --add-needed libphp.so pdo_pgsql.so
patchelf --set-rpath $PREFIX/libexec/apache2:$PREFIX/lib pdo_pgsql.so

patchelf --add-needed libphp.so pgsql.so
patchelf --set-rpath $PREFIX/libexec/apache2:$PREFIX/libpgsql.so

Screenshot_20230915-231755_Браузер

romanovj commented 9 months ago

@licy183 something is damaging the libs, probably patching after stripping

PHP Startup: Unable to load dynamic library 'pdo_pgsql.so' (tried: /data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so (dlopen failed: empty/missing DT_HASH/DT_GNU_HASH in "/data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so" (new hash type from the future?)),

and

httpd: Syntax error on line 66 of /data/data/com.termux/files/usr/etc/apache2/httpd.conf: Cannot load /data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so into server: dlopen failed: empty/missing DT_HASH/DT_GNU_HASH in "/data/data/com.termux/files/usr/lib/php-apache/pdo_pgsql.so" (new hash type from the future?)

eppesuig commented 9 months ago

Thank you, @romanovj , the procedure you wrote works perfectly. I only had to find the correct path for patchelf (it was inside the ~/.termux-build tree). Should I now provide information about different header details for the shared object? Would this be intersting for fixing the build process?

romanovj commented 9 months ago

@eppesuig it's standart package

pkg install patchelf

eppesuig commented 9 months ago

Just compiling pgsql extension as suggested works perfectly. Still I am uncertain about this bug report: the crossbuilder corrupts the shared objects.