今天在调用php系统函数 easter_date()的过程中,本地没有问题,代码上传到服务器却报了个致命错误:调用未定义的函数 easter_date(),服务器是 Linux 环境。
网上搜了一下,发现问题是因为在安装编译php的过程中没有加–enable-calendar支持。
只能重新编译一下calendar模块了,这个时候我服务器已经编译安装了php,那么如何在增加calendar支持呢?其实很简单,把calendar当做一个扩展来重新编译一下,将生成的文件路径增加到php.ini文件中去即可。
操作步骤:
1. 首先去php官网下载和你当前php环境相同版本的php源码,查看当前php环境的版本可通过 php -v 命令查看。
php源码下载地址:https://www.php.net/downloads.php
2. 下载完毕解压下载到的源码包。
tar -zxvf php-7.2.29.tar.gz
进入编译目录
cd php-7.2.29/ext/calendar/
3. 开始编译安装
/usr/bin/phpize
#若不知道自己的phpize在哪里,可通过whereis phpize命令查找
./configure --with-php-config=/usr/local/php/bin/php-config
#若不知道php-config文件在哪,可通过find / -name 'php-config'查找
make && make install
以上操作完毕之后会显示出类似下面的提示:
Libraries have been installed in:
/home/yhm/php-7.2.29/ext/calendar/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
进入php安装目录(每个人的可能不一样)
cd /usr/local/php/etc
vim php.ini
#然后在配置文件里面添加
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/calendar.so"
然后重启php-fpm就行啦。