Beginning PHP
by Rajesh Sivaraman • February 2, 2012 • Linux, PHP • 0 Comments
PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
In this article, I would like to demonstrate how easy it is to get started with PHP. We will look at how to install Apache and PHP on a computer running Ubuntu and how to write our first PHP page.
To install Apache and PHP from the Ubuntu repositories, open a terminal and run the commands below. Apache should start automatically once it is installed. Make sure that Apache is running by browsing to http://localhost in your computer. You should be seeing a “It Works !” page. We will also create a test.php file in the root directory of our web server and assign rights to our user so that we can edit it.
|
1 2 3 4 |
sudo apt-get update
sudo apt-get install apache2 php5
sudo touch /var/www/test.php
sudo chown panayola:panayola /var/www/test.php |
We are all set to begin with our first PHP page. Now open this file ( /var/www/test.php ) your favorite text editor and paste the following code.
|
1 2 3 4 |
<?php
// This is a comment. It does nothing. But the line below will do something.
echo "<h1>Hello World !</h1>";
?> |
Save the file and test using your browser by accessing http://localhost/test.php .
Test the result by right clicking the page in browser and selecting the view page source option. You can see that the HTML code embedded into the echo command was sent to the browser. Don’t forget to checkout http://www.php.net , the home of PHP.
Hope you liked this article. Feel free to try, share and discuss.
Related posts:

