php 调用未定义的函数 curl_init() 即使它在 php7 中启用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34842596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined function curl_init() even it is enabled in php7
提问by Sabri Karag?nen
I've just installed php7 to my Ubuntu. At first, there was no problem, my web site was working. But suddenly, it started to return Call to undefined function curl_init() error. Now, my pages contain curl codes do not work.
我刚刚在我的 Ubuntu 上安装了 php7。起初,没有问题,我的网站正在运行。但是突然,它开始返回 Call to undefined function curl_init() 错误。现在,我的页面包含 curl 代码不起作用。
In phpinfo(), it looks Curl is enabled. There were similar questions but none of them handled it in php7. I thought it should be something different than others.
在 phpinfo() 中,看起来 Curl 已启用。有类似的问题,但没有一个在php7中处理过。我认为它应该与其他人不同。
Edit: When I try
编辑:当我尝试
php -i | grep curl
in terminal, it returns
在终端,它返回
/etc/php/7.0/cli/conf.d/20-curl.ini,
curl
回答by Deus777
I've had similar problem with curl after upgrade to XX (16.04). After reinstalling curl with:
升级到 XX (16.04) 后,我遇到了类似的 curl 问题。重新安装 curl 后:
sudo apt-get install php-curl
And server restart
然后服务器重启
sudo service apache2 restart
everything went back to normal :)
一切恢复正常:)
回答by ultrajohn
Assumption
假设
You've installed the version of the module for the PHP version you are using, and yet the problem is not going away.
您已经为您使用的 PHP 版本安装了模块的版本,但问题并没有消失。
What is going on here?
这里发生了什么?
There could be multiple versions of PHP installed on your system and Apache is not using the version you are expecting it to use.
您的系统上可能安装了多个版本的 PHP,而 Apache 没有使用您希望它使用的版本。
How do you know which version of PHP Apache is using?
您如何知道 Apache 使用的是哪个版本的 PHP?
To know this, the key idea is to learn the ROOT directory of your Apache's configuration files. In the command line, you can type:
要知道这一点,关键思想是了解 Apache 配置文件的 ROOT 目录。在命令行中,您可以键入:
apache2ctl -V //sample output below
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 15 2016 15:34:04
Server's Module Magic Number: 20120211:27
Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"
In my case, my Apache's ROOT configuration directory is shown in the
就我而言,我的 Apache 的 ROOT 配置目录显示在
HTTPD_ROOT="/etc/apache2"
Now that I know the location of the configs that Apache is using, I can now accurately determine the version of PHP it is using by examining the "mods-enabled"
directory located inside the "/etc/apache2"
directory.
现在我知道了 Apache 正在使用的配置的位置,我现在可以通过检查"mods-enabled"
位于"/etc/apache2"
目录中的目录来准确地确定它正在使用的 PHP 版本。
In my case, when do an ls
while inside the "mods-enabled"
, it showed the ff output:
在我的例子中,当ls
在里面做一段时间时"mods-enabled"
,它显示了 ff 输出:
access_compat.load authz_user.load filter.load php5.load
...
authz_host.load env.load php5.conf
At this point, I now know for certain that Apache is using the 'php5'
version of PHP installed on my system, whatever that may be.
在这一点上,我现在肯定知道 Apache 正在使用'php5'
我系统上安装的 PHP 版本,无论是什么版本。
Then I tried to reproduce the error above using this version of PHP (i.e., 'php5'
) by running the command below:
然后我尝试'php5'
通过运行以下命令使用此版本的 PHP(即)重现上述错误:
$ php5 -r "curl_init();"
PHP Fatal error: Call to undefined function curl_init() in Command line code on line 1
Voila!
瞧!
The version of PHP that I expected my Apache was using is "php5.6"
and running the same command above with this version did not produce the said error.
我期望我的 Apache 使用的 PHP 版本是,"php5.6"
并且在这个版本上运行上面相同的命令没有产生上述错误。
Solution
解决方案
To solve this problem, you either install the version of the module that corresponds to the PHP version that Apache is using (in my example php5.0-curl) or you may change the version of PHP that is being used in Apache to the version you want.
要解决此问题,您可以安装与 Apache 使用的 PHP 版本相对应的模块版本(在我的示例中为 php5.0-curl),或者您可以将 Apache 中使用的 PHP 版本更改为该版本你要。
How do I tell Apache which version of PHP to use?
如何告诉 Apache 使用哪个版本的 PHP?
You can accomplish this using the a2enmod/a2dismod
cli commands of Apache2.
您可以使用a2enmod/a2dismod
Apache2的cli 命令完成此操作。
Firstly, I disable the PHP module that is currently active on my server (i.e., "php5"
):
首先,我禁用了当前在我的服务器上处于活动状态的 PHP 模块(即"php5"
):
a2dismod php5
Then I enabled the php module for the version of PHP that I want my Apache to use:
然后我为我希望我的 Apache 使用的 PHP 版本启用了 php 模块:
a2enmod php5.6
Then I restart Apache
然后我重新启动Apache
service apache2 restart
After I refreshed the offending page on my website, the error is now gone.
在我刷新网站上有问题的页面后,错误消失了。
回答by Sheraz Ahmed
I did all of the above but did not solve the problem.
我做了以上所有但没有解决问题。
Env:Ubuntu, php7.1, Laravel 5.6
环境:Ubuntu、php7.1、Laravel 5.6
Solution
解决方案
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.1-curl
回答by Kevin Hill
For me, the resolution was to update apt-get with the following command, and then install php7.0-curl.
对我来说,解决方法是使用以下命令更新apt-get,然后安装php7.0-curl。
sudo add-apt-repository ppa:ondrej/php
回答by leopold
Your Filepath is probably incorrect
您的文件路径可能不正确
Check the Apache error log in
检查Apache错误日志
/var/log/apache2/error.log
if the called path or filename does match your real path in e.g.
如果被调用的路径或文件名与您的真实路径匹配,例如
/usr/lib/php/20151012/php_curl.so
In my case it's been the same path, but "the php_" was missing
在我的情况下,它是相同的路径,但缺少“php_”
/usr/lib/php/20151012/curl.so
So I changed the path / filename accordingly in
所以我相应地更改了路径/文件名
/etc/php/7.0/cli/conf.d/20-curl.ini
from
从
extension=php_curl.so
into
进入
extension=curl.so
回答by Prabhu Nandan Kumar
I know its very late answer but I think its useful because I faced same issue and tried all above given solution but not worked. Then I hit following command and now working perfectly :
我知道它的答案很晚,但我认为它很有用,因为我遇到了同样的问题并尝试了上述所有给定的解决方案但没有奏效。然后我点击了以下命令,现在工作正常:
apt-get install php7.0-curl
回答by symcbean
Your pages probably are not generated with the CLI SAPI. Check what phpinfo() returns when run from your webserver (its probably trying to read the wrong ini file).
您的页面可能不是使用 CLI SAPI 生成的。检查从您的网络服务器运行时 phpinfo() 返回的内容(它可能试图读取错误的 ini 文件)。
回答by Mustak_Talukder
ubuntu 18.04 php 7.4
Ubuntu 18.04 php 7.4
if you have PHP old version and the new version as well as. you need to disable old curl mode so that. follow the steps.
如果您有 PHP 旧版本和新版本以及。您需要禁用旧的卷曲模式,以便。按照步骤。
sudo a2dismod php7.1 (your old version)
sudo a2endmod php7.4 (your new version)
sudo service apache2 restart
sudo systemctl restart apache2
sudo a2dismod php7.1 (your old version)
sudo a2endmod php7.4 (your new version)
sudo service apache2 restart
sudo systemctl restart apache2
it works for me.
这个对我有用。
回答by DomeDan
Scratched my head over this for a while, curl module was loaded but still got the error.
This happen after I upgraded from Debian Stretch to Buster.
我为此抓了一阵子,curl 模块已加载,但仍然出现错误。
这是在我从 Debian Stretch 升级到 Buster 之后发生的。
The reason was that php7.3-curl was installed and used, but apache run php7.0 even though 7.3 was installed. So I removed php7.0 and reinstalled libapache2 to get it working
原因是安装并使用了 php7.3-curl,但 apache 运行 php7.0 即使安装了 7.3。所以我删除了 php7.0 并重新安装了 libapache2 以使其正常工作
apt-get remove php-7.0
apt-get remove libapache2-mod-php7.3
apt-get install libapache2-mod-php7.3
回答by Mark Wandatha
- step 1 : Download Php 7,
- step 2 : copy libeay32.dll and ssleay32.dll and past them in C:\Windows\System32.
- step 3 : Replace the php_openssl.dll and php_curl.dll in C:\php\ext with the latest dll. restart apache
- 第 1 步:下载 PHP 7,
- 第 2 步:复制 libeay32.dll 和 ssleay32.dll 并将它们粘贴到 C:\Windows\System32 中。
- 第 3 步:将 C:\php\ext 中的 php_openssl.dll 和 php_curl.dll 替换为最新的 dll。重启阿帕奇
This fixed my issues issue, hope someone benefits too
这解决了我的问题,希望有人也受益