Using phpinfo to Display Info (Including Version Number) of your php (Linux)

An easy and quick way to find out what php version your apache server is using is to use the phpinfo() function. To do this we will create a file with <?php phpinfo() ?> in it and access it through our server by opening it in a browser.

Deciding Where to Put the PHP File

On CentOS 6 the default directory for html documents is /var/www/html/. Let’s go to that directory:

[ahmed@amayem /]$ cd /var/www/html/

Or if you want to go to a custom directory you may do that but we will have to change some apache configuration to point it to that directory.

Make a PHP file

[ahmed@amayem html]$ sudo "<?php phpinfo() ?>" > test.php
-bash: test.php: Permission denied

Looks like even sudo isn’t working here, we will have to change to root:

[ahmed@amayem html]$ su
[root@amayem html]# sudo echo '<?php phpinfo() ?>' > info.php

Now we need to give the file the proper rights. Let’s check what other files are there and copy that:

[root@amayem html]# ls -l in*
-rwxr-xr-x 1 root root 2175 Nov 13  2013 index.html
-rw-r--r-- 1 root root   19 Aug 29 17:59 info.php

So we need to add the execute rights:

[root@amayem html]# ls -l in*
-rwxr-xr-x 1 root root 2175 Nov 13  2013 index.html
-rwxr-xr-x 1 root root   19 Aug 29 17:59 info.php

That looks good.

Point Apache to the Directory that Contains the PHP File (if not using the default html directory)

If you decide not to use the default directory then we will have to adjust the Apache config. Go to the Apache config file. In CentOS 6 it is found here /etc/httpd/conf/httpd.conf. Let’s go there and access it:

[root@amayem html]# cd /etc/httpd/conf/
[root@amayem conf]# vi httpd.conf 

Go to the bottom of the file by entering G. If NameVirtualHost *:80 is commented then uncomment it (remove the # at the beginning of the line). Paste (copy and paste in vi here) the following at the end while replacing the values to what your values would be.

<VirtualHost *:80>
    DocumentRoot /var/www/html

Exit insert mode qith Esc or ctrl+c and save by entering :x. Now Apache needs to be restarted to get this new configuration.

[root@amayem conf]# apachectl restart

Now time to serve the new page.

Opening the file from a browser

Open a browser and go to your serverName/info.php, for example for me according to the setup above it would be Here is what it would look like:

Screen Shot 2014-08-30 at 10.13.16 PM

Getting Plain Text ‘

If you get a white page with the plain text <?php phpinfo() ?> at the top then you probably don’t have php installed or if it is installed then it is not enabled, in which case check the following:

  1. Installing php using yum
  2. Enabling ‘php’ in apache


  1. Cyberciti’s phpInfo page

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.