php-config Command in Linux



The php-config command in Linux retrieves information about PHP installation and configuration. It is beneficial for developers when compiling PHP extensions or troubleshooting.

Table of Contents

Here is a comprehensive guide to the options available with the php-config command −

Installation of php-config Command in Linux

The php-config is a PHP-based tool that requires a PHP development package. To use php-config, the php-dev package must be installed on Linux.

To install it on Ubuntu, Kali Linux, Raspberry Pi OS, Debian, and all Debian-based distributions, use the command given below −

sudo apt install php8.3-dev

To install it on Fedora, use the following command −

sudo dnf install php-devel

To verify the installation, check the version of the php-config command −

php-config --version

Syntax of php-config Command

The syntax of the php-config command in Linux is as follows −

php-config [options]

The [options] field in the above syntax is used to specify various options (mentioned in the next section) to modify the command’s response.

php-config Command Options

The options of the Linux php-config command are listed below −

Option Description
--prefix Directory where PHP is installed.
--includes Include paths for header files.
--ldflags Linker flags used during PHP compilation.
--libs Additional libraries used during compilation.
--man-dir Manpages installation directory.
--extension-dir Default directory for PHP extensions.
--include-dir Default directory for header files.
--php-binary Path to the PHP CLI/CGI binary.
--php-sapis Installed Server APIs (SAPI modules).
--configure-options Configuration options used to compile PHP.
--version Installed PHP version.
--vernum PHP version as an integer value.

Examples of php-config Command in Linux

In this section, the usage of the php-config command in Linux will be discussed with examples −

  • Displaying PHP Installation Directory Prefix
  • Displaying Include Paths
  • Displaying Linker Flags
  • Displaying Additional Libraries
  • Displaying the Extension Directory
  • Displaying the Path of PHP Header Files
  • Displaying the Path of PHP Binary
  • Listing Installed Server APIs
  • Printing PHP Version as an Integer
  • Displaying Usage Help and Configuration

Display PHP Installation Directory Prefix

To display the PHP installation directory (/usr/local) prefix, use the --prefix option with the php-config command −

php-config --prefix
php-config Command in Linux1

The above command indicates the base installation directory, which is useful when locating PHP binaries, libraries, or configuration files.

Display Include Paths

To list include paths containing header files necessary for PHP development, use the --includes option −

php-config --includes
php-config Command in Linux2

It is useful during PHP extension or application compilation to include the correct PHP headers.

Display Linker Flags

It is important to know the linker flag to develop links against the correct libraries when building custom PHP extensions. To display it, use the --ldflags option −

php-config --ldflags
php-config Command in Linux3

The linker is a tool that combines object files, libraries, and other resources into a single, executable binary or shared library. Linker flags guide this process by specifying additional settings, paths, or behaviors.

Display Additional Libraries

To list extra libraries linked during PHP compilation, use the --libs option with php-config −

php-config --libs
php-config Command in Linux4

Display Extension Directory

To display the extension directory where PHP extensions are located, use the --extension-dir option −

php-config --extension-dir
php-config Command in Linux5

Display Path of PHP Header Files

To display the path of the directory where PHP header files are stored, use the --include-dir options −

php-config --include-dir
php-config Command in Linux6

Display Path of PHP Binary

To display the path of the PHP binary, use the --php-binary option −

php-config --php-binary
php-config Command in Linux7

Listing Installed Server APIs

To list the installed server APIs, use the --php-sapis option with the php-config command −

php-config --php-sapis
php-config Command in Linux8

Print PHP Version as Integer

To display the PHP version as an integer, use the --vernum option −

php-config --vernum
php-config Command in Linux9

Display Usage Help and Configuration

To display the entire PHP configuration along with usage help, execute the php-config command without any option −

php-config
php-config Command in Linux10

Conclusion

The php-config command is a powerful tool in Linux that provides detailed information about PHP installation and configuration, helping in tasks like compiling extensions or troubleshooting. This guide covers its installation, syntax, options, and usage examples.

The php-config utility provides access to vital details, such as the PHP version, installation paths, include directories, libraries, and configuration settings, ensuring streamlined PHP development and management.

In this tutorial, we covered the php-config command, its installation, syntax, options, and usage in Linux with examples.

Advertisements