1 / 65

CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad

CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad Virtual Campus, CIIT COMSATS Institute of Information Technology T2-Lecture-16. XAMPP An Open source Web Development Technology. For Lecture Material/Slides Thanks to: http://www.phpknowhow.com.

latona
Download Presentation

CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 330 E-Commerce Teacher Ahmed MumtazMustehsan GM-IT CIIT Islamabad Virtual Campus, CIIT COMSATS Institute of Information Technology T2-Lecture-16

  2. XAMPPAn Open source Web Development Technology For Lecture Material/Slides Thanks to: http://www.phpknowhow.com

  3. Synopsis Role of PHP in Web Applications Working with XAMPP Installation of XAMPP How to Run PHP Files Getting Information About PHP Installation Choosing a PHP Editor Choosing IDE Environment T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  4. Role of PHP in Web Applications

  5. Role of PHP in Web Applications PHP is a server side scripting language. Processing takes place at server using its resources. And output is sent to the client. In a client side scripting like JavaScript, the processing is done in the client’s computer consuming its resources. Note: PHP can also be used as a language for Command line Scripting and Desktop applications. But it’s widely used for web applications. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  6. Role of PHP in Web Applications To understand the role of PHP, let’s have a look to a normal web request and a web request that involves PHP. Note: There can be many intermediate steps involved but only the main and important ones have been mentioned for understanding purposes. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  7. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  8. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  9. Dynamic Content &lt; html &gt; &lt; / html &gt; &lt; ?php ? &gt; • “using PHP you can create dynamic web sites”. The site that generate the web Pages for client dynamically. Example: • let’s take a look at  welcome.html and welcome.php. Note: For HTML code <html> </html> For PHP code <?php ?> Both are the same T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  10. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  11. Static vs Dynamic contents Static Components: No matter what’s the current time of the day, welcome.html, would always print Welcome! as the heading. Showing a staticbehavior Dynamic Components: The script welcome.php will print Good Morning! before 12 noon, and Welcome!, if it is after 12. showing a dynamic behavior because the content it delivers changes according to the time of the day. (date() function uses server’s time and it may be different from your PC’s time). PHP can be used to build dynamic content based on the context. Real benefits of PHP’s dynamic behavior can be observed by creating database driven web applications. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  12. How PHP Engine Outputs Content ? When PHP interpreter reads a file, it only processes lines between <?php and ?> tags. It outputs rest of the lines without any processing. In welcome.php, PHP interpreter outputs all the HTML content till <?php tag without any processing. Then based on the time of the day it adds Good Morning! or Welcome! to the output. Then from </h1> tag, it outputs rest of the lines without processing. Web server collects all these outputs and sends the client to the client who made the request. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  13. Client Browser vs PHP code Only the output is sent to the client. So, no PHP content can be seen by viewing the source of PHP files in client’s web browser. You can have more than one block of PHP content in a page. The variables defined in these blocks are available to next blocks. Example, PHP file (welcome-new.php) behave as same as welcome.php. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  14. Example the use of PHP Variables T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  15. Embedding PHP in HTML When PHP and HTML content are mixed in a PHP file like welcome.php and welcome-new.php, it is called as “Embedding PHP in HTML”. The same result can be obtained only from PHP (welcome-latest.php) which contains only PHP content. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  16. Where to Use PHP? Embedding PHP blocks in HTML can be useful to utilize PHP power of manipulating and embading dynamic nature. So use PHP code only where it is necessary. In welcome files, we only need PHP to output the correct greeting. The rest of the lines can be displayed without PHP. This saves PHP processing resources and lets us have clean and readable files in our development. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  17. Working with XAMPP

  18. XAMPP – What’s the tool? • XAMPP (pronounced as ZAMP) is a small and light Apache distribution containing the most common web development technologies in a single package. Acronym for: X- Read as "cross", meaning cross-platform A-Apache HTTP Server (Web Server) M-MySQL (Open Source database) P-PHP (Server side scripting) P-Perl (scripting language) Note: X is also referred as LINX at different sites. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  19. Features of XAMPP: Ideal tool for developing and testing applications in PHP & MySQL. Takes less time than installing each of its components separately. Multiple instances of XAMPP can exist on a single computer. Allow website designers and programmers to test their work on their own computers without any access to the Internet XAMPP also provides support for creating and manipulating databases in MySQL and SQLite among others. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  20. XAMPP v/s XAMPP Lite T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  21. Types of XAMPP- It’s free and available for Windows, Mac OS Solaris and Linux and called: WAMP ------ For Windows MAMP------ For Mac OS X SAMP------ For Solaris LAMP ------ For LINUX T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  22. Install XAMPP Download Start by downloading XAMPP by following these links to downloads and installation guides: Download and install XAMPP for Windows Download and install XAMPP for Mac Download and install XAMPP for Linux T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  23. Downloading and Installing XAMPP • Go to XAMPP web site and download the installer based on your operating system. • Installation should be similar to a normal software installation you do in your operating system. • When installing, there would be an option to select whether you want: To run Apache and MySQL as services while booting machine OR if you are not doing PHP development frequently. You can start Apache and MySQL as and when required. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  24. Install XAMPP Just follow the instructions on the screen during the installation process. Below are screenshots from an installation on Windows. Choose the "Installer" download on the XAMPP website: T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  25. Install XAMPP Run the file and choose C:\xampp as the install location: T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  26. Install XAMPP You don't need to choose any "Service Sections": T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  27. Install XAMPP • After Finishing the installation of XAMPP, Start the server and save your future PHP documents in the folder c:\xampp\htdocs on your computer and access them in the browser with the address http://localhost. Click "Finish" when the installation process is complete: T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  28. Starting Apache and MySQL Note: Instructions provided are based on Windows operating system but the approache should be similar for other operating systems. Go to the location where you installed XAMPP (usually C:\Program Files\xampp) and double click on XAMPP Control Panel , (xampp-control.exe). It will display the screen! T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  29. Starting Apache and MySQL Once opened, you would see XAMPP icon on the right of your task bar. Click on Start buttons next to Apache and MySQL for starting them. Clicking on that icon will show/hide XAMPP control panel. To exit from XAMPP, click on Exit button in XAMPP Control Panel. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  30. Error!! Apache Is Not Starting Sometimes even after clicking Start button several times, Apache is not starting. This is usually because some other service is running at the port required by Apache which is 80 by default. An easy reproducible way for this error is starting Skype before starting Apache. In such a case, you would need to stop other service temporary and restart it after starting Apache. For example, if Skype is stopped, it will find another port for working after restarting. In the installation directory, you would see a program called Port Check (xampp-portcheck.exe). Double click on it and it will show you status of required port for Apache, MySQL and other software that comes with XAMPP. If required ports are already occupied, it will show the names of services that run on those ports. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  31. Making Requests to the Server Once you started Apache in control panel, type http://localhost in your web browser. This would bring you a web page that lists XAMPP related details. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  32. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  33. Putting Stuff in Web Folder • Under XAMPP root directory there is a folder called htdocs. • Put your web site related stuff in htdocs . • For each web site create a Folder, inside htdocs folder and put content to avoid conflicts. • For an example, create a folder called learnphp inside htdocs folder and put  welcome.php inside that. • Then you can access it via: URL  http://localhost/learnphp/welcome.php. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  34. Root URL and Home Page Content In above example, root URL of your web site is http://localhost/learnphp/ and it’s generally expected to see home page of the web site once root URL is typed in the web browser. Web servers are configured to look for an index file (e.g.  index.htm,index.html, index.php etc) in the root of the web site folder contains content for the home page of the site. So, if a file called index.php is present inside http://localhost/learnphp/ it will automatically be displayed. Make sure only one index file in the folder of web site to avoid conflicts. If there are more than one (say index.html, index.php), the file will be chosen based on the order defined in your web server’s configuration settings. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  35. Locations of Configuration Files • Based on your requirements, sometimes you would need to change default settings of your web and database servers. Usually this is done by altering their configuration files. In XAMPP, Apache, PHP and MySQL configurations files are located in following locations (This assumes XAMPP installation directory as C:\Program Files\xampp). • Apache Conf File (httpd.conf):  C:\Program Files\xampp\apache\conf\httpd.conf • PHP Conf File (php.ini):  C:\Program Files\xampp\apache\bin\php.ini • MySQL Conf File (my.cnf):  C:\Program Files\xampp\mysql\bin\my.cnf • In XAMPP, some Apache configuration settings have been moved to sub configuration files under xampp\apache\conf\extra. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  36. To open my.cnf, double clicking on it may not work sometimes. In that case, open Notepad and then locate my.cnf file by setting Files of Type to All Files as below. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  37. Restarting Apache and MySQL To take effect any configuration change, it’s required to restart Apache and/or MySQL. In XAMPP, if these two are already running, stop them and start again in the Control Panel. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  38. How to Run PHP Files

  39. How to Run PHP Files • Double click on a HTML file (files with .html or .htm extension) it would open in web browser. • But same won’t happen if you double clicked on a PHP file (probably it would open in an editor). • The reason is PHP files first need be processed in a web server before sending their output to the web browser. • Therefore before running PHP files, they should be placed inside the web folder of a web server (htdocs )and then make a request to desired PHP file by typing its URL in the web browser. • The root of its web folder can be accessed by typing  http://localhost in the web browser. • So, if you placed a file called hello.php inside its web folder, you can run that file by calling http://localhost/htdocs/hello.php. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  40. Getting Information about PHP Installation

  41. Getting Information about PHP Installation PHP provides phpinfo() function that prints details about your PHP installation. It can be helpful when you want to know about a certain setting like the location of php.ini file. Copy following code to a file located in your web server and run it in your web browser. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  42. Getting Information about PHP Installation T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  43. Getting Information about PHP Installation You will be able to see tabulated information about your php installation. Usually a file like this is used as a test file to check that PHP is up and running. First you will be able to see your PHP version. Configuration File (php.ini) Path shows where is your php.ini located. PHP may keep a separate php.ini file for command-line. This setting shows the location of php.ini file that corresponds to your web server (the one you will use most). Under date section, you will find the timezone used by PHP. For many PHP extensions installed, there would a table listing extension details. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  44. Choosing a PHP Editor

  45. Choosing a PHP Editor PHP files can be edited using any text editor however, prefer an advanced editor when engaged in PHP development. Usually operating system offers a text editor with syntax highlighting (If not, find a free one on net). However working on a PHP project that involves many files, just syntax highlighting won’t be enough. You will need an IDE (Integrated Development Environment). An IDE is an application that integrates development tools like a debugger, an interpreter, a version control system with the editor. That lets you execute many development tasks at one place. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  46. Choosing IDE When you choose an IDE, look for following features. PHP syntax highlighting. Integrated interpreter so that if you make a syntax mistake it will be immediately visible. Autofilling that suggests PHP built-in code and the code you have already defined (like variables) when you start typing. Allowing easy refactoring like changing a method name across a file or across a set of files. Highlighting unused variables (this will allow you to cleanup your code). Integrated version controlling so that it clearly shows changed lines and allows you to revert back if needed. EasyEclipse for PHP and NetBeans for PHP are free and feature-rich IDEs. Both are available for Windows, Mac and Linux operating systems. T2-Lecture-16 Ahmed Mumtaz Mustehsan www.phpknowhow.com

  47. PHP and MySQL Web Development • When you install PHP, you can select from a number of extensions. • The MySQL support in PHP consists of a number of functions you can call to interact with MySQL, tMyn

  48. PHP and MySQL Web Development 1 Browser Web Server 6 5 2 3 MySQL Server PHP Engine 4 tMyn

  49. PHP and MySQL Web Development A typical web database transaction consists of the following stages, which are numbered in above Figure: • A user’s web browser issues an HTTP request for a particular web page. For example, using an HTML form, she might have requested a search for all books at MikkeliOnlineProfessionalBooks.com written by Leila Karjalainen. The search results page is called results.php. • The web server receives the request for results.php, retrieves the file, and passes it to the PHP engine for processing. tMyn

  50. PHP and MySQL Web Development • The PHP engine begins parsing the script. Inside the script is a command to connect to the database and execute a query (perform the search for books). PHP opens a connection to the MySQL server and sends on the appropriate query. • The MySQL server receives the database query, processes it, and sends the results - a list of books - back to the PHP engine. • The PHP engine finishes running the script, which usually involves formatting the query results nicely in HTML. It then returns the resulting HTML to the web server.

More Related