Install and Test PHP on Linux system

Posted on in Categories last updated August 27, 2006

Q. How can I install and test PHP on Linux? How do I make sure it is working on my Linux system? I am using Red Hat Fedora Core Linux.

A. PHP (PHP Hypertext Preprocessor) is an open-source, programming language. Originally designed as a high level scripting language for producing dynamic Web pages, PHP is used mainly in server-side application software.

Task: Install PHP

If you are using Fedora Core or Cent Os Linux, type the following command:
# yum install php

If you are using Debian Linux, type the following command:
# apt-get install php5

Now restart Web Server:
# /etc/init.d/httpd restart

Task: Test php

Go to /var/www/html/ directory:
# cd /var/www/html/

Create a php file – phptest.php
# vi phptest.php

Append following lines:
<?php phpinfo(); ?>

Save and close the file.

Open a web browser and type the url : http://yourdomain.com/phptest.php or http://localhost/phptest.php or http://server-ip-address/phptest.php.

See sample output here

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

12 comment

  1. ServerName changed to:
    ServerName :80

    But explicit hostname did not work in URL only ‘localhost/phptest.php’ worked

    Using DHCP on Red Hat Enterprise Linux Workstation release 6.3 (Santiago) so I’m not sure how to specify the IP entry in /etc/hosts

    Kernel: 2.6.32-279.19.1.el6.x86_64

Leave a Comment