lamp introduction 20100419

Post on 14-Dec-2014

1.346 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

aaa

TRANSCRIPT

March 24, 2006

Introduction to LAMPCory AitchisonSoftware Engineer

Novell Inc.caitchison@novell.com

© Novell Inc, Confidential & Proprietary

2

Session Overview

• Introduction to LAMP• Installation on OES Linux• Optimization• Some available applications• Migration• Creating Lamp Applications

Introduction to LAMP

© Novell Inc, Confidential & Proprietary

4

What is LAMP

• LAMP is a framework for developing and web applications rapidly

• LAMP stands for– Linux– Apache– MySQL– PHP (or Perl or Python)

• Each one of these components of the LAMP stack is interchangable

© Novell Inc, Confidential & Proprietary

5

Stack Model

mod_php

PHP

MySQL

Linux/OES

Hardware

Apache

© Novell Inc, Confidential & Proprietary

6

Stack Model – MySQL

You can use any database in place of MySQL:• Oracle*• PostgreSQL• Access• DB/2*

MySQL is generally preferred for the following reasons:• Ease of use• Good documentation• Open Source• 4.0.18

© Novell Inc, Confidential & Proprietary

7

Stack Model - PHP

When people talk about LAMP the language generally referenced is PHP. Although, it is possible to use any web ready language at this point in the stack.

• OES Version 4.3.4• Excellent documentation at http://www.php.net• A lot of support in the open source community • (http://hotscripts.com)• Tight integration with Apache through mod_php• You must take care of security concerns

© Novell Inc, Confidential & Proprietary

8

Stack Model - Apache

Again here you could use any webserver, however, apache is perhaps the best and most widely used webserver available• Highly configurable• Very flexible• Large market share• OES Version 2.0.49

Installation

© Novell Inc, Confidential & Proprietary

10

OES Linux Installation

• During install ensure that required packages have been selected– apache2-prefork– mysql– php4– apache2-mod-php4– php4-mysql– php4-session– php4-sockets– php4-zlib

© Novell Inc, Confidential & Proprietary

11

OES Linux Installation

• Some additional configuration is helpful.• Create the file /etc/apache2/httpd.conf.local• Add the line:

DirectoryIndex index.html index.php• Edit the file /etc/sysconfig/apache2• Add /etc/apache2/httpd.conf.local to the

APACHE_CONG_INCLUDE_FILES line

© Novell Inc, Confidential & Proprietary

12

Errata

• Most services run in user space.• Kernel is isolated from processes• Development can be done on server• Can be used as a desktop• Admin skills are similar for desktop and server• Easy to configure

Apache

© Novell Inc, Confidential & Proprietary

14

Apache

• Most popular web server on the planet• Highly configurable• can be clustered• open source• many modules and management applications

available• http://httpd.apache.org/

© Novell Inc, Confidential & Proprietary

15

Popular Apache Modules

• mod_rewrite• mod_php• prefork• mod_auth• mod_cgi• optimization modules in following slides

© Novell Inc, Confidential & Proprietary

16

Apache Optimization

• Mod_Mem_Cache – Memory based storage manager (Experimental)– CacheEnable – Enables memory or disk based caching– MCacheSize - maximum amount of memory to be used by the

cache (in Kbytes)– MCacheMaxObjectCount - maximum number of objects to be

cached– MCacheMinObjectSize - minimum size of a document (in bytes)– MCacheMaxObjectSize – maximum allowable size of a

document (in bytes)– http://httpd.apache.org/docs-2.0/mod/mod_mem_cache.html

© Novell Inc, Confidential & Proprietary

17

Apache Optimization

• Mod_Disk_Cache – Disk based storage manager (Experimental)– CacheEnable– CacheSize– CacheMinFileSize– CacheMaxFileSize– http://httpd.apache.org/docs-2.0/mod/mod_disk_cache.html

© Novell Inc, Confidential & Proprietary

18

Apache Optimization

• Load Balancing with Mod_Proxy– Most effect in environments where there is a lot of dynamic

content in a distributed environment– Disable forward proxy with “ProxyRequests Off”– Redirect requests to the specific backend servers with

“ProxyPass”– Allow redirection headers to be fixed up with

“ProxyPassReverse”– Use in conjunction with mod_mem_cache– http://httpd.apache.org/docs-2.0/mod/mod_proxy.html

• Logging– LogLevel Directive (ie LogLevel error)

© Novell Inc, Confidential & Proprietary

19

Apache Configuration

• The configuration for apache is handled in many different files on SLES and therefore on OES. The main ones are

• /etc/apache/httpd.conf• /etc/apache/httpd.conf.local• /etc/apache/conf.d/*• /etc/sysconfig/apache2

© Novell Inc, Confidential & Proprietary

20

Apache Configuration

• /etc/apache/httpd.conf

• Don't edit this file. It is owned by the apache package and will be over written if you install an update.

• /etc/apache/httpd.conf.local

• This is where you should make changes to you server as it is parsed after /etc/apache/httpd.conf

© Novell Inc, Confidential & Proprietary

21

Apache Configuration

• /etc/apache/conf.d/*• All conf files in this directory are parsed. This is the

best place to put specific module configuration (ala jk.conf)

• /etc/sysconfig/apache2• You can tell apache which modules to load here, as

well as what other conf files to parse.•

• Apache has a LOT of options. Far to many to discuss here.

MySQL

© Novell Inc, Confidential & Proprietary

23

MySQL

• Popular database• a lot of traffic in news groups• open source• excellent management tools

– phpMyAdmin• clusterable• easy to optimize

© Novell Inc, Confidential & Proprietary

24

MySQL Optimization

My.INI

Variable Default >512 MB >1 GB

key_buffer_size 16M 128 M 256M

table_cache 64 128 256

sort_buffer_size 2M 4M 8M

myisam_sort_buffer_size 8M 32M 64M

read_buffer_size 128K 1M 2M

© Novell Inc, Confidential & Proprietary

25

MySQL Optimization

• Use Indexes!!! - unique if possible• NOT NULL – especially with indexed columns• Fixed length fields• Use binary logging.• Use OPTIMIZE to defragment table files• Use ANALYZE to store key distributions• Use default values• Do not SELECT *• Use EXPLAIN to see how queries are performed• –log-slow-queries

PHP

© Novell Inc, Confidential & Proprietary

27

PHP

• Very easy to use• Powerful mysql integration• Simple HTML integration• Tied tightly to Apache• Easy application deployment

© Novell Inc, Confidential & Proprietary

28

Scripting Optimization

• The default setting are good but you can make some changes (for example logging, memory usage, how long a script can run, . . .)

• In general let MySQL do the work for you. If you write good queries and have optimized your tables you will be in good shape.

© Novell Inc, Confidential & Proprietary

29

PHP Pages

It is remarkably easy to combine php and html and have Apache render the pages for you correctly.

You embed php into a page by surrounding your code with a scriptlet tag. In the case of php you use:

<?php . . . ?>

© Novell Inc, Confidential & Proprietary

30

PHP Pages

So our first php program could look something like this:

<?phpecho “Hello World”;

?>

As you may be able to guess this code would render Hello World in a browser.

© Novell Inc, Confidential & Proprietary

31

PHP Pages

If we wanted to make this page compliant to the XHTML spec it would look something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>NDK Self Service</title></head><body>

<?phpecho “<div>Hello World</div>”;

?></body></html>

© Novell Inc, Confidential & Proprietary

32

PHP Pages

We can do most anything inside those <?php . . . ?> tags that any programming language can:

•conditional logic•loops•variables•objects•arrays•parameter passing (via gets and posts)•and the list goes on and on

© Novell Inc, Confidential & Proprietary

33

PHP Pages

We can do most anything inside those <?php . . . ?> tags that any programming language can:

•conditional logic•loops•variables•objects•arrays•parameter passing (via gets and posts)•and the list goes on and on

© Novell Inc, Confidential & Proprietary

34

PHP – MySQL Functions

• mysql_affected_rows• mysql_change_user• mysql_client_encoding• mysql_close• mysql_connect• mysql_create_db• mysql_data_seek• mysql_db_name• mysql_db_query• mysql_drop_db• mysql_errno• mysql_error• mysql_escape_string• mysql_fetch_array• mysql_fetch_assoc

• mysql_fetch_field• mysql_fetch_lengths• mysql_fetch_object• mysql_fetch_row• mysql_field_flags• mysql_field_len• mysql_field_name• mysql_field_seek• mysql_field_table• mysql_field_type• mysql_free_result• mysql_get_client_info• mysql_get_host_info• mysql_get_proto_info• mysql_get_server_info

• mysql_info• mysql_insert_id• mysql_list_dbs• mysql_list_processes• mysql_num_fields• mysql_num_rows• mysql_pconnect• mysql_ping• mysql_query• mysql_real_escape_string• mysql_result• mysql_select_db• mysql_stat• mysql_thread_id• mysql_unbuffered_query

© Novell Inc, Confidential & Proprietary

35

PHP – Common MySQL Functions

• resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )

• int mysql_errno ( [resource link_identifier] )

• string mysql_error ( [resource link_identifier] )

• array mysql_fetch_array ( resource result [, int result_type] )

• resource mysql_query ( string query [, resource link_identifier] )

• bool mysql_select_db ( string database_name [, resource link_identifier] )

© Novell Inc, Confidential & Proprietary

36

PHP – DB Query Example

<?php

//getting the return var is not strictly necessary$conn = mysql_connect('localhost', 'admin', 'novell');

mysql_select_db('address_book', $conn);

$sql = 'SELECT name, address, email ' .' FROM address_book ';

$rs = mysql_query($sql, $conn);

foreach (list($name, $address, $email) = mysql_fetch_row($rs)){

echo ...}

?>

© Novell Inc, Confidential & Proprietary

37

PHP – HTTP Parameter Passing

• HTTP parameters are accessible via “superglobal” variables

• Use on of the following– $_GET['<parameter name>']– $_POST['<parameter name>']– $_REQUEST['<parameter name>']

• It is better security to access your variables with $_GET or $_POST (and only once at that).

© Novell Inc, Confidential & Proprietary

38

Other Useful Functions

• phpinfo()This function display all sorts of useful information

regarding your php setup, and is a great tool for debugging.

• var_dump()Allows you to see the contents and type of your var.

Deploying a LAMP Application

© Novell Inc, Confidential & Proprietary

40

Deploying a LAMP Application

• One of the nicest things about LAMP is how easy the applications are to deploy.

• If apache is set up correctly it is a simple matter of copying your files into the directory that you want your application to reside.

• You do not need to restart anything or deploy anything, just save and copy.

Available Applications/Migration

© Novell Inc, Confidential & Proprietary

42

Applications

• phpMyAdmin (http://www.phpmyadmin.net)• xoops (http://www.xoops.org)• Most everything at http://www.hotscripts.com/ should

work.

© Novell Inc, Confidential & Proprietary

43

Migration

Generally there are no migration issues. Some things you may want to look for in migrating a LAMP application are:

Embedded path problemsSystem calls

© Novell Inc, Confidential & Proprietary

44

References

• http://www.mysql.com• http://www.php.net• http://www.apache.org

Unpublished Work of Novell, Inc. All Rights Reserved.This work is an unpublished work and contains confidential, proprietary, and trade secret information of Novell, Inc. Access to this work is restricted to Novell employees who have a need to know to perform tasks within the scope of their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated, abridged, condensed, expanded, collected, or adapted without the prior written consent of Novell, Inc. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability.

General DisclaimerThis document is not to be construed as a promise by any participating company to develop, deliver, or market a product. Novell, Inc., makes no representations or warranties with respect to the contents of this document, and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. Further, Novell, Inc., reserves the right to revise this document and to make changes to its content, at any time, without obligation to notify any person or entity of such revisions or changes. All Novell marks referenced in this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All third-party trademarks are the property of their respective owners.

top related