10

I wanted to get the settings of the current installed PHP on my server. I don't want to have the settings of PHP(.ini) itself, I need the /configure parameters how the PHP is currently installed. E.g. the values of --prefix or --includedir or --sysconfdir of my currently PHP ...

Edit: I know that phpinfo() will output the settings but on my server isn't a Configure Command field with the information! How do I get these information?

Edit #2: Does nobody understand what I want to know or is my answer really that bad that I get so much downvotes? A common use to install PHP is like that:

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

I didn't installed the current PHP5.2 on the server so I don't know how it was configurated during installation and I need/want to know what were the settings to install PHP5.3 like the current 5.2 to have a high chance to get all my websites working without any trouble.

hakre
  • 193,403
  • 52
  • 435
  • 836
Poru
  • 8,254
  • 22
  • 65
  • 89

5 Answers5

11

You are looking for the php-config command. Running this will spit out everything PHP knows about it's installation and creation. Specifically, the following flags will tell you about the compilation of the php binary.

--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

The command only accepts one flag at a time, so it may be better to run it without flags.

Example output:

$ 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]

Where the bit after each Option in the list isn't just an example output, it's the actual value; it is what you get if you call php-config with that option. E.g.

$ php-config --prefix
/usr
Community
  • 1
  • 1
Mario Haubenwallner
  • 1,835
  • 1
  • 17
  • 21
  • 1
    This was a great find and very helpful to me. I hope you don't mind that I added some details to your answer. – Patrick M Mar 28 '18 at 22:01
10

You've said that your output from phpinfo() / php -i doesn't have a Configure Command section. Can you post the output of php -i | head -n 10 ?

EDIT:

Based on your comment that states PHP Version => 5.2.4-2ubuntu5.23, it seems you're running Ubuntu. I found the list of which versions of Ubuntu include which version of PHP here, which implies you're running Hardy Heron. I found details of the particular source package here, and the upload date corresponds to the build date that you see in your output of php -i. Since you're running a 64-bit version of the package, the complete Ubuntu buildlog can be found here (warning: LONG). Scrolling through that you can find the configure commands for the apache2 build on line 1815, the cgi build on line 6170 and the cli build on line 9164. To save you some scrolling, here's the command for the apache2 build (i.e. the package 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
nickgrim
  • 5,387
  • 1
  • 22
  • 28
  • The output: `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` – Poru Mar 01 '12 at 20:52
  • I've updated my answer with references to the Ubuntu buildlog. – nickgrim Mar 03 '12 at 18:04
  • @MarioHaubenwallner your comment should be an answer. – Phil Mar 02 '18 at 05:56
3

You can use phpinfo()

phpinfo — Outputs information about PHP's configuration

<?php
phpinfo();
?>

You could run php -i from the command-line and see if you get different results. Even though

php -i calls phpinfo(), and prints out the results,

the results may differ from <?php phpinfo() ?> since the command-line may have it's own php.ini.

sshow
  • 8,820
  • 4
  • 51
  • 82
3
<?php phpinfo(); ?>

The phpinfo() function will give you all the settings you're looking for, formatted as HTML.

WWW
  • 9,734
  • 1
  • 29
  • 33
1

Use this to get the settings:

<?php
phpinfo();
?>
Andy
  • 49,085
  • 60
  • 166
  • 233