For lab this week, we want to set up our web server to handle PHP and write a simple PHP-enabled web page.
The following is the steps to install .php support for apache2 in ubuntu. Recall that apache2 is the apache package designed by ubuntu. The commands given below are expected to be run from a command line prompt in a terminal window.
sudo pico /etc/apt/sources.listAdd the following line to the source.list file
deb http://192.168.1.1 feisty mainThis will direct you machine to the package/installation files that are set up on one machine in the lab.
sudo apt-get update
sudo apt-get install php5
In your DocumentRoot directory, create a file test.php. You can use any text editor you like instead of using pico in the command.
sudo pico test.phpThis file should contain something like:
<html> <body> <?php phpinfo(); ?> </html> </body>The phpinfo() function displays a large amount of data about the web server.
Variable in PHP begin with a dollar sign, $. Detailed information on this can be found at the W3Schools Web page at: http://www.w3schools.com/php/php_variables.asp. Assignments are done as follows:
$var_name = value ;
Loops in PHP can be done using the C/C++/Java style of while loops, do-while loop and for loops. Detailed information on this can be found at the W3Schools Web Page at: http://www.w3schools.com/php/php_looping.asp A for loop that will output the values from 1 to 10 would be
<?php for ($i = 1 ; $i <= 10 ; $i++) echo "$i" ?>
The formula to convert from degrees Celius to degrees Fahrenheit is:
Tf = (9.0/5.0)*Tc + 32 Where: Tc = temperature in degrees Celsius, Tf = temperature in degrees FahrenheitDetailed information on operator in PHP can be found at the W3Schools Web Page at: http://www.w3schools.com/php/php_operators.asp
This lab assignment is to done in the lab in SEL 2264.