Apache is installed and is now delivery pages to clients or in other words a web browser. HTML pages are good but lack any major interactivity and are not dynamic enough for today’s web sites. PHP offers a solution to dynamic web pages by allowing pages to make decisions based on input or data from an external source such as a database or another web site. The first step will be to install PHP. This is done from the command line by entering the following. $ sudo apt-get install php5 We will also install the php-mysql package that will allow php web pages to interact with the MySQL database. $ sudo apt-get install php5-mysql $ cd /var/www $ sudo nano test.php Enter the following php code into the test.php document. <html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php phpinfo(); ?>
</body>
</html> You can see that the structure of a php follows the same rules as the HTML file did but the big difference is the tag the starts with <?. * When PHP parses a file, it looks for opening and closing tags, which are which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. PHP also allows for short open tags (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the –enable-short-tags option. * This indicates that you are about to create some php code so rather than outputting the words php phpinfo(), it will instead call a function called phpinfo(). This function will display information relating to PHP and the apache server. Later lessons will explore PHP in more detail. * Contribution by Steve. Thank you for expanding on this.
|