2013-07-01 48 views
3

呃,我遇到了一些与我的Amazon微型实例有关的实际麻烦。我刚刚实现了一个PHP < - > MYSQL接口。该实例似乎报告说MYSQLI插件没有安装,但是,所有其他指示都是相反的。我已经用尽了搜索的耐心,现在将吸引整个互联网更高的智慧。感谢您的期待!PHP无法在Amazon EC2微型实例上运行MYSQLI函数

我的代码:

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

错误消息:致命错误:调用到/var/www/html/euler/login.php未定义功能mysqli_connect()第27行

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

这里是我的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 

这是个e仅在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' 

最后还有一件事要注意。我试着运行下面的代码,服务器返回一个完全空白的页面。没有错误,没有任何东西。就像php崩溃没有产生错误。我不知道如何解释。

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

我甚至有这么沮丧,我尝试了一些PDO,但后来遇到错误连接失败:找不到驱动程序

请告知,如果任何进一步的信息请求,我会及时提供它。感谢您的帮助

+0

你有没有启用php.ini中的mysqli扩展? – crush

+0

我的php.ini文件中有“mysqli”的部分贴在上面。 – travish82

+0

如果可以的话,我会关闭这个问题,但Stack Overflow似乎并不希望让他们的站点直观或用户友好,所以我没有动力去努力找出如何做到这一点。 – travish82

回答

2

UPDATE:

最多的地方,我理解你的PHP安装编译与mysqli支持,但该模块未启用。为什么?因为您指定phpinfo()中唯一对mysqli的引用是Configure Command。如果启用,应该显示如this one 这样的表格。

所以,也许,你根本就没有取消对延长线的php.ini文件:

extension=mysqli.so 

战后初期:

按照official docummentation

To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.

换句话说,你可以检查你的php.ini文件是否被考虑在内(可能是错误的路径) 。尝试:

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

输出: 配置文件(php.ini)路径:/etc/php.ini 它指向那里,我可以确认这是文件所在的位置。 '$ cd/etc [ec2-user @ * etc] $ ls | grep的PHP php.d 的php.ini PHP-zts.d [EC2用户@ IP-10-253-73-35等] $' 哇..不得不“降价有什么要命笨的方法“评论......它说最后有两个空格的分界线。 nope – travish82

+0

我更新了我的答案。 –

+0

这很有道理。我检查了php.ini文件,确实没有行:'extension = php_mysqli.dll'。我加入并重新启动httpd,但无济于事。没有出现MYSQLI的phpinfo()缺失部分。我将检查一些其他默认php.ini文件的差异。与此同时,你可以看到我的信息文件[在这里](http://www.travishoward.net/info.php),和我的php.ini文件的副本[在这里(有评论)](http:// www.travishoward.net/php.ini.full.html)或[here(without)](http://www.travishoward.net/php.ini.html)感谢您的持续帮助。 – travish82

7

在AWS中,我得到了这个错误,发现我需要运行“yum install php-mysqli”。这是除了mysql和php包之外的。

0

如果你已经安装了php 7。1,如

sudo yum install php71 

您还需要单独安装mysqli的,如

sudo yum install php71-mysqli 

不要运行

sudo yum install php-mysqli 

由于这将安装PHP 5