Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Ex No : 1 Date : 04/07/2012 1.

Objective:

SETTING UP A LAMP STACK

Use LAMP to create a server-side dynamic web page to monitor a source in a commercial application. 2. Installation procedure : 2.1 Apache installation: Command to install apache: #yum install httpd. To start apache server: #chkconfig httpd on. #/etc/init.d/httpd start. To stop the apache server: #/etc/init.d/httpd stop. To uninstall apache #yum remove httpd. 2.2 MySQL installation: Command to install mysql: #yum install mysql mysql-server. Location of mysql: Filesystem/usr/share/mysql. To start mysql service: #/etc/init.d/mysqld start. (or) #service mysqld start. To login to mysql: #mysql -u root -p Enter password: Syntax for mysql connection in php: mysql_connect(servername,username,password) To exit from mysql: exit To stop mysql service: #/etc/init.d/mysqld stop. (or) #service mysqld stop. To reset password in mysql: 1).Stop the mysql service. 2).Restart mysql in safe mode: #mysqld_safe skip-grant-tables& 3).Login to mysql at the command line: #mysqld -u root. 4).To create new password: >> update user set password=PASSWORD(new_password) where user='root'. 5).Exit from mysql. To unistall mysql: #yum remove mysql 2.3 PHP installation: Command to install php: #yum install php. Loaction of php: FileSystem/usr/share/swig 2.0.1/php. All php script must be written within <? php .............?>

Save the php file with .php extension. To run the file in command prompt: php filename.php. Run the php file in browser: Type http://localhost/cgi_bin/filename.php in the address bar. To uninstall php #yum remove php. 2.4 Aditional Information: To go to root user: su Enter root password : Network preference setting: Switch to System->Preference->Network Proxy. Enable manual proxy configuration. Set HTTP proxy to proxy.ssn.net and port to 8080. To change the access permission of a file: chmod -R 777 file location (for ex : /var/www/cgi-bin) 3. Application: 3.1 Description: A commercial application, SunSet SunRise which is used to display the time of the Sunset and Sunrise of any Place chosen. It also displays the Current Time and Current Date of the chosen place. A client web page is developed using PHP to get the Place name from user and submits it to the server. The server retrieves the Required information from the dynamic web page. MySql is used to store the place names. 3.2 Procedure: Client side: Client.php 1)A form is created using <form> tag with method=post and action=sunrise.php. 2)Drop Down Box is provided to select the places. 3)Mysql connection is established. If connection is not established,error message is displayed. Else a)Using mysql_query and mysql_fetch_array the city names saved in database are retrieved and displayed in drop down list using <select> . b)The user selects the place name from the list and clicks on the get-time button which calls the sunrise.php file and passes the name of the places selected as a parameter. 4)Submit button Get Info is placed after the drop down box. On clicking this button, the php page mentioned in the action attribute of the form is displayed. Server side: Sunrise.php 1)The city name passed is retrieved using $_POST['city']. 2)The source code from the dynamic website http://www.sunrisesunset.com/ is written to a text file using CURL command. 3)The file is opened and the position of the selected city is found using strpos. 4)The file pointer is moved to the corresponding position and the time is displayed in a tabular format. Information Displayed in the server side : Date Sunrise Time Sunset Time Current Time

3.3 MySQL commands: --->Create database: create database mydb; --->To drop the database: drop database mydb; --->To use the mydb database: use mydb; --->To create table: create table places ( name varchar(50) ); -->To insert places names: insert into places values('Dublin, Ireland'); insert into places values('Frankfurt, Germany'); insert into places values('Glasgow, Scotland'); insert into places values('Havana, Cuba'); insert into places values('Hong Kong, China'); insert into places values('Jerusalem, Israel'); insert into places values('Johannesburg, South Africa'); insert into places values('Lima, Peru'); insert into places values('London, United Kingdom'); 3.4 Database output :

3.5 Program coding : Client sideclient.php: <?php echo "<html>"; echo "<title>Setting up a LAMP STACK</title>"; echo "<body bgcolor='orange'>"; echo "<center><h1>SUNRISE SUNSET</h1>"; echo "<hr></hr>"; echo "<table border='2'><td><tr>"; echo "<br/><br/><br/><form name='f1' action = 'sunrise.php' method='post'><label><b> Select Your Place to Display the Date , Sunrise Time , Sunset Time , Current Time : </b></br></br>"; echo "<select id='city' name='city' >"; $con=mysql_connect("localhost","root","saranya"); if(!$con) die('Connection not established: '.mysql_error()); else { echo "Connection established "; mysql_select_db("mydb", $con); $result = mysql_query("SELECT * FROM places"); while($row = mysql_fetch_array($result)) { echo "<option value='".$row['name']."' >".$row['name']." </option>"; } mysql_close($con); echo "</select></label><input type='submit' value='Get Info'/></center></form></tr></td></table></body></html>"; } ?> Server side---sunrise.php: <?php ob_start(); echo "<html>"; echo "<title>Setting up a LAMP STACK</title>"; echo "<body bgcolor='orange'>"; echo "<center><u><h1>SunSet SunRise</h1></u></center>"; echo "<hr></hr>"; $place = $_POST['city']; $ch = curl_init("http://www.sunrisesunset.com/"); $fp = fopen("sunrise.txt", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); $fp = fopen('sunrise.txt', 'r'); fseek($fp,49650); while(!feof($fp)) { $p = ftell($fp); $data = fgets($fp); $pos = strpos($data,$place); if ( $pos != FALSE ) { $pos += $p;

fseek($fp,$pos); $info = fgets($fp,620); echo "<br/><br/><center><table border='3'><tr><td>"; echo $info; echo "</td></tr></table></center>"; } } rewind($fp); echo"</body>"; echo"</html>"; $content = ob_get_contents(); $fp1 = fopen('sunset.html', 'w'); fputs($fp1,$content); fclose($fp1); fclose($fp); ?> Sample Output: CLIENT SIDE : Client.php ->

SERVER SIDE : sunrise.php -->

4. Conclusion:

In Fedora14,the following were installed at first : Apache MySql PHP

The above mentioned packages were then used to create a server side dynamic web page (ie) client.php which monitors the source webpage, http://www.sunsetsunrise.com which dispalys : Sunset time Sunrise time Current time & Date, for a give location.

The client page,client.php displays the place names in a combo box by retreiving from the database and also contains a submit button named Get Info which submits the form. This client page on submission,invokes the server file,sunrise.php which retreives the required information from the website and displays it.

You might also like