PHP is very popular programming language used by a lot of programmers and web devleopers. During PHP application development we may need to get detailed information about the platform the PHP web server runs. This type of information is provided by phpinfo
function. phpinfo()
function provides information like PATH, User, Operating System, Modules etc.
PHP是许多程序员和Web开发人员所使用的非常流行的编程语言。 在PHP应用程序开发过程中,我们可能需要获取有关PHP Web服务器运行平台的详细信息。 此类信息由phpinfo
函数提供。 phpinfo()
函数提供诸如PATH,用户,操作系统,模块等信息。
安装PHP (Install PHP)
We will use php
command PHP Framework in this tutorial. So we need to install it properly before starting. We can install PHP like below.
在本教程中,我们将使用php
命令PHP Framework。 因此,我们需要在开始之前正确安装它。 我们可以像下面那样安装PHP。
Ubuntu,Debian,Mint,Kali: (Ubuntu, Debian, Mint, Kali:)
$ sudo apt install php
Fedora,CentOSi RHEL: (Fedora, CentOSi RHEL:)
$ sudo yum install php
创建phpinfo.php页面 (Create phpinfo.php Page)
We will start by creating a phpinfo web page. Actually it is very easy to create one. We just use following PHP code to list phpinfo.
我们将从创建一个phpinfo网页开始。 实际上创建一个很容易。 我们只使用以下PHP代码列出phpinfo。
<?php
phpinfo();
?>
在Apache Web服务器上运行phpinfo (Run phpinfo On Apache Web Server)
As we know PHP is a dynamic server side language. We need to run PHP code on the server with PHP framework and Web Server Application which is Apache in this case. Put the code described above into the the path /var/www/html
众所周知,PHP是一种动态的服务器端语言。 我们需要在具有PHP框架和Web服务器应用程序(在本例中为Apache)的服务器上运行PHP代码。 将上述代码放入路径/var/www/html
$ cp phpinfo.php /var/www/html
and run following command to start Apache Web Server. But we need to be sure that PHP modules are installed properly.
并运行以下命令以启动Apache Web Server。 但是我们需要确保正确安装了PHP模块。
$ sudo systemctl start apache2
Or
要么
$ sudo systemctl start httpd
在命令行上运行phpinfo (Run phpinfo On Command Line)
If we need to run phpinfo
in a more secure and local way we can use command line option which will put the output of the phpinfo page into terminal.
如果我们需要以更安全和本地的方式运行phpinfo
,可以使用命令行选项,它将phpinfo页面的输出放入终端。
$ php7.2 phpinfo.php
OR
要么
$ php phpinfo.php
使用PHP Web服务器从命令行运行phpinfo (Run phpinfo On From Commmand Line with Php Web Server)
We can also create a temporary web server which will serve the phpinfo
web page. We will use again the php command. We will also provide the IP address and port number we want to run web server.
我们还可以创建一个临时的Web服务器,该服务器将为phpinfo
网页提供服务。 我们将再次使用php命令。 我们还将提供我们要运行Web服务器的IP地址和端口号。
$ php7.2 -S 0.0.0.0:8080 phpinfo.php
WordPress phpinfo插件 (WordPress phpinfo Plugin)
If we are running a CMS (Content Management System) like WordPress we have options which is more practical then creating a web page and serve it. WordPress provides the PHPINFO plugin from the following link.
如果我们运行的是像WordPress这样的CMS(内容管理系统),那么我们有一些更实用的选项,然后创建一个网页并提供服务。 WordPress通过以下链接提供了PHPINFO插件。
https://wordpress.org/plugins/wordpress-php-info/
https://wordpress.org/plugins/wordpress-php-info/