1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
8 inherit flag-o-matic systemd autotools
11 DESCRIPTION="The PHP language runtime engine"
12 HOMEPAGE="https://www.php.net/"
13 SRC_URI="https://www.php.net/distributions/${P}.tar.xz"
21 unicode? ( BSD-2 LGPL-2.1 )"
24 KEYWORDS="~alpha amd64 arm ~arm64 ~hppa ~ia64 ~mips ppc ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
26 S="${WORKDIR}/${PN}-${MY_PV}"
28 # We can build the following SAPIs in the given order
29 SAPIS="embed cli cgi fpm apache2 phpdbg"
31 # SAPIs and SAPI-specific USE flags (cli SAPI is default on):
36 IUSE="${IUSE} acl argon2 bcmath berkdb bzip2 calendar cdb cjk
37 coverage +ctype curl debug
38 enchant exif ffi +fileinfo +filter firebird
39 +flatfile ftp gd gdbm gmp +iconv imap inifile
40 intl iodbc ipv6 +json kerberos ldap ldap-sasl libedit libressl lmdb
41 mhash mssql mysql mysqli nls
42 oci8-instant-client odbc +opcache pcntl pdo +phar +posix postgres qdbm
43 readline selinux +session session-mm sharedmem
44 +simplexml snmp soap sockets sodium spell sqlite ssl
45 sysvipc systemd test tidy +tokenizer tokyocabinet truetype unicode webp
46 +xml xmlreader xmlwriter xmlrpc xpm xslt zip zlib"
48 # Without USE=readline or libedit, the interactive "php -a" CLI will hang.
50 || ( cli cgi fpm apache2 embed phpdbg )
51 cli? ( ^^ ( readline libedit ) )
52 !cli? ( ?? ( readline libedit ) )
67 session-mm? ( session !threads )
68 mysql? ( || ( mysqli pdo ) )
73 RESTRICT="!test? ( test )"
75 # The supported (that is, autodetected) versions of BDB are listed in
76 # the ./configure script. Other versions *work*, but we need to stick to
77 # the ones that can be detected to avoid a repeat of bug #564824.
79 >=app-eselect/eselect-php-0.9.1[apache2?,fpm?]
80 >=dev-libs/libpcre2-10.30[unicode]
81 fpm? ( acl? ( sys-apps/acl ) )
82 apache2? ( www-servers/apache[apache2_modules_unixd(+),threads=] )
83 argon2? ( app-crypt/argon2:= )
84 berkdb? ( || ( sys-libs/db:5.3
90 bzip2? ( app-arch/bzip2:0= )
91 cdb? ( || ( dev-db/cdb dev-db/tinycdb ) )
92 coverage? ( dev-util/lcov )
93 curl? ( >=net-misc/curl-7.10.5 )
94 enchant? ( <app-text/enchant-2.0:0 )
95 ffi? ( >=dev-libs/libffi-3.0.11 )
96 firebird? ( dev-db/firebird )
97 gd? ( >=virtual/jpeg-0-r3:0 media-libs/libpng:0= )
98 gdbm? ( >=sys-libs/gdbm-1.8.0:0= )
99 gmp? ( dev-libs/gmp:0= )
100 iconv? ( virtual/libiconv )
101 imap? ( >=virtual/imap-c-client-2[kerberos=,ssl=] )
102 intl? ( dev-libs/icu:= )
103 kerberos? ( virtual/krb5 )
104 ldap? ( >=net-nds/openldap-1.2.11 )
105 ldap-sasl? ( dev-libs/cyrus-sasl )
106 libedit? ( dev-libs/libedit )
107 lmdb? ( dev-db/lmdb:= )
108 mssql? ( dev-db/freetds[mssql] )
109 nls? ( sys-devel/gettext )
110 oci8-instant-client? ( dev-db/oracle-instantclient-basic )
111 odbc? ( iodbc? ( dev-db/libiodbc ) !iodbc? ( >=dev-db/unixODBC-1.8.13 ) )
112 postgres? ( dev-db/postgresql:* )
113 qdbm? ( dev-db/qdbm )
114 readline? ( sys-libs/readline:0= )
115 session-mm? ( dev-libs/mm )
116 snmp? ( >=net-analyzer/net-snmp-5.2 )
117 sodium? ( dev-libs/libsodium:= )
118 spell? ( >=app-text/aspell-0.50 )
119 sqlite? ( >=dev-db/sqlite-3.7.6.3 )
121 !libressl? ( >=dev-libs/openssl-1.0.1:0= )
122 libressl? ( dev-libs/libressl:0= )
124 tidy? ( || ( app-text/tidy-html5 app-text/htmltidy ) )
125 tokyocabinet? ( dev-db/tokyocabinet )
126 truetype? ( =media-libs/freetype-2* )
127 unicode? ( dev-libs/oniguruma:= )
128 webp? ( media-libs/libwebp:0= )
129 xml? ( >=dev-libs/libxml2-2.7.6 )
130 xpm? ( x11-libs/libXpm )
131 xslt? ( dev-libs/libxslt )
132 zip? ( >=dev-libs/libzip-1.2.0:= )
133 zlib? ( >=sys-libs/zlib-1.2.0.4:0= )
136 RDEPEND="${COMMON_DEPEND}
139 selinux? ( sec-policy/selinux-phpfpm )
140 systemd? ( sys-apps/systemd ) )"
142 # Bison isn't actually needed when building from a release tarball
143 # However, the configure script will warn if it's absent or if you
144 # have an incompatible version installed. See bug 593278.
145 DEPEND="${COMMON_DEPEND}
147 >=sys-devel/bison-3.0.1"
149 BDEPEND="virtual/pkgconfig"
151 PHP_MV="$(ver_cut 1)"
153 PATCHES=( "${FILESDIR}/php-iodbc-header-location.patch" )
158 # work out where we are installing the ini file
159 php_set_ini_dir "${phpsapi}"
161 # Always install the production INI file, bug 611214.
162 local phpinisrc="php.ini-production-${phpsapi}"
163 cp php.ini-production "${phpinisrc}" || die
165 # default to /tmp for save_path, bug #282768
166 sed -e 's|^;session.save_path .*$|session.save_path = "'"${EPREFIX}"'/tmp"|g' -i "${phpinisrc}" || die
168 # Set the extension dir
169 sed -e "s|^extension_dir .*$|extension_dir = ${extension_dir}|g" \
170 -i "${phpinisrc}" || die
172 # Set the include path to point to where we want to find PEAR packages
173 sed -e 's|^;include_path = ".:/php/includes".*|include_path = ".:'"${EPREFIX}"'/usr/share/php'${PHP_MV}':'"${EPREFIX}"'/usr/share/php"|' -i "${phpinisrc}" || die
175 insinto "${PHP_INI_DIR#${EPREFIX}}"
176 newins "${phpinisrc}" php.ini
178 elog "Installing php.ini for ${phpsapi} into ${PHP_INI_DIR#${EPREFIX}}"
181 dodir "${PHP_EXT_INI_DIR#${EPREFIX}}"
182 dodir "${PHP_EXT_INI_DIR_ACTIVE#${EPREFIX}}"
185 elog "Adding opcache to $PHP_EXT_INI_DIR"
186 echo "zend_extension=${PHP_DESTDIR}/$(get_libdir)/opcache.so" >> \
187 "${D}/${PHP_EXT_INI_DIR}"/opcache.ini
188 dosym "../ext/opcache.ini" \
189 "${PHP_EXT_INI_DIR_ACTIVE#${EPREFIX}}/opcache.ini"
192 # SAPI-specific handling
193 if [[ "${sapi}" == "fpm" ]] ; then
194 einfo "Installing FPM config files php-fpm.conf and www.conf"
195 insinto "${PHP_INI_DIR#${EPREFIX}}"
196 doins sapi/fpm/php-fpm.conf
197 insinto "${PHP_INI_DIR#${EPREFIX}}/fpm.d"
198 doins sapi/fpm/www.conf
201 dodoc php.ini-{development,production}
205 PHP_INI_DIR="${EPREFIX}/etc/php/${1}-php${SLOT}"
206 PHP_EXT_INI_DIR="${PHP_INI_DIR}/ext"
207 PHP_EXT_INI_DIR_ACTIVE="${PHP_INI_DIR}/ext-active"
213 # In php-7.x, the FPM pool configuration files have been split off
214 # of the main config. By default the pool config files go in
215 # e.g. /etc/php-fpm.d, which isn't slotted. So here we move the
216 # include directory to a subdirectory "fpm.d" of $PHP_INI_DIR. Later
217 # we'll install the pool configuration file "www.conf" there.
219 sed -i "s~^include=.*$~include=${PHP_INI_DIR}/fpm.d/*.conf~" \
220 sapi/fpm/php-fpm.conf.in \
221 || die 'failed to move the include directory in php-fpm.conf'
223 # Emulate buildconf to support cross-compilation
224 rm -fr aclocal.m4 autom4te.cache config.cache \
225 configure main/php_config.h.in || die
231 addpredict /usr/share/snmp/mibs/.index #nowarn
232 addpredict /var/lib/net-snmp/mib_indexes #nowarn
234 PHP_DESTDIR="${EPREFIX}/usr/$(get_libdir)/php${SLOT}"
236 # The php-fpm config file wants localstatedir to be ${EPREFIX}/var
237 # and not the Gentoo default ${EPREFIX}/var/lib. See bug 572002.
239 --prefix="${PHP_DESTDIR}"
240 --mandir="${PHP_DESTDIR}/man"
241 --infodir="${PHP_DESTDIR}/info"
242 --libdir="${PHP_DESTDIR}/lib"
243 --with-libdir="$(get_libdir)"
244 --localstatedir="${EPREFIX}/var"
246 $(use_enable threads maintainer-zts)
250 $(use_with argon2 password-argon2 "${EPREFIX}/usr")
252 $(use_with bzip2 bz2 "${EPREFIX}/usr")
253 $(use_enable calendar)
254 $(use_enable coverage gcov)
257 $(use_enable xml dom)
261 $(use_enable fileinfo)
264 $(use_with nls gettext "${EPREFIX}/usr")
265 $(use_with gmp gmp "${EPREFIX}/usr")
266 $(use_with mhash mhash "${EPREFIX}/usr")
267 $(use_with iconv iconv \
268 $(use elibc_glibc || use elibc_musl || use elibc_FreeBSD || echo "${EPREFIX}/usr"))
273 $(use_with xml libxml)
274 $(use_enable unicode mbstring)
275 $(use_with ssl openssl)
279 $(use_enable opcache)
280 $(use_with postgres pgsql "${EPREFIX}/usr")
282 $(use_with spell pspell "${EPREFIX}/usr")
283 $(use_enable simplexml)
284 $(use_enable sharedmem shmop)
285 $(use_with snmp snmp "${EPREFIX}/usr")
287 $(use_enable sockets)
289 $(use_with sqlite sqlite3)
290 $(use_enable sysvipc sysvmsg)
291 $(use_enable sysvipc sysvsem)
292 $(use_enable sysvipc sysvshm)
293 $(use_with tidy tidy "${EPREFIX}/usr")
294 $(use_enable tokenizer)
296 $(use_enable xmlreader)
297 $(use_enable xmlwriter)
301 $(use_with zlib zlib "${EPREFIX}/usr")
306 if use cdb || use berkdb || use flatfile || use gdbm || use inifile \
307 || use qdbm || use lmdb || use tokyocabinet ; then
308 our_conf+=( "--enable-dba" )
311 # DBA drivers support
314 $(use_with berkdb db4 "${EPREFIX}/usr")
315 $(use_enable flatfile)
316 $(use_with gdbm gdbm "${EPREFIX}/usr")
317 $(use_enable inifile)
318 $(use_with qdbm qdbm "${EPREFIX}/usr")
319 $(use_with tokyocabinet tcadb "${EPREFIX}/usr")
320 $(use_with lmdb lmdb "${EPREFIX}/usr")
323 # Support for the GD graphics library
325 $(use_with truetype freetype)
326 $(use_enable cjk gd-jis-conv)
331 # enable gd last, so configure can pick up the previous settings
332 our_conf+=( $(use_enable gd) )
337 $(use_with imap imap "${EPREFIX}/usr")
338 $(use_with ssl imap-ssl "${EPREFIX}/usr")
345 $(use_with ldap ldap "${EPREFIX}/usr")
346 $(use_with ldap-sasl)
351 local mysqllib="mysqlnd"
352 local mysqlilib="mysqlnd"
354 our_conf+=( $(use_with mysqli mysqli "${mysqlilib}") )
356 local mysqlsock="${EPREFIX}/var/run/mysqld/mysqld.sock"
357 if use mysql || use mysqli ; then
358 our_conf+=( $(use_with mysql mysql-sock "${mysqlsock}") )
362 if use odbc && use iodbc ; then
366 $(use_with pdo pdo-odbc "iODBC,${EPREFIX}/usr")
370 --with-unixODBC="${EPREFIX}/usr"
372 $(use_with pdo pdo-odbc "unixODBC,${EPREFIX}/usr")
383 our_conf+=( $(use_with oci8-instant-client oci8) )
388 $(use_with mssql pdo-dblib "${EPREFIX}/usr")
389 $(use_with mysql pdo-mysql "${mysqllib}")
390 $(use_with postgres pdo-pgsql)
391 $(use_with sqlite pdo-sqlite)
392 $(use_with firebird pdo-firebird "${EPREFIX}/usr")
393 $(use_with oci8-instant-client pdo-oci)
397 # readline/libedit support
399 $(use_with readline readline "${EPREFIX}/usr")
404 if use session ; then
405 our_conf+=( $(use_with session-mm mm "${EPREFIX}/usr") )
407 our_conf+=( $(use_enable session) )
410 # Use pic for shared modules such as apache2's mod_php
411 our_conf+=( --with-pic )
413 # we use the system copy of pcre
414 # --with-external-pcre affects ext/pcre
415 # Many arches don't support pcre-jit
421 # Catch CFLAGS problems
423 # Changed order to run it in reverse for bug #32022 and #12021.
424 replace-cpu-flags "k6*" "i586"
426 # Cache the ./configure test results between SAPIs.
427 our_conf+=( --cache-file="${T}/config.cache" )
429 # Support user-passed configuration parameters
430 our_conf+=( ${EXTRA_ECONF:-} )
432 # Support the Apache2 extras, they must be set globally for all
433 # SAPIs to work correctly, especially for external PHP extensions
437 mkdir -p "${WORKDIR}/sapis-build" || die
438 for one_sapi in $SAPIS ; do
439 use "${one_sapi}" || continue
440 php_set_ini_dir "${one_sapi}"
442 # The BUILD_DIR variable is used to determine where to output
443 # the files that autotools creates. This was all originally
444 # based on the autotools-utils eclass.
445 BUILD_DIR="${WORKDIR}/sapis-build/${one_sapi}"
446 cp -a "${S}" "${BUILD_DIR}" || die
447 cd "${BUILD_DIR}" || die
450 --with-config-file-path="${PHP_INI_DIR}"
451 --with-config-file-scan-dir="${PHP_EXT_INI_DIR_ACTIVE}"
454 for sapi in $SAPIS ; do
456 cli|cgi|embed|fpm|phpdbg)
457 if [[ "${one_sapi}" == "${sapi}" ]] ; then
458 sapi_conf+=( "--enable-${sapi}" )
459 if [[ "fpm" == "${sapi}" ]] ; then
461 $(use_with acl fpm-acl)
462 $(use_with systemd fpm-systemd)
466 sapi_conf+=( "--disable-${sapi}" )
471 if [[ "${one_sapi}" == "${sapi}" ]] ; then
472 sapi_conf+=( --with-apxs2="${EPREFIX}/usr/bin/apxs" )
474 sapi_conf+=( --without-apxs2 )
480 # Construct the $myeconfargs array by concatenating $our_conf
481 # (the common args) and $sapi_conf (the SAPI-specific args).
482 local myeconfargs=( "${our_conf[@]}" )
483 myeconfargs+=( "${sapi_conf[@]}" )
485 pushd "${BUILD_DIR}" > /dev/null || die
486 econf "${myeconfargs[@]}"
487 popd > /dev/null || die
492 # snmp seems to run during src_compile, too (bug #324739)
493 addpredict /usr/share/snmp/mibs/.index #nowarn
494 addpredict /var/lib/net-snmp/mib_indexes #nowarn
497 for sapi in ${SAPIS} ; do
498 if use "${sapi}"; then
499 cd "${WORKDIR}/sapis-build/$sapi" || \
500 die "Failed to change dir to ${WORKDIR}/sapis-build/$1"
507 # see bug #324739 for what happens when we don't have that
508 addpredict /usr/share/snmp/mibs/.index #nowarn
510 # grab the first SAPI that got built and install common files from there
511 local first_sapi="", sapi=""
512 for sapi in $SAPIS ; do
519 # Makefile forgets to create this before trying to write to it...
520 dodir "${PHP_DESTDIR#${EPREFIX}}/bin"
522 # Install php environment (without any sapis)
523 cd "${WORKDIR}/sapis-build/$first_sapi" || die
524 emake INSTALL_ROOT="${D}" \
525 install-build install-headers install-programs
527 local extension_dir="$("${ED}/${PHP_DESTDIR#${EPREFIX}}/bin/php-config" --extension-dir)"
529 # Create the directory where we'll put version-specific php scripts
530 keepdir "/usr/share/php${PHP_MV}"
535 for sapi in ${SAPIS}; do
536 if use "${sapi}" ; then
537 einfo "Installing SAPI: ${sapi}"
538 cd "${WORKDIR}/sapis-build/${sapi}" || die
540 if [[ "${sapi}" == "apache2" ]] ; then
541 # We're specifically not using emake install-sapi as libtool
542 # may cause unnecessary relink failures (see bug #351266)
543 insinto "${PHP_DESTDIR#${EPREFIX}}/apache2/"
544 newins ".libs/libphp${PHP_MV}$(get_libname)" \
545 "libphp${PHP_MV}$(get_libname)"
546 keepdir "/usr/$(get_libdir)/apache2/modules"
548 # needed each time, php_install_ini would reset it
549 local dest="${PHP_DESTDIR#${EPREFIX}}"
553 source="sapi/cli/php"
554 # Install the "phar" archive utility.
556 emake INSTALL_ROOT="${D}" install-pharcmd
557 dosym "..${dest#/usr}/bin/phar" "/usr/bin/phar${SLOT}"
561 source="sapi/cgi/php-cgi"
564 source="sapi/fpm/php-fpm"
567 source="libs/libphp${PHP_MV}$(get_libname)"
570 source="sapi/phpdbg/phpdbg"
573 die "unhandled sapi in src_install"
577 if [[ "${source}" == *"$(get_libname)" ]]; then
581 local name="$(basename ${source})"
582 dosym "..${dest#/usr}/bin/${name}" "/usr/bin/${name}${SLOT}"
586 php_install_ini "${sapi}"
588 # construct correct SAPI string for php-config
589 # thanks to ferringb for the bash voodoo
590 if [[ "${sapi}" == "apache2" ]]; then
591 sapi_list="${sapi_list:+${sapi_list} }apache2handler"
593 sapi_list="${sapi_list:+${sapi_list} }${sapi}"
598 # Installing opcache module
599 if use opcache ; then
600 into "${PHP_DESTDIR#${EPREFIX}}"
601 dolib.so "modules/opcache$(get_libname)"
604 # Install env.d files
605 newenvd "${FILESDIR}/20php5-envd" "20php${SLOT}"
606 sed -e "s|/lib/|/$(get_libdir)/|g" -i "${ED}/etc/env.d/20php${SLOT}" || die
607 sed -e "s|php5|php${SLOT}|g" -i "${ED}/etc/env.d/20php${SLOT}" || die
609 # set php-config variable correctly (bug #278439)
610 sed -e "s:^\(php_sapis=\)\".*\"$:\1\"${sapi_list}\":" -i \
611 "${ED}/usr/$(get_libdir)/php${SLOT}/bin/php-config" || die
615 systemd_newunit "${FILESDIR}/php-fpm_at.service" \
616 "php-fpm@${SLOT}.service"
618 systemd_newunit "${FILESDIR}/php-fpm_at-simple.service" \
619 "php-fpm@${SLOT}.service"
625 echo ">>> Test phase [test]: ${CATEGORY}/${PF}"
626 PHP_BIN="${WORKDIR}/sapis-build/cli/sapi/cli/php"
627 if [[ ! -x "${PHP_BIN}" ]] ; then
628 ewarn "Test phase requires USE=cli, skipping"
631 export TEST_PHP_EXECUTABLE="${PHP_BIN}"
634 if [[ -x "${WORKDIR}/sapis-build/cgi/sapi/cgi/php-cgi" ]] ; then
635 export TEST_PHP_CGI_EXECUTABLE="${WORKDIR}/sapis-build/cgi/sapi/cgi/php-cgi"
638 if [[ -x "${WORKDIR}/sapis-build/phpdbg/sapi/phpdbg/phpdbg" ]] ; then
639 export TEST_PHPDBG_EXECUTABLE="${WORKDIR}/sapis-build/phpdbg/sapi/phpdbg/phpdbg"
642 REPORT_EXIT_STATUS=1 "${TEST_PHP_EXECUTABLE}" -n -d \
643 "session.save_path=${T}" \
644 "${WORKDIR}/sapis-build/cli/run-tests.php" -n -q -d \
645 "session.save_path=${T}"
647 for name in ${EXPECTED_TEST_FAILURES}; do
648 mv "${name}.out" "${name}.out.orig" 2>/dev/null || die
651 local failed="$(find -name '*.out')"
652 if [[ ${failed} != "" ]] ; then
653 ewarn "The following test cases failed unexpectedly:"
654 for name in ${failed}; do
655 ewarn " ${name/.out/}"
658 einfo "No unexpected test failures, all fine"
661 if [[ ${PHP_SHOW_UNEXPECTED_TEST_PASS} == "1" ]] ; then
663 for name in ${EXPECTED_TEST_FAILURES}; do
664 [[ -f "${name}.diff" ]] && continue
665 passed="${passed} ${name}"
667 if [[ ${passed} != "" ]] ; then
668 einfo "The following test cases passed unexpectedly:"
669 for name in ${passed}; do
673 einfo "None of the known-to-fail tests passed, all fine"
679 # Output some general info to the user
680 if use apache2 ; then
682 elog "To enable PHP in apache, you will need to add \"-D PHP\" to"
683 elog "your apache2 command. OpenRC users can append that string to"
684 elog "APACHE2_OPTS in /etc/conf.d/apache2."
686 elog "The apache module configuration file 70_mod_php.conf is"
687 elog "provided (and maintained) by eselect-php."
691 # Create the symlinks for php
693 for m in ${SAPIS}; do
694 [[ ${m} == 'embed' ]] && continue;
696 local ci=$(eselect php show $m)
697 if [[ -z $ci ]]; then
698 eselect php set $m php${SLOT} || die
699 einfo "Switched ${m} to use php:${SLOT}"
701 elif [[ $ci != "php${SLOT}" ]] ; then
702 elog "To switch $m to use php:${SLOT}, run"
703 elog " eselect php set $m php${SLOT}"
709 # Remove dead symlinks for SAPIs that were just disabled. For
710 # example, if the user has the cgi SAPI enabled, then he has an
711 # eselect-php symlink for it. If he later reinstalls PHP with
712 # USE="-cgi", that symlink will break. This call to eselect is
713 # supposed to remove that dead link per bug 572436.
714 eselect php cleanup || die
716 if ! has "php${SLOT/./-}" ${PHP_TARGETS}; then
717 elog "To build extensions for this version of PHP, you will need to"
718 elog "add php${SLOT/./-} to your PHP_TARGETS USE_EXPAND variable."
722 # Warn about the removal of PHP_INI_VERSION if the user has it set.
723 if [[ -n "${PHP_INI_VERSION}" ]]; then
724 ewarn 'The PHP_INI_VERSION variable has been phased out. You may'
725 ewarn 'remove it from your configuration at your convenience. See'
727 ewarn ' https://bugs.gentoo.org/611214'
729 ewarn 'for more information.'
732 elog "For details on how version slotting works, please see"
735 elog " https://wiki.gentoo.org/wiki/PHP"
740 # This serves two purposes. First, if we have just removed the last
741 # installed version of PHP, then this will remove any dead symlinks
742 # belonging to eselect-php. Second, if a user upgrades slots from
743 # (say) 5.6 to 7.0 and depcleans the old slot, then this will update
744 # his existing symlinks to point to the new 7.0 installation. The
745 # latter is bug 432962.
747 # Note: the eselect-php package may not be installed at this point,
748 # so we can't die() if this command fails.