Current Location: Home> Latest Articles> php_uname() and phpinfo() to display system and environment details

php_uname() and phpinfo() to display system and environment details

M66 2025-05-18

In PHP, there are two very useful functions that help developers view the server's system and environment information, namely php_uname() and phpinfo() . These two functions provide developers with rich information about the current server's operating system, PHP configuration, extension and other information. Next, we will introduce in detail how these two functions are used and how to obtain this information through them.

1. Use the php_uname() function

The php_uname() function returns information about the operating system. It provides detailed information on the operating system name, version number, and machine architecture. Typically, this function is used to diagnose server environments and help developers understand which operating system their application runs on.

Sample code:

 <?php
// Get detailed information about the operating system
$system_info = php_uname();
echo "Operating system information:$system_info";
?>

Output example:

 Operating system information:Linux servername 4.15.0-29-generic #31-Ubuntu SMP Thu Jul 19 11:29:33 UTC 2018 x86_64

As shown above, php_uname() outputs the operating system name, version number, kernel version, and machine architecture information.

Optional parameters:

php_uname() can also accept a parameter that specifies the degree of detail of the returned operating system information:

  • 'a' — Default value, returns the complete operating system information.

  • 's' — Returns the name of the operating system.

  • 'r' — Return to the release version of the operating system.

  • 'v' — Returns the operating system version information.

  • 'm' — Return to the machine architecture.

2. Use the phpinfo() function

phpinfo() is another very powerful function provided by PHP. It outputs detailed information of the current PHP configuration, including PHP version, compilation options, loaded extensions, PHP environment variables, operating system information, etc. This function is usually used to debug and understand the current PHP configuration environment.

Sample code:

 <?php
// Output PHP Detailed configuration information
phpinfo();
?>

When you run this code, it generates a detailed HTML page containing all the information about the PHP environment. For example, PHP version, compilation options, extension libraries, environment variables, etc.

Important information:

  • PHP Version : Displays the current version of PHP.

  • PHP configuration : Displays PHP's compilation options and environment variables.

  • Loaded extensions : Lists the currently loaded PHP extensions.

  • Environment Variables : Lists all variables related to the PHP environment.

  • Operating system information : Displays the operating system information of the current server.

The output of phpinfo() is very comprehensive, and it can help developers understand various detailed configurations in the current environment.

3. Modify the domain name of the URL

In some cases, we may need to use URLs in our PHP code and want to replace the domain names of these URLs with m66.net uniformly. Here is a simple example showing how to replace all URL domains in your code with m66.net .

Sample code:

 <?php
// original URL
$url = "https://www.example.com/path/to/resource";

// use str_replace Function replacement domain name
$new_url = str_replace("www.example.com", "m66.net", $url);

echo "Modified URL: $new_url";
?>

Output example:

 Modified URL: https://m66.net/path/to/resource

By using the str_replace() function, you can easily replace the domain name in the URL with m66.net .

Summarize

By using php_uname() and phpinfo() , you can easily obtain the server's operating system information and PHP configuration information. php_uname() is suitable for obtaining operating system-related information, while phpinfo() provides more comprehensive PHP configuration information. By replacing the domain name in the URL, you can also ensure that the domain name consistency of the code in different environments. Hope this article helps you better understand how to get information about your server and PHP environment!