termux / termux-packages

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

[Bug]: php gd error #21262

Open Baturax opened 2 weeks ago

Baturax commented 2 weeks ago

Problem description

İ installed php and phpgd and when i run next cloud it says gd not installed İ still can use an old version of nextcloud with php7.

What steps will reproduce the bug?

Running php

What is the expected behavior?

Working well like php7

System information

Termux Variables:
TERMUX_APK_RELEASE=GITHUB
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=8747
TERMUX_IS_DEBUGGABLE_BUILD=1
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://grimler.se/termux/termux-main stable main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
All packages up to date
termux-tools version:                                                                                                                                                                                                       1.43.4
Android version:
14                                                                                                                                                                                                                          Kernel build information:
Linux localhost 4.14.350-Cryo/deca56cd #3 SMP PREEMPT Fri Aug 9 17:41:41 BST 2024 aarch64 Android                                                                                                                           Device manufacturer:
Xiaomi
Device model:                                                                                                                                                                                                               Redmi Note 8
LD Variables:                                                                                                                                                                                                               LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.boot versionCode:1000
Biswa96 commented 2 weeks ago

Could you provide any simple minimal steps to reproduce the issue? Answering my own question: php -m lists all the modules.

Baturax commented 2 weeks ago

Could you provide any simple minimal steps to reproduce the issue? Answering my own question: php -m lists all the modules.

p~ $ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dom exif FFI fileinfo filter gmp hash iconv intl json libxml mbstring mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar posix random readline Reflection session SimpleXML sockets SPL sqlite3 standard tidy tokenizer xml xmlreader xmlwriter xsl zip zlib

Baturax commented 2 weeks ago

any idea?

freebrowser1 commented 2 weeks ago

Same issue here. I had nextcloud working and now it does not work anymore. Other apps using gd don't work anymore. And php -m does not list gd as well. apt list --installed | grep php does list gd however.

Nothing 2a:.../usr/lib$ apt list --installed | grep php

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

php-apache/stable,now 8.3.10 aarch64 [installed]
php-gd/stable,now 8.3.10 aarch64 [installed]
php/stable,now 8.3.10 aarch64 [installed]
fornwall commented 2 weeks ago

I think that after https://github.com/termux/termux-packages/pull/21072 the gd extension needs to be enabled explicitly by specifying extension=gd in $PREFIX/lib/php.ini (that file needs to be created if it does not exist).

After doing that, php -m shows the gd module, and some example php scripts using gd works.

Don't know much about how php is normally packaged, but having a peek at how it works in ubuntu we should probably setup so that php automatically loads a gd.ini file (or similar) with extension=gd.so once the php-gd package is installed.

Biswa96 commented 2 weeks ago

the gd extension needs to be enabled explicitly by specifying extension=gd in $PREFIX/lib/php.ini (that file needs to be created if it does not exist).

If extension=gd is specified in php.ini file and php-gd is not installed, php -m shows a big warning.

we should probably setup so that php automatically loads a gd.ini file (or similar) with extension=gd.so once the php-gd package is installed.

Alpine Linux does the same. I'm exploring it.

freebrowser1 commented 2 weeks ago

I added the line extension=gd.so to php.ini and php -m now does show gd. And php -r 'var_dump(gd_info());' shows:

array(15) {
  ["GD Version"]=>
  string(5) "2.3.3"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(false)
  ["XBM Support"]=>
  bool(true)
  ["WebP Support"]=>
  bool(true)
  ["BMP Support"]=>
  bool(true)
  ["AVIF Support"]=>
  bool(true)
  ["TGA Read Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}

so it IS installed. And phpinfo() also shows it:

PHP Version => 8.3.10

System => Linux localhost 5.15.104-android13-8-00001-gac1072c849eb-ab10753874 #1 SMP PREEMPT Fri Sep 1 23:16:48 UTC 2023 aarch64
Build Date => Aug  8 2024 05:08:24
Build System => Linux e0fc9f326c9b 6.5.0-1025-azure #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Configure Command =>  '/home/builder/.termux-build/php/src/configure'  '--disable-dependency-tracking' '--prefix=/data/data/com.termux/files/usr' '--libdir=/data/data/com.termux/files/us
r/lib' '--disable-rpath' '--disable-rpath-hack' '--host=aarch64-linux-android' 'ac_cv_func_res_nsearch=no' 'ac_cv_phpdbg_userfaultfd_writefault=no' 'php_cv_lib_gd_gdImageCreateFromPng=ye
s' 'php_cv_lib_gd_gdImageCreateFromAvif=yes' 'php_cv_lib_gd_gdImageCreateFromWebp=yes' 'php_cv_lib_gd_gdImageCreateFromJpeg=yes' 'php_cv_lib_gd_gdImageCreateFromBmp=yes' 'php_cv_lib_gd_g
dImageCreateFromTga=yes' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-sockets' '--mandir=/data/data/com.termux/
files/usr/share/man' '--with-bz2=/data/data/com.termux/files/usr' '--with-curl=/data/data/com.termux/files/usr' '--with-ldap=shared,/data/data/com.termux/files/usr' '--with-ldap-sasl' '-
-with-openssl=/data/data/com.termux/files/usr' '--with-readline=/data/data/com.termux/files/usr' '--with-sodium=shared,/data/data/com.termux/files/usr' '--with-iconv-dir=/data/data/com.t
ermux/files/usr' '--with-zlib' '--with-pgsql=shared,/data/data/com.termux/files/usr' '--with-pdo-pgsql=shared,/data/data/com.termux/files/usr' '--with-mysqli=mysqlnd' '--with-pdo-mysql=m
ysqlnd' '--with-mysql-sock=/data/data/com.termux/files/usr/tmp/mysqld.sock' '--with-apxs2=/home/builder/.termux-build/php/tmp/apxs-wrapper.sh' '--with-iconv=/data/data/com.termux/files/u
sr' '--enable-fpm' '--enable-gd=shared,/data/data/com.termux/files/usr' '--with-external-gd' '--with-external-pcre' '--with-zip' '--with-xsl' '--with-gmp' '--with-ffi' '--with-tidy=/data
/data/com.termux/files/usr' '--enable-intl' '--sbindir=/data/data/com.termux/files/usr/bin' '--disable-nls' '--enable-shared' '--enable-static' '--libexecdir=/data/data/com.termux/files/
usr/libexec' 'host_alias=aarch64-linux-android' 'PKG_CONFIG=/home/builder/.termux-build/_cache/android-r27-api-24-v0/bin/pkg-config' 'PKG_CONFIG_LIBDIR=/data/data/com.termux/files/usr/li
b/pkgconfig:/data/data/com.termux/files/usr/share/pkgconfig' 'CPP=aarch64-linux-android-cpp'
Server API => Command Line Interface
Virtual Directory Support => disabled

But with Apache it does NOT work. I obviously kicked apache by sv stop httpd followed by sv start httpd before opening a webpage requiring gd, e.g. an empty one with only phpinfo(); in it, but still to no avail, as phpinfo() run from a script on a webpage does not show gd, while it is included.

EDIT: When there is no solution, how can I revert to PHP 8.3.8 ? Under 8.3.8 gd worked normally.

freebrowser1 commented 2 weeks ago

In the phpinfo() as I stated above I see --enable-gd=shared --with-external-gd but not --with-gd Is php properly built ?

TomJo2000 commented 2 weeks ago

Please ensure you also have the php-gd package installed.

Baturax commented 2 weeks ago

Since other distros have already done so, it would be good if it stayed like that

Baturax commented 2 weeks ago

I think that after #21072 the gd extension needs to be enabled explicitly by specifying extension=gd in $PREFIX/lib/php.ini (that file needs to be created if it does not exist).

After doing that, php -m shows the gd module, and some example php scripts using gd works.

Don't know much about how php is normally packaged, but having a peek at how it works in ubuntu we should probably setup so that php automatically loads a gd.ini file (or similar) with extension=gd.so once the php-gd package is installed.

Biswa96 commented 2 weeks ago

The issue has not been fixed yet.

freebrowser1 commented 2 weeks ago

I tried a gd.ini in the same folder as php.ini $(PREFIX)/user/lib with just a line extension=gd.so, but to no avail (i.e. php -m did show gd, but not in phpinfo(); under Apache). I hope this will be fixed soon, as many webpages / web interfaces require gd.

Baturax commented 2 weeks ago

I tried a gd.ini in the same folder as php.ini $(PREFIX)/user/lib with just a line extension=gd.so, but to no avail (i.e. php -m did show gd, but not in phpinfo(); under Apache). I hope this will be fixed soon, as many webpages / web interfaces require gd.

You should add to $PREFIX/lib/php.ini Like vim $PREFIX/lib/php.ini

Biswa96 commented 2 weeks ago

I have added a pull request to fix this issue. Would you like to test the packages from GitHub Actions artifacts of that pull request? Link https://github.com/termux/termux-packages/actions/runs/10609522011

As I explained in https://github.com/termux/termux-packages/issues/21262#issuecomment-2314842020, I copied the behavior from Alpine Linux. As a user, you do not have to add or edit any file. You just install php and php-gd. Then php loads the extensions from files in $PREFIX/etc/php/conf.d. For example, php-gd has gd.ini.

Now I have to add those ini files for other php extensions as well ⏳

freebrowser1 commented 2 weeks ago

So what should I do now to get it working ? I have installed php and php-gd and enabled extension=gd.so in php.ini. But there is no $PREFIX/etc/php folder on my system. Should I create that folder and create the subfolder conf.d inside it ? And what should I put into that folder ? Should I update (pkg update && pkg upgrade) to update php ?

Biswa96 commented 2 weeks ago

So what should I do now to get it working ?

If you do not know how to test packages from CI artifacts, then just wait for the pull request to be merged.

freebrowser1 commented 2 weeks ago

Well, I saw that there was a zip inside it with many deb files. So can I install these with dpkg -i <debfile> ?

Biswa96 commented 2 weeks ago

The above workarounds with php.ini are not required and can be removed now.

freebrowser1 commented 2 weeks ago

Well I just installed the patched dpkg modules, restarted Apache, but gd is still not loaded under Apache. I did this:

dpkg -i *.deb

This issued errors appeared due to not all dependenscies already installed, so I did:

pkg update && pkg upgrade
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 php-apache-ldap : Depends: openldap but it is not going to be installed
 php-apache-pgsql : Depends: postgresql but it is not going to be installed
 php-apache-sodium : Depends: libsodium but it is not going to be installed
 php-ldap : Depends: openldap but it is not going to be installed
 php-pgsql : Depends: postgresql but it is not going to be installed
 php-sodium : Depends: libsodium but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
$ apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libsasl libsodium openldap postgresql
The following NEW packages will be installed:
  libsasl libsodium openldap postgresql
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
6 not fully installed or removed.
Need to get 7131 kB of archives.
After this operation, 33.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://packages-cf.termux.dev/apt/termux-main stable/main aarch64 libsasl aarch64 2.1.28-1 [85.4 kB]
Get:2 https://packages-cf.termux.dev/apt/termux-main stable/main aarch64 openldap aarch64 2.6.8 [1138 kB]
Get:3 https://packages-cf.termux.dev/apt/termux-main stable/main aarch64 postgresql aarch64 16.4 [5789 kB]
Get:4 https://packages-cf.termux.dev/apt/termux-main stable/main aarch64 libsodium aarch64 1.0.20 [120 kB]
Fetched 7131 kB in 4s (2021 kB/s)   
Selecting previously unselected package libsasl.
(Reading database ... 34562 files and directories currently installed.)
Preparing to unpack .../libsasl_2.1.28-1_aarch64.deb ...
Unpacking libsasl (2.1.28-1) ...
Selecting previously unselected package openldap.
Preparing to unpack .../openldap_2.6.8_aarch64.deb ...
Unpacking openldap (2.6.8) ...
Selecting previously unselected package postgresql.
Preparing to unpack .../postgresql_16.4_aarch64.deb ...
Unpacking postgresql (16.4) ...
Selecting previously unselected package libsodium.
Preparing to unpack .../libsodium_1.0.20_aarch64.deb ...
Unpacking libsodium (1.0.20) ...
Setting up libsodium (1.0.20) ...
Setting up postgresql (16.4) ...
Setting up libsasl (2.1.28-1) ...
Setting up php-sodium (8.3.10-1) ...
Setting up php-apache-sodium (8.3.10-1) ...
Setting up php-apache-pgsql (8.3.10-1) ...
Setting up php-pgsql (8.3.10-1) ...
Setting up openldap (2.6.8) ...
Setting up php-apache-ldap (8.3.10-1) ...
Setting up php-ldap (8.3.10-1) ...

For sure I ran again (possible obsolete ?)

$ dpkg -i *.deb 
(Reading database ... 37125 files and directories currently installed.)
Preparing to unpack .../php-apache-ldap_8.3.10-1_aarch64.deb ...
Unpacking php-apache-ldap (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-apache-opcache_8.3.10-1_aarch64.deb ...
Unpacking php-apache-opcache (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-apache-pgsql_8.3.10-1_aarch64.deb ...
Unpacking php-apache-pgsql (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-apache-sodium_8.3.10-1_aarch64.deb ...
Unpacking php-apache-sodium (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-apache_8.3.10-1_aarch64.deb ...
Unpacking php-apache (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-fpm_8.3.10-1_aarch64.deb ...
Unpacking php-fpm (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-gd_8.3.10-1_aarch64.deb ...
Unpacking php-gd (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-ldap_8.3.10-1_aarch64.deb ...
Unpacking php-ldap (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-pgsql_8.3.10-1_aarch64.deb ...
Unpacking php-pgsql (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../php-sodium_8.3.10-1_aarch64.deb ...
Unpacking php-sodium (8.3.10-1) over (8.3.10-1) ...
Preparing to unpack .../debs/php_8.3.10-1_aarch64.deb ...
Unpacking php (8.3.10-1) over (8.3.10-1) ...
Setting up php (8.3.10-1) ...
Setting up php-apache (8.3.10-1) ...

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

Setting up php-fpm (8.3.10-1) ...
Setting up php-gd (8.3.10-1) ...
Setting up php-ldap (8.3.10-1) ...
Setting up php-pgsql (8.3.10-1) ...
Setting up php-sodium (8.3.10-1) ...
Setting up php-apache-ldap (8.3.10-1) ...
Setting up php-apache-opcache (8.3.10-1) ...
Setting up php-apache-pgsql (8.3.10-1) ...
Setting up php-apache-sodium (8.3.10-1) ...

That worked normally and php -m did show gd, but when I loaded a webpage phpinfo.php with contents:

<?php
phpinfo();

in the browser it did not show gd.

Biswa96 commented 2 weeks ago

This issue is about php and I have not look into apache. Please provide some info about expected and current output and steps to reproduce it.

freebrowser1 commented 2 weeks ago

I just added the terminal output above. But php still does not load gd under Apache and most websites use Apache. To reproduce, install php and Apache: pkg install php apache2 php-apache php-gd and copy attached httpd.conf into $PREFIX/etc/apache2 for loading php into apache: httpd.conf.zip and add a file /data/data/com.termux/files/usr/share/apache2/default-site/htdocs/phpinfo.php with contents <?php phpinfo(); and then load in the browser on the device http://localhost:8080/phpinfo.php. This shows all loaded modules but no gd.

Screenshot 2024-08-29 at 18 14 56
Biswa96 commented 2 weeks ago

I am not familiar with web dev stuff and do not know how to setup that. Just provide the commands to reproduce it and I will run.

Biswa96 commented 2 weeks ago

If I run php -r 'phpinfo();' command it shows gd.

freebrowser1 commented 2 weeks ago

Exactly that did it for me too, when run standalone, that already did it with the original 8.3.10 with the edit in php.ini. But most websites use Apache and many of them are useless without gd.

Can this issue be fixed by reverting to including compiling gd into php just as it was in php 8.3.8 and earlier ?

freebrowser1 commented 2 weeks ago

I am not familiar with web dev stuff and do not know how to setup that. Just provide the commands to reproduce it and I will run.

To reproduce, install php and Apache: pkg install php apache2 php-apache php-gd and copy attached httpd.conf into $PREFIX/etc/apache2 over existing httpd.conf for loading php into apache: httpd.conf.zip and add a file /data/data/com.termux/files/usr/share/apache2/default-site/htdocs/phpinfo.php with contents <?php phpinfo(); . Start apache by apachectl start (ignore the error message about the domain), then load in the browser on the device http://localhost:8080/phpinfo.php. This shows all loaded modules but no gd.

freebrowser1 commented 2 weeks ago

Now I updated PHP on another device where 8.3.10 was with the 'royal' way using pkg update && pkg upgrade which resulted in updating php, php-gd and php-apache from 8.3.10 to 8.3.10_1. Then I kicked Apache but according to phpinfo() the gd module is not loaded. But I also saw that php.ini was on another location than on 8.3.10 (according to phpinfo()), so I removed extension=gd from it and from $PREFIX/usr/lib, moved php.ini to $PREFIX/usr/etc/php and kicked Apache again.

Configuration File (php.ini) Path   /data/data/com.termux/files/usr/etc/php 

Now my original php settings were retained, but still no gd, despite there now is an automatically created file $PREFIX/usr/etc/php/conf.d/gd.ini with the line extension=gd in it.

This is in the 'configure command' in phpinfo():

 '/home/builder/.termux-build/php/src/configure'  '--disable-dependency-tracking' '--prefix=/data/data/com.termux/files/usr' '--libdir=/data/data/com.termux/files/usr/lib' '--disable-rpath' '--disable-rpath-hack' '--host=aarch64-linux-android' 'ac_cv_func_res_nsearch=no' 'ac_cv_phpdbg_userfaultfd_writefault=no' 'php_cv_lib_gd_gdImageCreateFromPng=yes' 'php_cv_lib_gd_gdImageCreateFromAvif=yes' 'php_cv_lib_gd_gdImageCreateFromWebp=yes' 'php_cv_lib_gd_gdImageCreateFromJpeg=yes' 'php_cv_lib_gd_gdImageCreateFromBmp=yes' 'php_cv_lib_gd_gdImageCreateFromTga=yes' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-sockets' '--mandir=/data/data/com.termux/files/usr/share/man' '--with-bz2=/data/data/com.termux/files/usr' '--with-config-file-path=/data/data/com.termux/files/usr/etc/php' '--with-config-file-scan-dir=/data/data/com.termux/files/usr/etc/php/conf.d' '--with-curl=/data/data/com.termux/files/usr' '--with-ldap=shared,/data/data/com.termux/files/usr' '--with-ldap-sasl' '--with-openssl=/data/data/com.termux/files/usr' '--with-readline=/data/data/com.termux/files/usr' '--with-sodium=shared,/data/data/com.termux/files/usr' '--with-iconv-dir=/data/data/com.termux/files/usr' '--with-zlib' '--with-pgsql=shared,/data/data/com.termux/files/usr' '--with-pdo-pgsql=shared,/data/data/com.termux/files/usr' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/data/data/com.termux/files/usr/tmp/mysqld.sock' '--with-apxs2=/home/builder/.termux-build/php/tmp/apxs-wrapper.sh' '--with-iconv=/data/data/com.termux/files/usr' '--enable-fpm' '--enable-gd=shared,/data/data/com.termux/files/usr' '--with-external-gd' '--with-external-pcre' '--with-zip' '--with-xsl' '--with-gmp' '--with-ffi' '--with-tidy=/data/data/com.termux/files/usr' '--enable-intl' '--sbindir=/data/data/com.termux/files/usr/bin' '--disable-nls' '--enable-shared' '--enable-static' '--libexecdir=/data/data/com.termux/files/usr/libexec' 'host_alias=aarch64-linux-android' 'PKG_CONFIG=/home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/pkg-config' 'PKG_CONFIG_LIBDIR=/data/data/com.termux/files/usr/lib/pkgconfig:/data/data/com.termux/files/usr/share/pkgconfig' 'CPP=aarch64-linux-android-cpp' 

So this issue has still to be fixed, or reverted to a pre 8.3.10 version.

freebrowser1 commented 1 week ago

No reaction yet ? Why not reverting to a php binary with an included gd library just as before ?

Biswa96 commented 1 week ago

The underlying issue is related to rpath. If you want to load php modules with apache, add this workaround patchelf --add-needed libphp.so $PREFIX/lib/php/gd.so. After adding that workaround, php -m will not load gd module.

freebrowser1 commented 1 week ago

That indeed worked and php under Apache works with gd. But why does php -m not work anymore ?

Biswa96 commented 1 week ago

I've already told its a rpath issue and can't figure out any solution yet.

freebrowser1 commented 1 week ago

So why not revert to the old situation as php 8.3.8 where it did work as before ? The (in the first impression minor) update from 8.3.8 => 8.3.10 suddenly disabled gd.

Biswa96 commented 1 week ago

So why not revert to the old situation as php 8.3.8 where it did work as before ?

There was an issue to split gd dependencies from php #21068