Install and Test PHP on Linux system

by on August 22, 2006 · 11 comments· LAST UPDATED August 27, 2006

in

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 11 comments… read them below or add one }

1 alaa ali August 22, 2009 at 9:04 pm

when i try to test my php a window appears: you have chosen to open test.php which is a php scripts.. what is this means? and how to solve this problem.. thanks in advance

Reply

2 DEA September 2, 2009 at 12:11 pm

Works great on Cent OS 5, Thanks!

Reply

3 mpande January 11, 2011 at 12:06 pm

To complete shutdown and exit just enter the command
init 0
Though remember to be root.
i.e
#init 0

Reply

4 Andrew August 6, 2011 at 7:09 pm

eroer 403, forbidden

Reply

5 Dulanja Subodhana September 8, 2012 at 8:27 pm

I can’t do step 2. Restart the web service.
There is no httpd in /etc/init.d/
What is the wrong. I’m using Ubuntu 11.10 with fvwm-crystal

Reply

6 Alivallo February 26, 2013 at 12:49 am

httpd does not exits.
that is because you need to install Apache web server.
after that you may find the file exists in /etc/apache/init.d/httpd

Reply

7 Rudy August 22, 2013 at 6:11 pm

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

Reply

8 Rudy August 22, 2013 at 6:17 pm

Correction:
ServerName (my_hostname):80

Comment removed &lt &gt symbols and text in-between

Reply

9 phpcoder September 17, 2013 at 8:11 pm

It does not work I can’t copy nor move my php directory with all my scripts to var/www/html

Reply

10 chrnux November 15, 2013 at 4:46 pm

are you logged in as root ?

Reply

11 phpcoder November 15, 2013 at 6:07 pm

I found a solution my dear friend, thanks for responding.
It was my lampp installation it had problems regarding its sockets.

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: