无法使用编译后的 php 的 ssl 连接到 mysql

无法使用编译后的 php 的 ssl 连接到 mysql

我已经绞尽脑汁好几天了。我就是想不通。

我使用 plesk 12 和 apache 2.2 运行 ubuntu 12。

我尝试使用以下两个选项的变体编译了 PHP 5.6.10 和 PHP 5.6.11:

./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.";
?>

注意:我也无法使用 phpmyadmin 连接到使用 mysqli 查询而不是 mysql_connect 的 SSL,所以它并不是一个弃用的东西。

当我运行 phpinfo 时,一切似乎都很好:

OpenSSL support enabled  
OpenSSL Library Version OpenSSL 1.0.1 14 Mar 2012  
OpenSSL Header Version  OpenSSL 1.0.1 14 Mar 2012  

但是当我从控制台检查 PHP 模块(ubuntu 包)时,一切正常:

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

答案1

我认为连接localhost默认使用 Unix 套接字,而不是 TCP。然后 SSL 可能根本不受支持。至少对于使用原始 MySQL 库的实现来说是这样:从手动的

在 Unix 上,MySQL 程序将主机名本地主机具体来说,与其他基于网络的程序相比,这种方式可能与您预期的不同。对于与 localhost 的连接,MySQL 程序尝试使用 Unix 套接字文件连接到本地服务器。即使给出了 --port 或 -P 选项来指定端口号,也会发生这种情况。

不要使用 localhost,而要使用正确的主机名或 IP 地址来强制建立 TCP 连接。这需要配置 MySQL 服务器以支持“远程”网络连接,并且要授予正确的 ACL 访问权限。

无论如何,使用 TLS 连接到本地主机上的服务在我看来完全是浪费资源……

相关内容