php编译安装时,默认的扩展目录总是很奇怪,至少让我不舒服,比如我编译的php7.4.3:
--extension-dir [/opt/php/74/lib/php/extensions/no-debug-non-zts-20190902]
其中 /opt/php/74 是–prefix 编译参数指定,后面为自动生成,不同版本的PHP,区别只是最后几数字。
我想想改变这个默认的路径,网上查半天没查到。但是查看用yum 或 apt 安装的PHP,路径又不是这样的:
Usage: /usr/bin/php-config [OPTION]
Options:
--prefix [/usr]
--includes [-I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib]
--ldflags []
--libs [-lcrypt -lresolv -lcrypt -ledit -lncurses -lstdc++ -lz -lpcre -lrt -lm -ldl -lxml2 -lz -llzma -lm -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lssl -lcrypto -lcrypt -lcrypt ]
--extension-dir [/usr/lib64/php/modules]
那说明,这个路径还是可以设置的。 网上查不到,就自己研究。
用vi打开configure文件,很快到如下一段代码:
if test -z "$EXTENSION_DIR"; then
extbasedir=$ZEND_MODULE_API_NO
if test "$oldstyleextdir" = "yes"; then
if test "$PHP_DEBUG" = "1"; then
part1=debug
else
part1=no-debug
fi
if test "$enable_maintainer_zts" = "yes"; then
part2=zts
else
part2=non-zts
fi
extbasedir=$part1-$part2-$extbasedir
EXTENSION_DIR=$libdir/extensions/$extbasedir
else
if test "$enable_maintainer_zts" = "yes"; then
extbasedir=$extbasedir-zts
fi
if test "$PHP_DEBUG" = "1"; then
extbasedir=$extbasedir-debug
fi
EXTENSION_DIR=$libdir/$extbasedir
fi
fi
很明显,这段代码是生成EXTENSION_DIR路径的,如果$EXTENSION_DIR为空才生成,不为空应该就是直接用变量的值了。
测试:
EXTENSION_DIR=/opt/php/74/extension ./configure --prefix=/opt/php/74
配置完成后,不用急着编译,在源码的main目录下,会生成一个build-defs.h的文件,打开内容如下:
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Stig Sæther Bakken <ssb@php.net> |
+----------------------------------------------------------------------+
*/
#define CONFIGURE_COMMAND " './configure' '--prefix=/opt/php/74'"
#define PHP_ODBC_CFLAGS ""
#define PHP_ODBC_LFLAGS ""
#define PHP_ODBC_LIBS ""
#define PHP_ODBC_TYPE ""
#define PHP_OCI8_DIR ""
#define PHP_OCI8_ORACLE_VERSION ""
#define PHP_PROG_SENDMAIL "/usr/sbin/sendmail"
#define PEAR_INSTALLDIR ""
#define PHP_INCLUDE_PATH ".:"
#define PHP_EXTENSION_DIR "/opt/php/74/extension"
#define PHP_PREFIX "/opt/php/74"
#define PHP_BINDIR "/opt/php/74/bin"
#define PHP_SBINDIR "/opt/php/74/sbin"
#define PHP_MANDIR "/opt/php/74/php/man"
#define PHP_LIBDIR "/opt/php/74/lib/php"
#define PHP_DATADIR "/opt/php/74/share/php"
#define PHP_SYSCONFDIR "/opt/php/74/etc"
#define PHP_LOCALSTATEDIR "/opt/php/74/var"
#define PHP_CONFIG_FILE_PATH "/opt/php/74/lib"
#define PHP_CONFIG_FILE_SCAN_DIR ""
#define PHP_SHLIB_SUFFIX "so"
#define PHP_SHLIB_EXT_PREFIX ""
应该是成功了,还是验证一下,make && make install 完成后运行php-config
Usage: ./php-config [OPTION]
Options:
--prefix [/opt/php/74]
--includes [-I/opt/php/74/include/php -I/opt/php/74/include/php/main -I/opt/php/74/include/php/TSRM -I/opt/php/74/include/php/Zend -I/opt/php/74/include/php/ext -I/opt/php/74/include/php/ext/date/lib]
--ldflags []
--libs [-lcrypt -lresolv -lcrypt -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt ]
--extension-dir [/opt/php/74/extension]
--include-dir [/opt/php/74/include/php]
--man-dir [/opt/php/74/php/man]
--php-binary [/opt/php/74/bin/php]
--php-sapis [ cli phpdbg cgi]
--ini-path [/opt/php/74/lib]
--ini-dir []
--configure-options [--prefix=/opt/php/74]
--version [7.4.3]
--vernum [70403]
完事。