Sei sulla pagina 1di 37

LAMP

Linux-Apache-MySQL-PHP

LAMP
LAMP stands for Linux-Apache-MySQLPHP. Instead of PHP, Perl and Python are also used. This is a free and lightweight alternative to WISA, Windows-IIS-SQL Server-ASP (and now, ASP.Net).

Linux

Free as in Freedom
Richard Stallman started the GNU Project and spearheaded the free software movement. Stallman says free represents end users liberties, not the price of software. He has charged for his own software (for making copies and for services), but always allowed his clients to distribute copies as well. But: One cant charge much in a free market economy when people can make copies freely.

Freedoms
Stallman lists these freedoms (http://www.gnu.org):
0. To run the program for any purpose. 1. To study how the program works, and to adapt it to your needs. 2. To redistribute copies to help your neighbor. 3. To improve the program, and release your improvements so that the whole community benefits.

Note: 1 & 3 require access to source code. Free Software Foundation (FSF) was founded to support the GNU Project.

Free vs. Open Source


Stallman reminds that open source does not necessarily mean end user has any freedoms. More recently the term FOSS was coined to represent Free and Open Source Software. There are many open source licenses GPL (GNU Public License) requires improved programs to also remain free. GPL uses copyright to prevent others from copyrighting improvements. This is sometimes called copyleft.

Software as a Service Economy


In a free software world, there would be no software patents. Noone can own software, but the original developer, if still active, would probably be respected to make important decisions. Developers can earn money by their services (extensions, modifications of existing software, fixes, and new software). Support services can be bought and sold.

GNU/Linux
GNU Project GNU Operating System GNU (GNUs Not Unix) was to replace UNIX. Microkernel vs. Monolithic kernel.
Mach microkernel was to complete the GNU OS. In 1992 Andrew Tanenbaum said Linux is Obsolete because Linux has a monolithic kernel. Microkernel is more secure, not as efficient. Today, monolithic kernels are still going strong.

Linux could not have happened without GNU. Stallman requested that GNU/Linux be used.

Unix/Linux: Command Line


Any Unix/Linux user has to know how to use command line and shell. One exception: Mac OS X uses FreeBSD underneath, and has GUI for everything. More recent Linux distributions (see distrowatch.com) have GUI interfaces for most/all tasks.

Unix Commands
A Unix command handles one simple task (eg. ls lists directory contents). Options are passed as command line arguments (as in ls -lF */*.txt, ls --color). Complex tasks are composed of many simple tasks. Commands work together using pipes. Pipes redirect a program's output to another program as input.

Linux Window Managers


Today, much can be done without accessing the command line. Ubuntu vs Kubuntu: The only difference is GNOME versus KDE windows managers. If you use Linux at home, you can install Beryl Window manager. Beryl (based on XGL) is an innovative window manager.

Apache

Apache HTTP Server


Apache has been the most popular web server since April 1996 when it passed NCSA. In April 1996, Apache stood at 29% (and IIS at 1.6%) of the web server market:
http://survey.netcraft.com/Reports/9604/ALL/

Today, Apache stands at 59% (and IIS at 31%):


http://news.netcraft.com/archives/web_server _survey.html

Security
IIS until IIS 6.0 had serious security issues. Those who migrated to Apache have not come back to IIS, even though IIS 6.0 is much more secure:
http://blogs.msdn.com/michael_howard/archive/2004/ 10/15/242966.aspx

Or is it? Maybe some bugs are not reported? IIS 6.0 is complex:
http://blogs.zdnet.com/threatchaos/?p=311

Apache 2 Configuration
Apache 2 configuration: /etc/apache2/*:
apache2.conf general config file httpd.conf not used in Apache 2 sites-available/ default, and other sites (Apache
2 can serve multiple sites with their own IP addresses with one executable)

sites-enabled/ soft-links to enabled sites ... (see /etc/apache2/README)

sites-available/default may have:


DocumentRoot /var/www/

Modules
Most tasks in Apache are handled by modules. Some popular Apache modules:
PHP mod_ssl (SSL: Secure Sockets Layer) OpenSSL FrontPage perl

Apache Software Foundation


Apache Software Foundation (ASF) is a nonprofit organization that develops several highquality open-source programs. Apache HTTP server is one such program. Jakarta project by ASF has a number of highquality Java web development tools:
http://jakarta.apache.org/

Some ASF Java Tools


Derby: Java database (originally IBM Cloudscape; now also called Sun Java DB) Tomcat: Servlet and JavaServer Pages (JSP) Server. Ant: Portable build tool (java make) Struts: Web application framework for input validation and flow control (page-to-page). Lucene: Text indexing/search We have Derby, Tomcat and Ant at the lab.

MySQL

MySQL
MySQL is a popular, scalable, free, open-source database management system (DBMS). It runs on Windows, Linux, and many other operating systems. MySQL AB, the Swedish company that owns the codebase offers services, extra tools, and licensed versions. MySQL AB states that MySQL is used in 11 million installations in the world. We will use phpMyAdmin to access MySQL through Apache.

PHP
PHP is popular, simple and lightweight server-side scripting language used to create dynamic web pages. History:
1995: PHP 2, Personal Home Page Tools 1997: PHP 3, PHP: Hypertext Processor 2000: PHP 4 2004: PHP 5

Some sites that use PHP:


Wikipedia, Yahoo, Digg, Facebook

Server-Side Scripting
On the server, PHP code produces HTML. Client only receives HTML. Client can't view the original PHP code. Compare with HTML:
<b>This is readable on the page</b> <!-- This is visible if you view source --> <?php // PHP source is not visible ?>

Edit-Reload-Test
Quick edit-test cycle: Edit the PHP file on the server (localhost if same machine) and reload the page on the client. The compilation step is not explicit, and the effects of your changes can be quickly discovered. PHP is easy to learn, and quite simple. The next few pages show some sample PHP programs.

info.php
This is always the first PHP file created. A single PHP function creates a very large HTML page detailing everything PHP knows about its execution environment. The file contents are simply:
<?php phpinfo(); ?>

helloworld.php
<html> <head> <title>PHP: Hello World</title> </head> <body> <h1>PHP Says:</h1> <?php echo "Hello World!" ?> </body> </html>

helloform.php
This is a page that uses a form. The page processes its own form. Code structure:
html header PHP processing of user parameter form that allows user to enter his/her name. end of body and html

helloform.php 1/2: PHP Processing


<html> <head><title>PHP: Hello Xyz</title></head> <body> <?php if (array_key_exists('user', $_GET)) {
// Without stripslashes, O'Reilly appears as O\'Reilly

$user = stripslashes($_GET['user']);

} else { $user = 'Stranger'; } ?>


<h1>Hello <?php echo $user ?></h1>

helloform.php 2/2: HTML Form


... (1/2: PHP form processing goes here)

<!-- Normally, you'll use method="POST" --> <form method="GET" action="helloform.php"> Your Name: <input type="text" name="user" size="40"> <input type="submit" name="submit" value="OK"> </form> </body> </html>

colorbox.php
Loops are often used to create html lists and tables with dynamic content. This example uses nested loops to create a colorful table dynamically. Note that the outer loop spans two php code sections, with an HTML section inbetween:
<?php for($red...) { ?> <tr> <?php ... } ?>

<table border="0" cellspacing="0">

<?php for ($red = 0; $red <= 255; $red += 17) { ?>


<tr> <?php for($green = 0; $green <= 255; $green += 17) { // Print color components (red and green; blue = ff) // as two-digit 0-prepended hexadecimals
printf('<td bgcolor="%02x%02xff">&nbsp;&nbsp;&nbsp;',

$red, $green); } } ?> </table>

Potrebbero piacerti anche