[mapguide-commits] r10278 - in branches/4.0/MgDev: . Bindings/src/Bindings/Php cmake/configs

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Nov 8 03:53:30 PST 2026


Author: jng
Date: 2026-11-08 03:53:28 -0800 (Sun, 08 Nov 2026)
New Revision: 10278

Modified:
   branches/4.0/MgDev/Bindings/src/Bindings/Php/CMakeLists.txt
   branches/4.0/MgDev/CMakeLists.txt
   branches/4.0/MgDev/cmake/configs/php.ini.in
   branches/4.0/MgDev/cmake_package.sh
Log:
Install the PHP binding in PHP's extension directory

php.ini pointed extension_dir at webserverextensions/lib64 because that is where the MapGuide
binding was installed, while PHP's own extension directory
(webserverextensions/php/lib/php/extensions/<api>/) was never on the search path. A shared PHP
extension therefore could not be loaded by name at all: mbstring is built with
--enable-mbstring=shared (the only way to build PHP 8.3 on the generic build's rockylinux base,
php/php-src#12774), so `extension=mbstring` failed on every invocation and mb_convert_encoding()
was undefined unless a copy of the module was left beside the binding.

Resolve the extension directory once, at configure time, from the php-config that cmake_linuxapt.sh
installs into the prefix, and install the binding there instead:

- php.ini's extension_dir is that directory, so the binding and every shared extension (mbstring,
  opcache) are found by name, and the full builds no longer need to stage a second copy of mbstring.
- The binding installs relative to the prefix, so DESTDIR/CPack staging is unchanged, and its RPATH
  is computed from the extension directory to webserverextensions/lib64 and <prefix>/lib64
  ($ORIGIN/../../../../../lib64 and $ORIGIN/../../../../../../lib64), replacing the hardcoded
  $ORIGIN/../../lib64 that assumed the module lived in webserverextensions/lib64.
- The unversioned libphp_MapGuideApi.so is a relative symlink, so an extracted tree loads the
  module as well as an installed one.
- install_symlink() takes an optional install directory for that; existing callers are unchanged.

cmake_package.sh then has to describe what the packages contain, because the binding is now a
shared library in a component that never carried one:

- it only hands dpkg-shlibdeps files that exist, and always puts the prefix's own lib64 on the
  search path. Three of the five debs used to be packaged with no Depends field at all: httpd
  because the glob it passed for a component with no webserverextensions/lib64 stayed unexpanded
  and the call failed, server and coordsys because <prefix>/lib64 was never on the path.
- dpkg_component takes an optional directory whose binaries are dependencies too, used for the PHP
  extension directory (httpd) and share/gis/coordsys (the CS-Map utilities).

Verified with a generic Release build: the tarball carries libphp_MapGuideApi-4.0.0.so and
mbstring.so under webserverextensions/php/lib/php/extensions/no-debug-zts-20230831, the installed
php.ini's extension_dir resolves to it, and `php -m` loads both MapGuideApi and mbstring with no
LD_LIBRARY_PATH and no -d overrides - the binding's RPATH alone finds the glue and core libraries.
The .run package installed on Debian 12 loads both through the installed php.ini and runs the PHP
binding test script against a live mgserver.

The ubuntu22 build resolves the same directory and behaves the same way. Its deb packaging moves
libphp_MapGuideApi into mapguideopensource-httpd (the package that carries PHP) and out of
mapguideopensource-webextensions. common and webextensions keep the control files they had, httpd
gains the Depends it never had (libc6, libgcc-s1, libstdc++6, libxerces-c3.2), server gains
libace-7.0.6, libc6, libgcc-s1, libstdc++6, libuuid1, libxerces-c3.2 and zlib1g, and coordsys gains
libc6, libgcc-s1 and libstdc++6. Installing that .run on Ubuntu 22.04 loads MapGuideApi and mbstring
from the installed php.ini under both the CLI and Apache's mod_php, the web tier test page drives a
live mgserver, and dep_check reports no missing dependencies.

PHP is only built by the full (non common-subset) builds, so the extension directory is resolved
only where the binding is built, and the common-subset and portable trees are unaffected.


Modified: branches/4.0/MgDev/Bindings/src/Bindings/Php/CMakeLists.txt
===================================================================
--- branches/4.0/MgDev/Bindings/src/Bindings/Php/CMakeLists.txt	2026-11-08 07:04:01 UTC (rev 10277)
+++ branches/4.0/MgDev/Bindings/src/Bindings/Php/CMakeLists.txt	2026-11-08 11:53:28 UTC (rev 10278)
@@ -77,9 +77,17 @@
 )
 
 if (UNIX)
-    message(STATUS "php_MapGuideApi will install to: ${LIB_INSTALL_DIR}")
-    install(TARGETS php_MapGuideApi${MG_VERSION_SUFFIX} DESTINATION ${LIB_INSTALL_DIR} COMPONENT ${MG_COMPONENT})
-    install_symlink(${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/libphp_MapGuideApi${MG_VERSION_SUFFIX}.so libphp_MapGuideApi.so ${MG_COMPONENT})
+    # A PHP module belongs in PHP's extension directory, where php.ini's extension_dir points. The
+    # glue libraries it links are in webserverextensions/lib64 and the core libraries in
+    # <prefix>/lib64, so express both as $ORIGIN-relative paths from the extension directory. The
+    # unversioned name is a relative symlink so an extracted tree still loads the module.
+    file(RELATIVE_PATH PHP_EXTENSION_REL_WEB "${PHP_EXTENSION_DIR_ABS}" "${MG_INSTALL_WEB_PREFIX_ABS}/lib${LIB_SUFFIX}")
+    file(RELATIVE_PATH PHP_EXTENSION_REL_PREFIX "${PHP_EXTENSION_DIR_ABS}" "${MG_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
+    set_target_properties(php_MapGuideApi${MG_VERSION_SUFFIX} PROPERTIES
+        INSTALL_RPATH "$ORIGIN:$ORIGIN/${PHP_EXTENSION_REL_WEB}:$ORIGIN/${PHP_EXTENSION_REL_PREFIX}")
+    message(STATUS "php_MapGuideApi will install to: ${PHP_EXTENSION_DIR_REL}")
+    install(TARGETS php_MapGuideApi${MG_VERSION_SUFFIX} DESTINATION ${PHP_EXTENSION_DIR_REL} COMPONENT ${MG_COMPONENT})
+    install_symlink(libphp_MapGuideApi${MG_VERSION_SUFFIX}.so libphp_MapGuideApi.so ${MG_COMPONENT} ${PHP_EXTENSION_DIR_REL})
 endif (UNIX)
 target_link_libraries(php_MapGuideApi${MG_VERSION_SUFFIX}
     ${ACE_LIBRARY}
@@ -96,11 +104,4 @@
     MgWebSupport${MG_VERSION_SUFFIX}
 )
 
-file(COPY "php.i" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
-
-# Set RPATH to avoid needing to use LD_LIBRARY_PATH in various configs
-if(MG_CPU EQUAL 64)
-    set_target_properties(php_MapGuideApi${MG_VERSION_SUFFIX} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../../lib64")
-else(MG_CPU EQUAL 64)
-    set_target_properties(php_MapGuideApi${MG_VERSION_SUFFIX} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../../lib")
-endif(MG_CPU EQUAL 64)
\ No newline at end of file
+file(COPY "php.i" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
\ No newline at end of file

Modified: branches/4.0/MgDev/CMakeLists.txt
===================================================================
--- branches/4.0/MgDev/CMakeLists.txt	2026-11-08 07:04:01 UTC (rev 10277)
+++ branches/4.0/MgDev/CMakeLists.txt	2026-11-08 11:53:28 UTC (rev 10278)
@@ -142,6 +142,36 @@
 set(MG_INSTALL_COORDSYS_PREFIX_ABS "${MG_INSTALL_PREFIX}/share/gis/coordsys")
 set(CMAKE_INSTALL_PREFIX "${MG_INSTALL_PREFIX}")
 
+# A PHP module has to live in PHP's extension directory, because that is what php.ini's
+# extension_dir names. cmake_linuxapt.sh installs PHP (and its php-config) into the install prefix
+# before this project is configured, so ask that php-config where the directory is.
+if (UNIX AND NOT MG_COMMON_SUBSET_ONLY)
+    set(PHP_EXTENSION_DIR "" CACHE PATH "PHP extension directory (php.ini extension_dir)")
+    if (NOT PHP_EXTENSION_DIR)
+        find_program(PHP_CONFIG_EXE NAMES php-config
+            HINTS "${MG_INSTALL_WEB_PREFIX_ABS}/php/bin"
+            NO_DEFAULT_PATH)
+        if (PHP_CONFIG_EXE)
+            execute_process(COMMAND "${PHP_CONFIG_EXE}" --extension-dir
+                OUTPUT_VARIABLE PHP_EXTENSION_DIR
+                OUTPUT_STRIP_TRAILING_WHITESPACE
+                ERROR_QUIET)
+        endif (PHP_CONFIG_EXE)
+    endif (NOT PHP_EXTENSION_DIR)
+    if (NOT PHP_EXTENSION_DIR)
+        message(FATAL_ERROR "Could not determine PHP's extension directory. Install PHP first (cmake_linuxapt.sh) or pass -DPHP_EXTENSION_DIR=<dir>.")
+    endif (NOT PHP_EXTENSION_DIR)
+    # Install relative to the prefix where possible so DESTDIR/CPack staging keeps working.
+    set(PHP_EXTENSION_DIR_ABS "${PHP_EXTENSION_DIR}")
+    file(RELATIVE_PATH PHP_EXTENSION_DIR_REL "${MG_INSTALL_PREFIX}" "${PHP_EXTENSION_DIR}")
+    if (PHP_EXTENSION_DIR_REL MATCHES "^\\.\\.")
+        set(PHP_EXTENSION_DIR_REL "${PHP_EXTENSION_DIR}")
+    else (PHP_EXTENSION_DIR_REL MATCHES "^\\.\\.")
+        set(PHP_EXTENSION_DIR_ABS "${MG_INSTALL_PREFIX}/${PHP_EXTENSION_DIR_REL}")
+    endif (PHP_EXTENSION_DIR_REL MATCHES "^\\.\\.")
+    message(STATUS "PHP extension directory: ${PHP_EXTENSION_DIR_ABS}")
+endif (UNIX AND NOT MG_COMMON_SUBSET_ONLY)
+
 set(MG_VERSION_SUFFIX "-${MG_VERSION}")
 
 macro(set_install_subdir relbase)
@@ -239,7 +269,19 @@
 
 # Some helper macros
 macro(install_symlink target linkname component)
-    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${MG_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/${linkname})")
+    # The optional fourth argument is the install directory, relative to the prefix; it defaults
+    # to LIB_INSTALL_DIR (the PHP binding uses PHP's extension directory instead).
+    if (${ARGC} GREATER 3)
+        set(_symlink_dir "${ARGV3}")
+    else (${ARGC} GREATER 3)
+        set(_symlink_dir "${LIB_INSTALL_DIR}")
+    endif (${ARGC} GREATER 3)
+    if (IS_ABSOLUTE "${_symlink_dir}")
+        set(_symlink_path "${_symlink_dir}/${linkname}")
+    else (IS_ABSOLUTE "${_symlink_dir}")
+        set(_symlink_path "${MG_INSTALL_PREFIX}/${_symlink_dir}/${linkname}")
+    endif (IS_ABSOLUTE "${_symlink_dir}")
+    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${_symlink_path})")
     install(CODE "message(\"-- Created symlink: ${linkname} -> ${target}\")")
 endmacro(install_symlink)
 macro(use_cxx11)

Modified: branches/4.0/MgDev/cmake/configs/php.ini.in
===================================================================
--- branches/4.0/MgDev/cmake/configs/php.ini.in	2026-11-08 07:04:01 UTC (rev 10277)
+++ branches/4.0/MgDev/cmake/configs/php.ini.in	2026-11-08 11:53:28 UTC (rev 10278)
@@ -759,8 +759,10 @@
 user_dir =
 
 ; Directory in which the loadable extensions (modules) reside.
+; This is PHP's own extension directory: the MapGuide binding and every shared PHP extension
+; (mbstring, opcache) are installed there, so `extension=<name>` resolves without a path.
 ; https://php.net/extension-dir
-extension_dir = "@MG_INSTALL_WEB_PREFIX_ABS@/lib at LIB_SUFFIX@"
+extension_dir = "@PHP_EXTENSION_DIR_ABS@"
 
 ; Directory where the temporary files should be placed.
 ; Defaults to the system default (see sys_get_temp_dir)

Modified: branches/4.0/MgDev/cmake_package.sh
===================================================================
--- branches/4.0/MgDev/cmake_package.sh	2026-11-08 07:04:01 UTC (rev 10277)
+++ branches/4.0/MgDev/cmake_package.sh	2026-11-08 11:53:28 UTC (rev 10278)
@@ -207,6 +207,9 @@
     DIRLIST="$3"
     REMOVELIST="$4"
     STRIPLIST="$5"
+    # Optional: a subdirectory of the install base whose shared libraries are also scanned for
+    # dependencies (httpd has none under ${LIBDIR}; its library is the PHP binding)
+    SHLIBDEPS_EXTRA="$6"
     DPKG_TREE="$WORKING_DIR/debian"
     DPKG_ROOT="$DPKG_TREE/${DPKG_NAME_N}"
     DPKG_CP_ROOT="$DPKG_ROOT/$MGINST"
@@ -279,10 +282,29 @@
     # Shared library symlinks point back to install directory
     # Add install directory to path to compensate
     # Also add FDO libs to path
-    export LD_LIBRARY_PATH=/usr/local/fdo-${FDO_VER}/${LIBDIR}:${DPKG_CP_ROOT}/${LIBDIR}:/${MGINST}/${LIBDIR}:/${MGINST}/server/${LIBDIR}:/${MGINST}/webserverextensions/${LIBDIR}
+    # The prefix's own ${LIBDIR} is always included: components below it (server, coordsys) link the
+    # core libraries that live there, and leaving it out stopped dpkg-shlibdeps resolving them.
+    export LD_LIBRARY_PATH=/usr/local/fdo-${FDO_VER}/${LIBDIR}:/usr/local/mapguideopensource-${MG_VER}/${LIBDIR}:${DPKG_CP_ROOT}/${LIBDIR}:/${MGINST}/${LIBDIR}:/${MGINST}/server/${LIBDIR}:/${MGINST}/webserverextensions/${LIBDIR}
     echo "Using LD_LIBRARY_PATH of:"
     echo "$LD_LIBRARY_PATH"
-    dpkg-shlibdeps -p"$DPKG_NAME_N" --ignore-missing-info ${DPKG_CP_ROOT}/${LIBDIR}/*.so
+    # Only hand dpkg-shlibdeps files that exist: a component need not have a ${LIBDIR} of its own,
+    # and an unexpanded glob made it fail and left the package without a Depends field.
+    SHLIBDEPS_FILES=
+    for file in ${DPKG_CP_ROOT}/${LIBDIR}/*.so
+    do
+        [ -f "$file" ] && SHLIBDEPS_FILES="${SHLIBDEPS_FILES} ${file}"
+    done
+    # SHLIBDEPS_EXTRA names a directory of the install base whose binaries and shared libraries are
+    # dependencies as well: the PHP binding (httpd) and the CS-Map utilities (coordsys).
+    if [ -n "$SHLIBDEPS_EXTRA" ]; then
+        for file in $(find ${DPKG_CP_ROOT}${SHLIBDEPS_EXTRA} -type f \( -name '*.so' -o -perm -u+x \) 2>/dev/null)
+        do
+            SHLIBDEPS_FILES="${SHLIBDEPS_FILES} ${file}"
+        done
+    fi
+    if [ -n "$SHLIBDEPS_FILES" ]; then
+        dpkg-shlibdeps -p"$DPKG_NAME_N" --ignore-missing-info ${SHLIBDEPS_FILES}
+    fi
     dpkg-gensymbols -p"$DPKG_NAME" -P"debian/$DPKG_NAME_N"
     export LD_LIBRARY_PATH=
 
@@ -321,13 +343,13 @@
     arg_dir_list="apache2 php tomcat"
     arg_remove_list="\.a\$ \.la\$"
     arg_strip_list="\.so\$"
-    dpkg_component httpd "$arg_inst_base" "$arg_dir_list" "$arg_remove_list" "$arg_strip_list"
+    dpkg_component httpd "$arg_inst_base" "$arg_dir_list" "$arg_remove_list" "$arg_strip_list" "/php/lib/php/extensions"
 
     arg_inst_base=""
     arg_dir_list="share"
     arg_remove_list="\.a\$ \.la\$ \.c\$ \.o\$ \.mak\$ \.nmk\$"
     arg_strip_list="\.so\$"
-    dpkg_component coordsys "$arg_inst_base" "$arg_dir_list" "$arg_remove_list" "$arg_strip_list"
+    dpkg_component coordsys "$arg_inst_base" "$arg_dir_list" "$arg_remove_list" "$arg_strip_list" "/share/gis/coordsys"
 }
 
 create_rpm_package()



More information about the mapguide-commits mailing list