2015-07-10 155 views
1

现在,我一直在墙壁上撞我的头几天。我只是不知道。使用SSL时无法连接到MySQL

我已经编译PHP 5.6.10和5.6.11 PHP这些选项:

./configure --prefix=/opt/php-5.6.11-apache --with-config-file-path=/opt/php-5.6.11-apache/etc --disable-debug --enable-roxen-zts --enable-short-tags --enable-magic-quotes --enable-sigchild --enable-libgcc --with-libdir=/lib/x86_64-linux-gnu --with-openssl --with-openssl-dir=/usr/bin --with-zlib --enable-bcmath --with-bz2 --enable-calendar --enable-ctype --with-curl=/usr/bin --with-cdb --enable-inifile --enable-flatfile --enable-dba --with-xsl --enable-dom --enable-exif --enable-filter --enable-ftp --with-gd --with-png-dir=/usr --with-jpeg-dir=/usr --enable-gd-native-ttf --with-freetype-dir=/usr --with-gettext --with-gmp --enable-hash --with-iconv --with-imap --with-imap-ssl --with-kerberos --with-ldap --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-mcrypt=/usr --with-mhash --with-mysql --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysqli=mysqlnd --with-pgsql --with-unixODBC=/usr --with-sqlite --with-sqlite3=/usr --enable-pdo --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-odbc=unixODBC,/usr --with-pdo-sqlite=/usr --enable-phar --enable-posix --enable-session --with-mm --enable-shmop --enable-soap --with-xmlrpc --enable-libxml --enable-sockets --with-pspell --with-enchant --enable-intl --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-tokenizer --enable-wddx --enable-simplexml --enable-xml --enable-xmlreader --enable-xmlwriter --enable-zip --with-pear --with-pcre-regex --with-snmp --enable-json --enable-pcntl --enable-inline-optimization --enable-fileinfo --enable-zend-multibyte --enable-opcache --enable-cgi --with-apxs2=/usr/bin/apxs2 --disable-all 

我也曾尝试以下操作:

./configure --prefix=/opt/php-5.6.10 --with-config-file-path=/opt/php-5.6.10/etc --disable-debug --enable-roxen-zts --enable-short-tags --enable-magic-quotes --enable-sigchild --enable-libgcc --with-libdir=/lib/x86_64-linux-gnu --with-openssl --with-zlib --enable-bcmath --with-bz2 --enable-calendar --enable-ctype --with-curl --with-cdb --enable-inifile --enable-flatfile --enable-dba --with-xsl --enable-dom --enable-exif --enable-filter --enable-ftp --with-gd --with-png-dir=/usr --with-jpeg-dir=/usr --enable-gd-native-ttf --with-freetype-dir=/usr --with-gettext --with-gmp --enable-hash --with-iconv --with-imap --with-imap-ssl --with-kerberos --with-ldap --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pgsql --with-unixODBC=/usr --with-sqlite --with-sqlite3 --enable-pdo --with-pdo-mysql --with-pdo-pgsql --with-pdo-odbc=unixODBC,/usr --with-pdo-sqlite --enable-phar --enable-posix --enable-session --with-mm --enable-shmop --enable-soap --with-xmlrpc --enable-libxml --enable-sockets --with-pspell --with-enchant --enable-intl --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-tokenizer --enable-wddx --enable-simplexml --enable-xml --enable-xmlreader --enable-xmlwriter --enable-zip --with-pear --with-pcre-regex --with-snmp --enable-json --enable-pcntl --enable-inline-optimization --enable-fileinfo --enable-zend-multibyte --enable-opcache --enable-cgi --disable-all 

我不能用PHP连接MySQL SSL!

我收到以下错误:

PHP Warning: mysql_connect(): this stream does not support SSL/crypto in /xxxxx/test2.php on line 2 
PHP Warning: mysql_connect(): Cannot connect to MySQL by using SSL in /xxxxx/test2.php on line 2 
PHP Warning: mysql_connect(): [2002] (trying to connect via unix:///var/run/mysqld/mysqld.sock) in /xxxxx/test2.php on line 2 

test2.php包含以下内容:

<?php 
$link = mysql_connect("localhost","axxxx5","Jxxxxxxxxse",false,MYSQL_CLIENT_SSL) 
     or die(mysql_error()); 
$res = mysql_query("SHOW STATUS LIKE 'ssl_cipher';",$link); 
print_r(mysql_fetch_row($res)); 
echo "Finished."; 
?> 

当我跑的phpinfo,一切似乎很动听:

  • OpenSSL的支持启用
  • OpenSSL Library Version Op enSSL 1.0.1 2012年3月14日
  • OpenSSL的头版本的OpenSSL 1.0.1 2012年3月14日

但是,当我使用命令行工具检查,一切正常:

$ php /xxx/test2.php 
Array (
    [0] => Ssl_cipher 
    [1] => AES256-SHA) Finished 
+1

我认为你必须使用mysqli或PDO ...我相信mysql_connect已被弃用 – BK435

+0

Stack Overflow是一个编程和开发问题的网站。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[超级用户](http://superuser.com/)或[服务器故障](http://serverfault.com/)会是一个更好的地方。另请参阅[我在哪里发布有关Dev Ops的问题?](http://meta.stackexchange.com/q/134306)。 – jww

+0

@jww,当然,从这样的PHP应用程序连接到MySQL的问题是关于编程或开发的,不是吗? – Bruno

回答

2

当您连接到localhost

<?php mysql_connect("localhost",...) 

如果这样的链接是可用的,在本地套接字通信转变

mysql_connect(): [2002] (trying to connect via unix:/// (...) 

事实上,这样一个链接“不支持SSL /加密”(加密本地通信通道没什么意义)。

要绕过此优化并强制通过TCP/IP进行通信,请连接到127.0.0.1

+1

是的,远离这个过时的'mysql_ *'扩展名。 – RandomSeed