环境
- CentOS 7.4
- PHP 7.1.12 编译安装
复现
代码语言:javascript
复制
/usr/local/php71/bin/php -r "ftp_ssl_connect('server1.example.com');"
PHP Fatal error: Uncaught Error: Call to undefined function ftp_ssl_connect() in Command line code:1
原因
看文档:ftp_ssl_connect | php.net
- ftp 扩展没配置
- opensll 没有启用
解决方案
代码语言:javascript
复制
# /root/php-7.1.12/ is php source dir
cd /root/php-7.1.12/ext/ftp//usr/local/php71/ is php dir
/usr/local/php71/bin/phpize
the param --with-openssl-dir is very important
./configure --with-php-config=/usr/local/php71/bin/php-config --with-openssl-dir
make
make installvim /usr/local/php71/lib/php.ini
add last line
extension=ftp.so
service php-fpm reload
这要注意一定要加上 --with-openssl-dir
,不然会 FTPS support => disabled
。
当不清楚 ./configure
有什么参数时,可以执行 ./configure --help
。
检查
代码语言:javascript
复制
# method 1
/usr/local/php71/bin/php -r "phpinfo();" | grep FTPFTP support => enabled
FTPS support => enabledmethod 2
/usr/local/php71/bin/php -r "ftp_ssl_connect('server1.example.com');"
PHP Warning: ftp_ssl_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1
References
- Fatal error: Call to undefined function ftp_ssl_connect() | stackoverflow
– EOF –
- # php