Download
info 321 server technologies ii n.
Skip this Video
Loading SlideShow in 5 Seconds..
INFO 321 Server Technologies II PowerPoint Presentation
Download Presentation
INFO 321 Server Technologies II

INFO 321 Server Technologies II

158 Views Download Presentation
Download Presentation

INFO 321 Server Technologies II

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. INFO 321Server Technologies II LAMP Partly adapted from notes by Dr. Randy M. Kaplan Weeks 7-8

  2. Overview This set of notes are in these sections LAMP Overview PHP Introduction PHP Basic Syntax Installing PHP PHP Configuration Installing MySQL PHPMyAdmin MySQL Basics Weeks 7-8

  3. LAMP Overview Weeks 7-8

  4. The LAMP Stack LAMP comes from L = Linux A = Apache M = MySQL P = Perl/PHP/Python The LAMP stack is open source software that enables rapid development of web-based and database-based applications Weeks 7-8

  5. Installing LAMP Apache needs to be installed with some special entries in its configuration script and files Before we get to mySQL, we’ll need PHP to help administer mySQL Therefore assume that we’ll be using PHP The P in LAMP can refer to any web-friendly programming language Weeks 7-8

  6. Installing LAMP To install the LAMP stack you will need to install Linux Apache MySQL PHP or Perl or Python Linux is presumably already installed Weeks 7-8

  7. Installing LAMP There’s a sneaky way to install LAMP all at once on Windows, Linux, and other platforms WAMP (as in Windows, Apache, MySQL, PHP) See also here for other options, e.g. MAMP for Mac OS X, XAMPP for Linux/UNIX, etc. Weeks 7-8

  8. PHP Introduction Weeks 7-8

  9. PHP “PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML” PHP is a recursive acronym (!) for PHP: Hypertext Preprocessor PHP is available from http://www.php.net PHP is on version 5.3.5 as of 6 Jan 2011 Weeks 7-8

  10. PHP Platforms PHP can be used on all major operating systems, including Linux Many Unix variants (e.g. HP-UX, Solaris and OpenBSD) Microsoft Windows Mac OS X (should this be under Unix variants?) RISC OS Weeks 7-8

  11. PHP Binaries also exist for AS/400 Mac OS X Novell NetWare OS/2 RISC OS SGI IRIX 6.5.x Solaris (SPARC, INTEL) Solaris OpenCSW packages From http://www.php.net/downloads.php Weeks 7-8

  12. PHP Web Servers PHP has support for most web servers Apache Microsoft IIS and PWS Netscape and iPlanet servers O’Reilly Website Pro server Caudium, Xitami, OmniHTTPd, and others Weeks 7-8

  13. PHP database support PHP can communicate with almost any database management system Adabas D, dBase, Empress, FilePro (read-only), Hyperwave, IBM DB2, Informix, Ingres, InterBase, FrontBase, mSQL, Direct MS-SQL, MySQL, ODBC, Oracle (OCI7 and OCI8), Ovrimos, PostgreSQL, SQLite, Solid, Sybase, Velocis, Unix dbm Weeks 7-8

  14. What can PHP do? PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do Collect form data, generate dynamic page content, send and receive cookies, etc. But PHP can do much more Summarized from http://www.php.net/manual/en/intro-whatcando.php Weeks 7-8

  15. What can PHP do? Command line scripting You can make a PHP script and run it without any server or browser You only need the PHP parser This type of usage is ideal for scripts regularly executed using cron (on Unix or Linux) or Task Scheduler (on Windows) Scripts can also be used for simple text processing tasks Weeks 7-8

  16. What can PHP do? Writing desktop applications PHP is probably not the best language to create a desktop application with a graphical user interface, but it can be done Use PHP-GTK to write such programs WinBinder is a (Windows only) alternative to PHP-GTK Weeks 7-8

  17. What can PHP do? Server-side scripting is the most traditional and main target field for PHP You need three things to make this work, a PHP parser (CGI or server module), a web server and a web browser You need to run the web server, with a connected PHP installation You can access the PHP program output with a web browser, viewing the PHP page through the server Weeks 7-8

  18. PHP output types A PHP server often outputs HTML, but it can also output Images PDF files Flash movies Any text, such as XHTML or other XML file Weeks 7-8

  19. PHP Basic Syntax Summarized from http://www.php.net/manual/en/language.basic-syntax.php Weeks 7-8

  20. PHP example <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd"><html>    <head>        <title>Example</title>    </head>    <body>        <?php            echo "Hi, I'm a PHP script!";        ?>    </body></html> Weeks 7-8

  21. PHP example The <?php and ?> are start and end processing instructions (a.k.a. opening and closing tags) The PHP server interprets them, and sends HTML to your web browser  key concept! PHP is done server-side, whereas JavaScript is done on the client Weeks 7-8

  22. PHP is server interpreted Weeks 7-8

  23. %^$%^# semicolons! Notice the commands end with a semicolon, like most C-ish languages PHP requires instructions to be terminated with a semicolon at the end of each statement The closing tag of a block of PHP code automatically implies a semicolon You do not need to have a semicolon terminating the last line of a PHP block, it adds an extra whitespace if you do Weeks 7-8

  24. Short and long tags You’ll see examples of PHP with start and end processing tags like these <? Stuff ?> These are called short tags, which by default are enabled, but should be avoided short_open_tag = On Please use the officially correct long tags <?php other stuff ?> Weeks 7-8

  25. Script tags Note: If you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards Other allowed opening and closing tags define the script language <script language="php"> stuff </script> FrontPage prefers this Weeks 7-8

  26. Accidental closing tags One aspect of PHP that you need to be careful of, is that ?> will drop you out of PHP code and into HTML even if it appears inside a // comment This does not apply to /* blah */ multi-line comments Weeks 7-8

  27. Comments <?php    echo 'This is a test'; // This is a one-line c++ style comment    /* This is a multi line comment       yet another line of comment */    echo 'This is yet another test';    echo 'One Final Test'; # This is a one-line shell-style comment?> Weeks 7-8

  28. Comments PHP supports three different styles: 'C', 'C++' and Unix shell-style (Perl style) // This is a one-line c++ style comment  /* This is a multi line comment       yet another line of comment */ Don’t try to nest them! # This is a one-line shell-style comment One-line comments go to EOL or end of php block Weeks 7-8

  29. Installing PHP Weeks 7-8

  30. Prerequisites for building PHP The following software is needed to build PHP An ANSI C compiler flex: Version 2.5.4 bison: Version 1.28 (preferred), 1.35, or 1.75 A web server Any module specific components (such as GD, PDF libs, etc.) From http://www.php.net/manual/en/install.unix.php Weeks 7-8

  31. Installing PHP Download the PHP source – follow the standard procedure for installing a new software application 1. gzip -d httpd-2_0_NN.tar.gz 2. tar xvf httpd-2_0_NN.tar 3. gunzip php-NN.tar.gz 4. tar -xvf php-NN.tar 5. cd httpd-2_0_NN 6. ./configure --enable-so For multi-core processors add --enable-shared-core 7. make 8. make install http://www.php.net/manual/en/install.unix.apache2.php Weeks 7-8

  32. Installing PHP PHP uses an ini file – a kind of configuration file A configuration file is supplied in the source directory Copy the php.ini file to the appropriate directory cp php.ini-dist /usr/local/lib/php.ini Weeks 7-8

  33. http.conf Modifications for PHP Here’s the Apache connection The http.conf file needs to be modified so that Apache knows what to do when it encounters PHP Lines are added to the .conf file where similar lines are placed (have a look at the default http.conf file) Weeks 7-8

  34. http.conf Modifications for PHP Load the PHP 5 module LoadModule php5_module modules/libphp5.so Handle how file types are to be processed AddHandler application/x-httpd-php    .php AddHandler application/x-httpd-php-source    .phps Weeks 7-8

  35. Stop and Restart Apache Once you have modified the http.conf file, in order to recognize the new setting you will need to stop and restart the server Use apachectl to accomplish this Weeks 7-8

  36. Testing PHP and Apache One way to test to see if Apache is correctly in place is to write some PHP and see if it runs as it should A quick and dirty test would be the canonical “Hello World” program in PHP A better test is to continue configuration of the LAMP stack so that you can see some significant functionality demonstrated Weeks 7-8

  37. PHP Configuration Weeks 7-8

  38. PHP configuration file There is a configuration file in PHP, php.ini It’s in the path designated by the environment variable PHPRC Under Linux/Unix, its default location is /usr/local/lib or <install-path>/lib On Windows, it’s in the Windows directory For the server versions of PHP, it’s read only once when the web server is started Weeks 7-8

  39. Sample php.ini file ; any text on a line after an unquoted semicolon (;) is ignored [php] ; section markers (text within square brackets) are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib" Notice that path statements do not include the actual file name Weeks 7-8

  40. php.ini file syntax Notice that the syntax in the PHP configuration file is different from within PHP scripts! Comments start with a semicolon, and can start mid-line Section markers [anything between square brackets] are also ignored Most lines are directive = value format Weeks 7-8

  41. PHP configuration file The php.ini file has core directives, and may have extensions The default php.ini file has well documented dozens of options from which you can choose The php.ini file must have that name! You can have multiple versions in different directories (hence the PATH importance) Weeks 7-8

  42. PHP directives Directive names are case sensitive The value assigned can be A string, a number A PHP constant (e.g. E_ALL or M_PI) An INI constant (On, Off, True, False, Yes, No or None) An expression (e.g. E_ALL & ~E_NOTICE) A quoted string ("foo") Weeks 7-8

  43. User configuration file The php.ini file pertains to the entire PHP install Individual users may have a personal configuration file, “.user.ini” user_ini.filename = ".user.ini“ Weeks 7-8

  44. Shy PHP Your PHP install can hide itself from the outside world (e.g. for security reasons) by changing this default setting expose_php = On Weeks 7-8

  45. Php.ini sections Language Options Resource Limits Error handling and logging Data Handling Unicode settings Paths and Directories File Uploads (to allow or not) Fopen wrappers (allows treatment of URLs as files) Dynamic Extensions Module Settings (incl. mySQL and cookie settings) Weeks 7-8

  46. Installing MySQL Weeks 7-8

  47. Install MySQL MySQL is an open source, enterprise class, database management system It is fully compliant with the SQL standard although, unlike products like Oracle that have opted for a rich base of features, MySQL has opted for simplicity All basic functionality is available – with perhaps a bit less “slickness” than other products Weeks 7-8

  48. Getting MySQL MySQL is available from http://www.mysql.com/ The MySQL Community Server is the free version The MySQL Enterprise Subscription is about $600/year per server Weeks 7-8

  49. Download an Installable Image In the case of MySQL, building (compiling) the database management system does not result in major benefits unless the platform you are using is special Downloads are available from here The current version is 5.5.9 Weeks 7-8

  50. MySQL Installation In the case of windows, the installation package comes in a zipped file In the zip file is another named setup.exe Double click (Windows) this file and an installer will launch and walk you through installation Once the MySQL server is started, you can check to see if it is running using the command line client Weeks 7-8