phpmakefilelinkerlibrariespecl

How to compile and install a php extension on a server with multiple php versions?


I'm trying to re-enable pcntl after an update on my test server removed it somehow and broke my php application.

I used

update-alternatives --set php /usr/bin/php7.4
update-alternatives --set phpize /usr/bin/phpize7.4

to switch php version for the command line. However, the 'make' command still results in the wrong libraries being included for some, but not all, of the compilation (the linker is evil). For example, It created the following mess of a command for one of the files:

/bin/bash /usr/src/php-7.4.33/ext/pcntl/libtool --mode=compile cc -DHAVE_STRUCT_SIGINFO_T -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/src/php-7.4.33/ext/pcntl -DPHP_ATOM_INC -I/usr/src/php-7.4.33/ext/pcntl/include -I/usr/src/php-7.4.33/ext/pcntl/main -I/usr/src/php-7.4.33/ext/pcntl -I/usr/include/php/20230831 -I/usr/include/php/20230831/main -I/usr/include/php/20230831/TSRM -I/usr/include/php/20230831/Zend -I/usr/include/php/20230831/ext -I/usr/include/php/20230831/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/src/php-7.4.33/ext/pcntl/pcntl.c -o pcntl.lo

Given the various versions are all messed up and jumbled together to no surprise the compilation fails. How do I get it to grab stuff from the right folder? (Should be /usr/include/php/20190902)?

I could dig into the horror that is the library configuration of php, but I wonder if there's a simple, effective way to do this.


Solution

  • There's one more tool to configure, the following should be used to switch to the right version:

    cd /usr/src/php-$VERSION/ext/$EXTENSION
    update-alternatives --set php /usr/bin/php7.4
    update-alternatives --set phpize /usr/bin/phpize7.4
    update-alternatives --set php-config /usr/bin/php-config7.4
    make
    
    

    Then use

    make -n install
    

    check the output to see if it now has all the correct directories here too. Then a

    make install
    

    will correctly configure the extension.