简体   繁体   English

PHP无法在Amazon EC2微实例上运行MYSQLI函数

[英]PHP unable to run MYSQLI functions on Amazon EC2 micro instance

Ugh, I'm running into some real trouble with my Amazon micro instance. 呃,我的亚马逊微实例遇到了一些麻烦。 I'm just now implementing a PHP <-> MYSQL interface. 我刚刚实现了PHP < - > MYSQL接口。 The instance seems to be reporting that the MYSQLI plugin is not installed, however, all other indications are contrary. 该实例似乎报告未安装MYSQLI插件,但是,所有其他指示都是相反的。 I've exhausted my patience with searching and will now appeal to the higher intellect of the internet as a whole. 我已经厌倦了对搜索的耐心,现在将吸引整个互联网的更高智慧。 Thanks for looking! 谢谢你的期待!

My Code: 我的代码:

<?php
    error_reporting(E_ALL);
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    $mysql = mysqli_connect( 'localhost', 'EulerPhpUser', '*********' );
    // more code

error message: Fatal error: Call to undefined function mysqli_connect() in /var/www/html/euler/login.php on line 27 错误消息: 致命错误:在第27行的/var/www/html/euler/login.php中调用未定义的函数mysqli_connect()

$ cat /etc/*-release
Amazon Linux AMI release 2013.03

Here's the portion of my php.ini file 这是我的php.ini文件的一部分

; Maximum number of links.  -1 means no limit.
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.max-links
mysqli.max_links = -1

; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-port
mysqli.default_port = 3306

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-socket
mysqli.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-host
mysqli.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-user
mysqli.default_user =

; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
; http://www.php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-pw
mysqli.default_pw =

; Allow or prevent reconnect
mysqli.reconnect = Off

This is the only section of the phpifo() where my search for mysqli yielded results 这是phpifo()的唯一部分,我搜索mysqli产生了结果

Configure Command 
'./configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-amazon-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--with-t1lib=/usr' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-sqlite' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--with-mhash' '--with-apxs2=/usr/sbin/apxs' '--libdir=/usr/lib64/php' '--enable-pdo=shared' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/lib64/mysql/mysql_config' '--with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config' '--with-pdo-sqlite=shared,/usr' '--without-gd' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-xmlreader' '--disable-xmlwriter' '--without-sqlite3' '--disable-phar' '--disable-fileinfo' '--disable-json' '--without-pspell' '--disable-wddx' '--without-curl' '--disable-posix' '--disable-sysvmsg' '--disable-sysvshm' '--disable-sysvsem' 

Finally, one other thing to note. 最后,还有一点需要注意。 I tried to run the following code, and the server returns a completely blank page back. 我试图运行以下代码,服务器返回一个完全空白的页面。 No errors, no nothing. 没有错误,没有任何错误。 As if php crashed without generating an error. 好像php崩溃而没有产生错误。 I'm not sure how to interpret that. 我不确定如何解释。

if (function_exists('mysqli_connect')) {
     echo 'mysqli is installed';
} 

I even got so frustrated that I tried some PDO, but then got error Connection failed: could not find driver 我甚至非常沮丧,我尝试了一些PDO,但后来得到错误连接失败:找不到驱动程序

Please advise if any further info is requested and I'll promptly provide it. 如果有任何进一步的信息请告知我们,我会及时提供。 Thank you for the help 感谢您的帮助

In AWS, I got this error and found that I needed to run "yum install php-mysqli". 在AWS中,我收到此错误,发现我需要运行“yum install php-mysqli”。 This is in addition to the mysql and php packages. 这是mysql和php包的补充。

UPDATE: 更新:

Up to where I understand your PHP installation was compiled with mysqli support but the module is not enabled. 直到我理解你的PHP安装是用mysqli支持编译的,但模块没有启用。 Why? 为什么? Because you specify that the only reference to mysqli in the phpinfo() is the Configure Command . 因为您指定phpinfo()mysqli的唯一引用是Configure Command Should it be enabled, a table like 它应该启用,像一个表 这个 should show up. 应该出现。

So, maybe, you simply didn't uncomment the extension line in your php.ini file: 所以,也许,你根本没有取消注释php.ini文件中的扩展行:

extension=mysqli.so

Initial post: 最初的帖子:

According to the official docummentation : 根据官方文件

To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. 要检查系统是否正在使用配置文件,请尝试检索cfg_file_path配置设置的值。 If this is available, a configuration file is being used. 如果可用,则使用配置文件。

In other words, you could check if your php.ini file is being taken into account (it may be in a wrong path). 换句话说,您可以检查您的php.ini文件是否被考虑在内(它可能在错误的路径中)。 Try: 尝试:

<?php echo 'Configuration file (php.ini) path: ', get_cfg_var('cfg_file_path');

If you have installed php 7.1, eg 如果您已安装php 7.1,例如

sudo yum install php71

You will also need to install mysqli separately, eg 您还需要单独安装mysqli,例如

sudo yum install php71-mysqli

Do not run 别跑

sudo yum install php-mysqli

As this will install php 5 因为这将安装PHP 5

I can confirm this error on Amazon Linux upgrading PHP from 5.3 to 5.6. 我可以在Amazon Linux上将PHP从5.3升级到5.6来确认此错误。

There is no php56-mysqli package. 没有php56-mysqli包。 There is php56-mysqlnd , which I had installed. 我安装了php56-mysqlnd php-mysqli was the 5.3 version [on AWS Linux]. php-mysqli是[在AWS Linux上]的5.3版本。

The problem turned out to be that the installer left some PHP 5.3 pieces behind, notably /usr/bin/php (!). 结果问题是安装程序遗留了一些PHP 5.3,特别是/usr/bin/php (!)。

To correct this problem, run: 要解决此问题,请运行:

$ alternatives --force --refresh php

Flag --force is needed to make alternatives overwrite files left where the links should have been. 标记--force需要使alternatives覆盖链接本应存在的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM