【问题标题】:Get current PHP install settings获取当前 PHP 安装设置
【发布时间】:2012-03-20 05:28:09
【问题描述】:

我想在我的服务器上获取当前安装的 PHP 的设置。我不想拥有 PHP(.ini) 本身的设置,我需要 /configure 参数当前如何安装 PHP。例如。我当前 PHP 的 --prefix--includedir--sysconfdir 的值...

编辑: 我知道phpinfo() 将输出设置,但在我的服务器上不是带有信息的Configure Command 字段!我如何获得这些信息?

编辑#2: 没有人明白我想知道什么,或者我的回答真的那么糟糕以至于我得到了如此多的反对意见吗? 安装 PHP 的一个常见用法是:

./configure --prefix=/usr/share/php5\
 --with-libdir=lib64\
 --includedir=/usr/include\
 --enable-libxml\
 --enable-session
[...]

我没有在服务器上安装当前的 PHP5.2,所以我不知道它在安装过程中是如何配置的,我需要/想知道安装 PHP5.3 的设置是什么,就像当前的 5.2 一样很有可能让我的所有网站顺利运行。

【问题讨论】:

标签: php installation


【解决方案1】:

您正在寻找php-config 命令。运行它会吐出 PHP 所知道的关于它的安装和创建的所有信息。具体来说,以下标志将告诉您有关 php 二进制文件的编译。

--prefix  Directory prefix where PHP is installed, e.g. /usr/local

--ldflags LD Flags which PHP was compiled with

--libs    Extra libraries which PHP was compiled with

--configure-options   Configure options to recreate configuration of current 
          PHP installation

该命令一次只接受一个标志,因此最好不带标志运行它。

示例输出:

$ php-config
Usage: /usr/bin/php-config [OPTION]
Options:
  --prefix            [/usr]
  --includes          [-I/usr/include/php ...snip ]
  --ldflags           []
  --libs              [-lcrypt   -lresolv -lcrypt ...snip ]
  --extension-dir     [/usr/lib64/php/modules]
  --include-dir       [/usr/include/php]
  --man-dir           [/usr/share/man]
  --php-binary        [/usr/bin/php]
  --php-sapis         [cli cgi]
  --configure-options [--build=x86_64-redhat-linux-gnu --host= ...snip]
  --version           [5.3.29]
  --vernum            [50329]

列表中每个Option 之后的位不仅仅是一个示例输出,它是实际值;如果您使用该选项致电php-config,这就是您所得到的。例如

$ php-config --prefix
/usr

【讨论】:

  • 这是一个很棒的发现,对我很有帮助。希望您不介意我在您的回答中添加了一些细节。
【解决方案2】:

您说过您来自phpinfo() / php -i 的输出没有配置命令 部分。你能发布php -i | head -n 10的输出吗?

编辑

根据您对PHP Version => 5.2.4-2ubuntu5.23 的评论,您似乎正在运行 Ubuntu。我找到了哪些 Ubuntu 版本的列表包含了哪个版本的 PHP here,这意味着您正在运行 Hardy Heron。我找到了特定源包here 的详细信息,上传日期对应于您在php -i 的输出中看到的构建日期。由于您运行的是 64 位版本的软件包,因此可以在 here 找到完整的 Ubuntu 构建日志(警告:LONG)。滚动浏览它,您可以在 1815 行找到 apache2 构建的 configure 命令,第 6170 行的 cgi 构建和第 9164 行的 cli 构建。为了节省一些滚动,这里是 apache2 构建的命令(即包libapache2-mod-php5):

    CFLAGS="-O2 -Wall -fsigned-char -fno-strict-aliasing   -gstabs" PROG_SENDMAIL="/usr/sbin/sendmail" ../configure \
    --prefix=/usr --with-apxs2=/usr/bin/apxs2 \
    --with-config-file-path=/etc/php5/apache2 \
    --with-config-file-scan-dir=/etc/php5/apache2/conf.d \
    --build=x86_64-linux-gnu --host=x86_64-linux-gnu --mandir=/usr/share/man --enable-memory-limit --disable-debug --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --with-pear=/usr/share/php --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-track-vars --enable-trans-sid --enable-bcmath --with-bz2 --enable-ctype --with-db4 --without-gdbm --with-iconv --enable-exif --enable-filepro --enable-ftp --with-gettext --enable-mbstring --with-pcre-regex=/usr --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-dbx --enable-soap --enable-zip --with-mime-magic=/usr/share/file/magic.mime --with-exec-dir=/usr/lib/php5/libexec --with-system-tzdata \
    --without-mm \
    --with-curl=shared,/usr \
    --with-zlib-dir=/usr \
    --with-gd=shared,/usr --enable-gd-native-ttf \
    --with-gmp=shared,/usr \
    --with-jpeg-dir=shared,/usr \
    --with-xpm-dir=shared,/usr/X11R6 \
    --with-png-dir=shared,/usr \
    --with-freetype-dir=shared,/usr \
    --with-ttf=shared,/usr \
    --with-t1lib=shared,/usr \
    --with-ldap=shared,/usr \
    --with-ldap-sasl=/usr \
    --with-mhash=shared,/usr \
    --with-mysql=shared,/usr \
    --with-mysqli=shared,/usr/bin/mysql_config \
    --with-pspell=shared,/usr \
    --with-unixODBC=shared,/usr \
    --with-recode=shared,/usr \
    --with-xsl=shared,/usr \
    --with-snmp=shared,/usr \
    --with-sqlite=shared,/usr \
    --with-mssql=shared,/usr \
    --with-tidy=shared,/usr \
    --with-xmlrpc=shared \
    --with-pgsql=shared,/usr PGSQL_INCLUDE=`pg_config --includedir` \
    --enable-pdo=shared \
    --without-pdo-dblib \
    --with-pdo-mysql=shared,/usr \
    --with-pdo-odbc=shared,unixODBC,/usr \
    --with-pdo-pgsql=shared,/usr/bin/pg_config \
    --with-pdo-sqlite=shared,/usr \
    --with-pdo-dblib=shared,/usr

【讨论】:

  • 输出:phpinfo() PHP Version => 5.2.4-2ubuntu5.23 System => Linux - dedicated 2.6.18-028stab092.1 #1 SMP Wed Jul 20 11:44:12 MSD 2011 x86_64 Build Date => Feb 11 2012 05:49:55 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini Scan this dir for additional .ini files => /etc/php5/cli/conf.d
  • 我已经参考 Ubuntu 构建日志更新了我的答案。
  • @MarioHaubenwallner 你的评论应该是一个答案。
【解决方案3】:

您可以使用phpinfo()

phpinfo — 输出 PHP 的配置信息

<?php
phpinfo();
?>

你可以从命令行运行php -i,看看你是否得到不同的结果。 虽然

php -i 调用 phpinfo(),并打印出结果,

结果可能与&lt;?php phpinfo() ?&gt; 不同,因为命令行可能有它自己的 php.ini。

【讨论】:

  • @Poru 您似乎无法掌握哪些具体设置?
  • 安装PHP的配置设置
【解决方案4】:

使用它来获取设置:

<?php
phpinfo();
?>

【讨论】:

    【解决方案5】:
    <?php phpinfo(); ?>
    

    phpinfo() 函数将为您提供所需的所有设置,格式为 HTML。

    【讨论】:

    • +1 您给出了相同的答案,但您提供了适量的信息。 :)
    猜你喜欢
    • 2018-09-06
    • 2013-02-26
    • 2013-04-24
    • 2011-01-05
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多