12.4. A Couple of Quick Examples

We’ll start with two quick examples. Create a new directory for PHP work and cd into it:

$ mkdir /var/www/html/php 
$ chmod a+rx /var/www/html/php 
$ cd /var/www/html/php
					

Create a PHP file named hello.php: [4]

[4] Remember the permissions, 644.

<html> 
<head> 
<title>Hello, world! with PHP</title> 
</head> 
<body bgcolor="#ffffff"> 
<? echo "hello, world!" ?> 
</body> 
</html> 

To view the result of this file, load either one of these URLs: http://localhost/php/hello.php or www.opensourcewebbook.com/php/hello.php. The result can be seen in Figure 12.1.

Figure 12.1. hello, world! with PHP

The PHP code is embedded in ...

Get Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.