frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

Build mostly static frankenphp linking against only libphp.so (and libc.so)

Open henderkes opened this issue 7 months ago • 9 comments

Describe you feature request

Just documenting my journey on banging my head against the damn Go linker.

CGO_CFLAGS="$(php-config --includes) -I/usr/local/include" \
    CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L/usr/local/lib64 -Wl,-rpath,$(php-config --lib-dir)" \
    go build -tags=nobadger,nomysql,nopgx \
    -ldflags="-linkmode external -extldflags '-static-libgcc -static-libstdc++ -Wl,-Bstatic -lwatcher-c -lbrotlienc -lbrotlidec -lbrotlicommon -Wl,-Bdynamic'

Still links against shared libwatcher.c.so.

Need to remove the shared library or not compile it in the first place...

CGO_CFLAGS="$(php-config --includes) -I/usr/local/include" \
    CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L/usr/local/lib64 -Wl,-rpath,$(php-config --lib-dir)" \
    go build -tags=nobadger,nomysql,nopgx \
    -ldflags="-linkmode external -extldflags '-static-libgcc -static-libstdc++ -lwatcher-c'"

->

[m@M-NB frankenphp]$ ldd frankenphp
        linux-vdso.so.1 (0x00007fffb11d4000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f060ae5a000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f060ac31000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f060ac1d000)
        libphp.so => /usr/local/static-php/lib/libphp.so (0x00007f060524a000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0605043000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f060af3b000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f0605029000)

henderkes avatar May 17 '25 02:05 henderkes

Edit: specify -buildmode=pie

CGO_CFLAGS="$(php-config --includes) -I$(php-config --include-dir)/.." CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -Wl,-rpath,$(php-config --lib-dir)" go build -tags=nobadger,nomysql,nopgx -buildmode=pie -ldflags="-linkmode external -extldflags '-pie -static-libgcc -static-libstdc++ -lwatcher-c'"

henderkes avatar May 17 '25 02:05 henderkes

Won't be able to get rid of the libstdc++ and libgcc dependencies unless we build our own gcc + binutils chain. Low priority, but it's in the works.

Integrating libwatcher into static-php-cli (?) https://github.com/crazywhalecc/static-php-cli/issues/728

henderkes avatar May 17 '25 03:05 henderkes

about finished building php-zts and frankenphp for rpm.

debian has to follow next:

[m@M-TH rpm]$ sudo dnf install static-php-1-0.noarch.rpm
Last metadata expiration check: 0:01:50 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Dependencies resolved.
========================================================================================================================
 Package                       Architecture              Version                  Repository                       Size
========================================================================================================================
Installing:
 static-php                    noarch                    1-0                      @commandline                    6.8 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total size: 6.8 k
Installed size: 106
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : static-php-1-0.noarch                                                                          1/1

Installed:
  static-php-1-0.noarch

Complete!
[m@M-TH rpm]$ sudo dnf module enable php-zts:static-8.4
Last metadata expiration check: 0:02:12 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Dependencies resolved.
========================================================================================================================
 Package                     Architecture               Version                       Repository                   Size
========================================================================================================================
Enabling module streams:
 php-zts                                                static-8.4

Transaction Summary
========================================================================================================================

Is this ok [y/N]: y
Complete!
[m@M-TH rpm]$ sudo dnf in frankenphp php-zts-xdebug
Last metadata expiration check: 0:02:22 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Dependencies resolved.
========================================================================================================================
 Package                          Architecture             Version                   Repository                    Size
========================================================================================================================
Installing:
 frankenphp84                     x86_64                   1.7.0-1                   static-php                    17 M
 php-zts-xdebug                   x86_64                   8.4.8-1                   static-php                   252 k
Installing dependencies:
 php-zts-cli                      x86_64                   8.4.8-1                   static-php                    24 M
 php-zts-embed                    x86_64                   8.4.8-1                   static-php                    24 M

Transaction Summary
========================================================================================================================
Install  4 Packages

Total size: 65 M
Installed size: 185 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : php-zts-cli-8.4.8-1.x86_64                                                                     1/4
  Installing       : php-zts-embed-8.4.8-1.x86_64                                                                   2/4
  Running scriptlet: frankenphp84-1.7.0-1.x86_64                                                                    3/4
  Installing       : frankenphp84-1.7.0-1.x86_64                                                                    3/4
  Running scriptlet: frankenphp84-1.7.0-1.x86_64                                                                    3/4
Error: requesting CA info: performing request: Get "http://localhost:2019/pki/ca/local": dial tcp 127.0.0.1:2019: connect: connection refused

  Installing       : php-zts-xdebug-8.4.8-1.x86_64                                                                  4/4
  Running scriptlet: php-zts-xdebug-8.4.8-1.x86_64                                                                  4/4

Installed:
  frankenphp84-1.7.0-1.x86_64  php-zts-cli-8.4.8-1.x86_64  php-zts-embed-8.4.8-1.x86_64  php-zts-xdebug-8.4.8-1.x86_64

Complete!
[m@M-TH rpm]$ frankenphp version
v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=
[m@M-TH rpm]$ php-zts -v
PHP 8.4.8 (cli) (built: Jun 16 2025 17:00:02) (ZTS)
Copyright (c) The PHP Group
Built by Static PHP <https://static-php.dev> #StandWithUkraine
Zend Engine v4.4.8, Copyright (c) Zend Technologies
    with Xdebug v3.4.4, Copyright (c) 2002-2025, by Derick Rethans
    with Zend OPcache v8.4.8, Copyright (c), by Zend Technologies
[m@M-TH rpm]$ sudo dnf rm frankenphp
Dependencies resolved.
========================================================================================================================
 Package                         Architecture             Version                   Repository                     Size
========================================================================================================================
Removing:
 frankenphp84                    x86_64                   1.7.0-1                   @static-php                    47 M
Removing unused dependencies:
 php-zts-embed                   x86_64                   8.4.8-1                   @static-php                    70 M

Transaction Summary
========================================================================================================================
Remove  2 Packages

Freed space: 117 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Running scriptlet: frankenphp84-1.7.0-1.x86_64                                                                    1/2
  Erasing          : frankenphp84-1.7.0-1.x86_64                                                                    1/2
  Running scriptlet: frankenphp84-1.7.0-1.x86_64                                                                    1/2
  Erasing          : php-zts-embed-8.4.8-1.x86_64                                                                   2/2

Removed:
  frankenphp84-1.7.0-1.x86_64                                php-zts-embed-8.4.8-1.x86_64

Complete!
[m@M-TH rpm]$ sudo dnf module switch-to php-zts:8.3
Last metadata expiration check: 0:03:00 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Error: Problems in request:
missing groups or modules: php-zts:8.3
[m@M-TH rpm]$ sudo dnf module switch-to php-zts:static-8.3
Last metadata expiration check: 0:03:04 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Dependencies resolved.
========================================================================================================================
 Package                         Architecture            Version                      Repository                   Size
========================================================================================================================
Downgrading:
 php-zts-cli                     x86_64                  8.3.22-1                     static-php                   22 M
 php-zts-xdebug                  x86_64                  8.3.22-1                     static-php                  252 k
Switching module streams:
 php-zts                                                 static-8.4 -> static-8.3

Transaction Summary
========================================================================================================================
Downgrade  2 Packages

Total size: 23 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Downgrading      : php-zts-cli-8.3.22-1.x86_64                                                                    1/4
  Downgrading      : php-zts-xdebug-8.3.22-1.x86_64                                                                 2/4
  Cleanup          : php-zts-xdebug-8.4.8-1.x86_64                                                                  3/4
  Cleanup          : php-zts-cli-8.4.8-1.x86_64                                                                     4/4
  Running scriptlet: php-zts-cli-8.4.8-1.x86_64                                                                     4/4

Downgraded:
  php-zts-cli-8.3.22-1.x86_64                               php-zts-xdebug-8.3.22-1.x86_64

Complete!
[m@M-TH rpm]$ sudo dnf install frankenphp
Last metadata expiration check: 0:03:14 ago on Mon 16 Jun 2025 05:22:50 PM +07.
Dependencies resolved.
========================================================================================================================
 Package                         Architecture             Version                    Repository                    Size
========================================================================================================================
Installing:
 frankenphp83                    x86_64                   1.7.0-1                    static-php                    17 M
Installing dependencies:
 php-zts-embed                   x86_64                   8.3.22-1                   static-php                    23 M

Transaction Summary
========================================================================================================================
Install  2 Packages

Total size: 40 M
Installed size: 113 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : php-zts-embed-8.3.22-1.x86_64                                                                  1/2
  Running scriptlet: frankenphp83-1.7.0-1.x86_64                                                                    2/2
  Installing       : frankenphp83-1.7.0-1.x86_64                                                                    2/2
  Running scriptlet: frankenphp83-1.7.0-1.x86_64                                                                    2/2
Error: requesting CA info: performing request: Get "http://localhost:2019/pki/ca/local": dial tcp 127.0.0.1:2019: connect: connection refused


Installed:
  frankenphp83-1.7.0-1.x86_64                               php-zts-embed-8.3.22-1.x86_64

Complete!
[m@M-TH rpm]$ php-zts -v
PHP 8.3.22 (cli) (built: Jun 16 2025 16:52:34) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.3.22, Copyright (c) Zend Technologies
    with Xdebug v3.4.4, Copyright (c) 2002-2025, by Derick Rethans
    with Zend OPcache v8.3.22, Copyright (c), by Zend Technologies

henderkes avatar Jun 16 '25 10:06 henderkes

I'm not 100% sure whether naming the packages frankenphp83 and frankenphp84 is the right move. It prevents easy module switches to a different version. But I also didn't know how to properly introduce the php version it's linking against in the version.

Maybe frankenphp-1.7.0.84-1.x86_64? But that's technically incorrect. frankenphp-1.7.0_84-1.x86_64?

henderkes avatar Jun 16 '25 10:06 henderkes

I renamed them to the last option. Now switching streams works seamlessly.

henderkes avatar Jun 16 '25 11:06 henderkes

I'll need to figure out signing and will then look into hosting by next week. RPM should be done then, for .deb I still have to figure out how to create a repository.

henderkes avatar Jun 16 '25 11:06 henderkes

But I also didn't know how to properly introduce the php version it's linking against in the version.

Names are easy to change. It may be annoying, but if it is the wrong call; it isn't the end of the world.

withinboredom avatar Jun 16 '25 16:06 withinboredom

https://rpms.henderkes.com/

x86_64 el10 and aarch64 el9/10 are ready for testing.

still not 100% sure if I want to support anything below rhel 9, centos 7 is running into troubles once more, the list of patches required to support it is ever growing.

(it does not conflict with system php installations, only the devel package will in the future. it installs php-zts, php-zts-fpm and php-zts-embedded (libphp-zts-8X.so))

henderkes avatar Jun 17 '25 09:06 henderkes

added x86_64 el7, el8, el9 - the php packages work with el7, but the frankenphp binary is still being built on my host, hence requires el10

henderkes avatar Jun 17 '25 12:06 henderkes

el7-el10 are now available for both x86_64 and aarch64, including frankenphp

henderkes avatar Jun 20 '25 13:06 henderkes