我在Linux上运行mysql-56.6.23、php-56.6.7和httpd-2.4.12,并试图查看phpinfo()是否显示了我在php.ini主文件中指定的正确的自定义mysql套接字文件位置:
mysql.default_socket = /home/stephane/programs/mysql/install/tmp/mysql.sock
但即使在服务器重新启动后,phpinfo()仍会继续显示股票价值:
MYSQL_SOCKET /tmp/mysql.sock
以下是我如何编译这些软件的。
对于PHP:
./configure
--prefix=/home/stephane/programs/install
--with-apxs2=/home/stephane/programs/install/apache/bin/apxs
--with-config-file-path=/home/stephane/programs/php-5.6.7
--enable-libgcc
--with-mysql=/home/stephane/programs/mysql/install
--with-zlib-dir=/usr
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-gd
--enable-gd-native-ttf
--with-freetype-dir=/usr
--enable-ftp
--enable-xml
--enable-zip
--with-bz2
--enable-wddx
--without-pear
--enable-mbstring
--with-curl
对于MySQL:
cmake
-DCMAKE_INSTALL_PREFIX=/home/stephane/programs/mysql/install
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/home/stephane/programs/mysql/install/data
scripts/mysql_install_db
--no-defaults
--explicit_defaults_for_timestamp
--basedir=/home/stephane/programs/mysql/install
--datadir=/home/stephane/programs/mysql/install/data
--tmpdir=/home/stephane/programs/mysql/install/tmp
--lc-messages-dir=/home/stephane/programs/mysql/install/share
我不打算使用变通方法,比如在连接语句中指定套接字文件的位置。
我试图了解如何正确使用php.ini文件中的mysql.default_socket指令。
更新:是不是phpinfo()函数显示的MYSQL_SOCKET值不是从php.ini文件中获取的,而是从编译MYSQL时设置的编译时选项中获取的?
所以这次我尝试使用以下选项编译MySQL:-DMYSQL_UNIX_ADDR=/home/stephane/programs/mysql/install/tmp/mysql.sock
如:cmake\
-DCMAKE_INSTALL_PREFIX=/home/stephane/programs/mysql/install
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/home/stephane/programs/mysql/install/data
-DMYSQL_UNIX_ADDR=/home/stephane/programs/mysql/install/tmp/mysql.sock
但是在重新编译PHP并重新启动Apache之后,MYSQL_SOCKET值仍然不是自定义位置值。
此外,这给我留下了一个问题,为什么有两种不同的方式来表达自定义MySQL套接字位置,以及MySQL_socket用于什么。
您需要在适当的php.ini
文件中声明mysql.default-socket。我觉得您更改的文件负责控制台运行php配置。
查看phpinfo()
的顶部,了解web服务器的php.ini文件从何处加载。应在Loaded Configuration File
行中。
更新:根据注释,假设您在正确的文件中设置了配置,您应该检查php/webserver是否对/home/stephane/programs/mysql/install/tmp/mysql.sock
位置有读/写访问权限。也许这就是您的配置被默认值覆盖的原因。