Skip to content

Commit f670f3c

Browse files
committed
Add option to override where to install mod_php.so Apache module
The mod_php.so is by default installed to Apache's module directory on the host system and this might interfere with some possible edge cases where some other install prefix is used. For example, during development of the build system itself.
1 parent 46af6ac commit f670f3c

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

cmake/ext/skeleton/CMakeLists.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ install(
121121
COMPONENT php-development
122122
)
123123

124-
set(PHP_EXTENSION_%EXTNAMECAPS% TRUE)
124+
set(PHP_EXT_%EXTNAMECAPS%_ENABLED TRUE)
125125

126126
# Create configuration header.
127127
configure_file(cmake/config.h.in config.h)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* Define to 1 if the PHP extension '%EXTNAME%' is available. */
2-
#cmakedefine PHP_EXTENSION_%EXTNAMECAPS% 1
2+
#cmakedefine PHP_EXT_%EXTNAMECAPS%_ENABLED 1

cmake/sapi/apache2handler/CMakeLists.txt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
44
Configure the `apache2handler` PHP SAPI.
55
6-
## PHP_SAPI_APACHE2HANDLER
6+
## Configuration options
7+
8+
### PHP_SAPI_APACHE2HANDLER
79
810
* Default: `OFF`
911
* Values: `ON|OFF`
1012
1113
Enable the shared Apache 2 handler SAPI module.
1214
15+
## PHP_SAPI_APACHE2HANDLER_INSTALL_DIR
16+
17+
* Default: The path to the Apache modules directory of the host system
18+
(`Apache_LIBEXEC`).
19+
20+
The path where to install the PHP Apache module (`mod_php.so`). Relative path is
21+
interpreted as being relative to the installation prefix `CMAKE_INSTALL_PREFIX`.
22+
23+
## About
24+
1325
Loadable via Apache's Dynamic Shared Object (DSO) support. If Apache will use
1426
PHP together with one of the threaded Multi-Processing Modules (MPMs), PHP must
1527
be configured and built with `PHP_THREAD_SAFETY` set to `ON`. Thread safety will
@@ -21,11 +33,24 @@ with the `APACHE_ROOT` and `Apache_APXS_EXECUTABLE` variables.
2133
2234
For example:
2335
24-
```cmake
36+
```sh
2537
cmake -B php-build -DPHP_SAPI_APACHE2HANDLER=ON -DAPACHE_ROOT=/opt/apache2
2638
# or
2739
cmake -B php-build -DPHP_SAPI_APACHE2HANDLER=ON -DApache_EXECUTABLE=/opt/apache2/bin/apxs
2840
```
41+
42+
The path, where to install the PHP Apache module, can be overridden with the
43+
`PHP_SAPI_APACHE2HANDLER_INSTALL_DIR` variable. This might be used in edge cases
44+
where some specific custom installation prefix is used to avoid insuficcient
45+
permissions of the default location on the host, or when developing the PHP
46+
build system.
47+
48+
```sh
49+
cmake \
50+
-B <build-dir> \
51+
-DPHP_SAPI_APACHE2HANDLER=ON \
52+
-DPHP_SAPI_APACHE2HANDLER_INSTALL_DIR=/custom/path/to/lib/apache2/modules
53+
```
2954
#]=============================================================================]
3055

3156
include(FeatureSummary)
@@ -38,6 +63,15 @@ add_feature_info(
3863
"Apache HTTP server module"
3964
)
4065

66+
set(
67+
CACHE{PHP_SAPI_APACHE2HANDLER_INSTALL_DIR}
68+
TYPE STRING
69+
HELP "The path to the Apache modules directory to install PHP Apache module"
70+
VALUE ""
71+
)
72+
set_property(CACHE PHP_SAPI_APACHE2HANDLER_INSTALL_DIR PROPERTY TYPE PATH)
73+
mark_as_advanced(PHP_SAPI_APACHE2HANDLER_INSTALL_DIR)
74+
4175
if(NOT PHP_SAPI_APACHE2HANDLER)
4276
return()
4377
endif()
@@ -75,6 +109,13 @@ set_package_properties(
75109
PURPOSE "Necessary to enable the Apache PHP SAPI."
76110
)
77111

112+
if(Apache_FOUND AND NOT PHP_SAPI_APACHE2HANDLER_INSTALL_DIR)
113+
set_property(
114+
CACHE PHP_SAPI_APACHE2HANDLER_INSTALL_DIR
115+
PROPERTY VALUE "${Apache_LIBEXECDIR}"
116+
)
117+
endif()
118+
78119
target_link_libraries(
79120
php_sapi_apache2handler
80121
PRIVATE
@@ -146,9 +187,9 @@ endif()
146187
install(
147188
TARGETS php_sapi_apache2handler
148189
LIBRARY
149-
DESTINATION ${Apache_LIBEXECDIR}
190+
DESTINATION ${PHP_SAPI_APACHE2HANDLER_INSTALL_DIR}
150191
COMPONENT php-sapi-apache2handler
151192
RUNTIME
152-
DESTINATION ${Apache_LIBEXECDIR}
193+
DESTINATION ${PHP_SAPI_APACHE2HANDLER_INSTALL_DIR}
153194
COMPONENT php-sapi-apache2handler
154195
)

0 commit comments

Comments
 (0)