Wednesday, 28 October 2009

Day 2 - Hello world in php

I have seen many tutorials that start with php running under the apache. But for change I like to create the hello world application as a command line application. So this will show you that the php can also act as command line tool also.

Create a file with following content and name it as hello_world.php

echo 'Hello World!!!'.PHP_EOL;

To run it, in the command line
$ php hellow_world.php
Hello World!!!


Perfect you have made you first php hello world application. As part of the example you have noticed that you didn't complied your application to create a executable file. This is because php is not a compiler but its an Interpreter.

Day 1 - Preparing the machine

In this post I will help you get the machine ready for php development.

The OS that I am using Ubuntu. So I am making an assumption that you all using the ubuntu. Os the flavor is only dependent for the installation purpose only.
To start with we should need the following packages
  1. PHP
  2. Apache
  3. Mysql
Installing PHP
sudo apt-get install php5 php5-mysql php-pear php5-cli php5-dev php5-common

Installing Apache
sudo apt-get install apache2

Installing Mysql
sudo apt-get install mysql-client mysql-server

To test the installation in the command line run
php --version

You will see some thing like this
$ php --version
PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 23 2009 14:35:05)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

To test the apache check the following link in the browser http://localhost/ You should get a message 'It Works'

The start

This blog will help you study php from the very basics. And if you have any doubt there will be experts to help you in.