An Introduction to PHP
"PHP is an open source general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages. It is one of the first developed server-side scripting languages to be embedded into an HTML source document rather than calling an external file to process data. The code is interpreted by a Web server with a PHP processor module which generates the resulting Web page. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. PHP can be deployed on most Web servers and also as a standalone shell on almost every operating system and platform free of charge. A competitor to Microsoft's Active Server Pages (ASP) server-side script engine and similar languages, PHP is installed on more than 20 million Web sites and 1 million Web servers. Software that uses PHP includes MediaWiki, Joomla, Wordpress, Concrete5, MyBB, and Drupal." (from wikipedia)
General Notes on PHP
The following provides a summary of what PHP is:
- PHP stands for PHP: Hypertext Preprocessor
- PHP is a server-side scripting language, like ASP, JSP, etc.
- PHP scripts run on the server.
- PHP supports many databases, e.g., MySQL, Oracle.
- PHP is an open source software.
How to Start Your First PHP Program?
The CS Hercules Server supports PHP, so you don't need to
do anything on it, for example, installation or configuration.
The only thing you need to do is to create a
file in the
public_html directory. Note: you still
need to set the correct permission. To sumarize you can follow
the steps below:
- Create a .php file.
- Upload the .php file into the public_html folder.
- Set the permission for the php file:
ssh hercules cd public_html/ chmod 644 *.php
- Open your browser, input and visit the following address:
Where to Write Your PHP Scripts?
A PHP script always starts with a pair,
?>, for example,
<?php echo "<h1>Hello CS215 Students!<h1>"; echo "<p>Hi this is a sentence.</p>"; ?>
A PHP Server (the Hercules) parses the PHP scripts and returns the plain HTML code back to the client browser. That is, the
echofunction sends a level-one header (
H1) and a paraghraph (
P) to your browser. You can try this example on Hercules.
<!DOCTYPE html> <html> <head> <title>A Sample Php Program</title> </head> <body> <?php echo "<h1>Hello CS215 Students!<h1>"; ?> </body> </html>
- Create and run a simple .php page on Hercules.
- To run .php program in hercules, type php filename.php at the hercules prompt sign
- You can visit your php page by using the following url: