Monday, March 23, 2009

Installation & Run of PHP program


Hi, are you struggling with installation of PHP or Apache server in Linux Operating system???, here are some tips to install it. Use your terminal, here are some commands. Use all commands without quotes.

1.
"sudo apt-get install apache2" - To install the apache2 server, which helps you to link the server to your browser.

2."sudo apt-get install php5-cli"- To install php packages of version 5 (client side). While installing it asks for new password, enter any password and proceed.

3."sudo apt-get install cvs" The command cvs is an important component of Source Configuration Management (SCM) from which you can record the history of sources files, and documents.

Now everything is ready to run any php program.


If you dont know how to run a php program then follow this....(with sample program)

1. Using an editor create a file with an extension php or php3
Ex:- vim test.php -(Use it in terminal)
Here vim is an editor which is opening a file with a name test and extension with php. (For freshers it will be easy to use "gedit" instead of "vim" editor).

2. Now an editor is opened with plan page. Now hit the Insert key and write your php code. (If you use "gedit" instead of "vim" then you will get plan window, in which you can start writing code directly. No need of hitting the Insert button. But save it before close and continue)
Ex:- See above picture

3. Now hit Esc, :, w and q. To write(save) and quit from editor.
Ex:- :wq or :x (after hitting escape). (You can skip this step if you are using gedit editor)

4. Now all you need to do is copy a test.php file into /var/www directory. Copy it by cp command, if it doesnt work then you need to install mc.

5. "sudo apt-get install mc" -Visual shell for Unix-like systems.

6. "sudo mc" -which opens mc

7. There you will get a list of directories and files. Select your file (test.php) and copy it by pressing C key or in file tab you can use copy.

8. You will get a window which asks for destination, by default it will be /home/username, repalce it by /var/www. (username="your login name"). Now hit ctrl+z, so you will return to terminal.

9. Now you are almost done with everything just you need to locate http://
Ex:- http://localhost/test.php
(Type it in an URL of any browsers like IE/Mozilla/Opera etc)


There goes your page with display "Hello World"

2 comments:

karthik bhat said...

i try it soon dude..

Ajay Kulkarni said...

Its a simple one, i know u try it in the morning bcoz u feel fresh in the morning ;)... am i rite??