PDA

View Full Version : Deploying LAMPS for your web development


Banki
02-23-2009, 01:45 AM
Deploying LAMPS for your web development

Introduction

This document will teach you to set up and configure a LAMP system for web development.


Why LAMP?

LAMP [Linux, Apache, MySQL, PHP] refers to a set of software tools that allow for rapid development and deployment of sophisticated, robust web applications of all sorts.

All components of LAMP can be downloaded and used for free. This helps a lots in cost savings, which is why so many large organizations are moving to Linux and other open source solutions for a variety of projects.

Although LAMP components are provided with non-profit making, there’s still a surprisingly extensive support network for all LAMP components. There are literally millions of LAMP users who congregate in online communities like onlamp.com/ to help each other get the most out of LAMP. Training is available from a wide array of providers, and many consulting firms offer advanced capabilities for those businesses that require sophisticated LAMP development.

Perhaps most importantly, LAMP works well. Its component technologies offer tremendous flexibility, rapid development, high performance, and fewer security and stability problems than many far-costlier proprietary solutions.


The Components of LAMP

Linux
An operating system most often used to run servers, Linux is a lean performer that can run quite well even on older hardware (such as an old Pentium II).

Apache
The most widely used web server software in the world , Apache can be run on a variety of operating systems, including AIX, Digital UNIX, FreeBSD, Irix, Mac OS X, Netware, OpenBSD, Solaris, SunOS, Windows, and of course, Linux. Apache's security record is far better than that of Microsoft IIS.

MySQL
This databasee was built with the attitude that a web database should be lean and fast. It doesn't incorporate the diverse array of application server features that Oracle and Microsoft database tools do, instead focusing on core performance and leaving enhanced functions to scripting languages. MySQL runs on a variety of operating systems, including AIX, FreeBSD, Mac OS X, Solaris, Windows, and Linux. It is well known for its reliability.

PHP
Developed from the ground up as a web developer's language, PHP is easy to use and executes very quickly. Skilled developers can use PHP to build everything from online forms to complex database-driven web applications. PHP is extremely popular, runs on a variety of operating systems, and is most often used in conjunction with MySQL.


Before Installation

Assumed that you have the Linux installed.

Make sure you have downloaded all the relevant software:

(1) The latest binary version of MySQL (currently MySQL 4.1.3-beta), available from MySQL.com
(2) The latest version of PHP (currently PHP 5.0.0), from Php.net
(3) The latest version of Apache 2 (currently Apache 2.0.50), from Apache.org

Copy all of these to your /tmp directory and decompress them as follows:

$ cd /tmp
$ tar -xzvf mysql-standard-4.1.3-beta-pc-linux-i686.tar.gz
$ tar -xzvf php-5.0.0.tar.gz
$ tar -xzvf httpd-2.0.50.tar.gz

MySQL server installation

Detailed installation instructions for MySQL are provided in the download archive, but here's a fast recap:

Move the decompressed MySQL archive to /usr/local/mysql:

$ mv /tmp/mysql-standard-4.1.3-beta-pc-linux-i686 /usr/local/mysql

Create a user and group for MySQL:

$ groupadd mysql
$ useradd -g mysql mysql

Initialize the MySQL grant tables with the provided mysql_install_db script:

$ /usr/local/mysql/scripts/mysql_install_db --user=mysql [/output]

Give the MySQL user rights to the MySQL directory:

$ chown -R root?/usr/local/mysqll
$ chgrp -R mysql /usr/local/mysql
$ chown -R mysql /usr/local/mysql/data

Start the MySQL server:

$ /usr/local/mysql/support-files/ mysql.server start [/output]

At this point, also check to make sure that the MySQL server socket has been created in /tmp it usually has a name like mysql.sock.


Administering your MySQL Database

Once the MySQL server is installed successfully, most of the users would not like to administer their database with the command line. I definitely understand this and for those users who do not like to use command line, I suggest you to get a MySQL administration GUI, one of the available GUI in the markets with relatively lower cost is Navicat. If you would like to adopt a free tool, MySQL administrator provided by MySQL Ab is also a good alternative. I personally use Navicat for its simplicity and also for its speed. Navicat allows you to edit your data directly and one of the feature I like so much is that it allows me to test running for queries before actually putting it into the php scripts! J Navicat also has other features like backups, schedulers which is necessary for good database maintenance. Some features which I haven’t tested it out is its Reporting functions. I believe it will be useful for those need to generate reports for their data. For more information, please visit http://www.navicat.com/.


Apache server + PHP installation

There are two ways of using PHP with Apache: as a dynamic module that can be loaded into the Web server at run-time, or as a static module that is directly compiled into the Web server code. For this tutorial, I'm going with the first option.

To enable dynamic loading of PHP as an Apache 2.0 module, the Apache server must be compiled with Dynamic Shared Object (DSO) support. This feature can be enabled by passing the --enable-so option to the Apache 2.0 configure script:

$ cd /tmp/httpd-2.0.50
$ ./configure --prefix=/usr/local/apache2 --enable-so
$ make && make install

This should configure, compile, and install the server to /usr/local/apache2.


Installing PHP

With both MySQL and Apache installed, the final step is to compile and install PHP. The most important step in this process involves providing the PHP configure script with a list of extensions to activate, as well as the correct file paths for the external libraries needed.

This might look complicated, but it's really not: The --prefix argument sets the installation path for the PHP 5.0 binaries.
The --with-apxs2 argument tells PHP where to find Apache 2.0 and its apxs script (used to handle extensions).
The --with-libxml-dir and --with-zlib-dir arguments tell PHP where to locate the libxml2 and zlib libraries. Note that you need to use these options only if you compiled and installed the libraries yourself; if you're using your distribution's default libraries, PHP should be able to find them automatically.
The --with-mysql argument activates the regular MySQL extension. Note that in PHP 5.0, this is not active by default (as it was in PHP 4.0) and must be explicitly named in configure to be activated.
The --with-mysqli argument activates the new MySQL Improved extension (for MySQL 4.1.2+ only), and must point to the mysql_config script that comes with MySQL 4.x.
The --with-gd argument activates the GD extension for dynamic image creation.
The --with-zlib argument activates the ZLIB compression library for on-the-fly data compression.
The --enable-sockets argument activates socket communication features.
The --enable-soap argument activates support for SOAP and Web services.A number of other options and extensions are also possible

$ ./configure –help for a complete list.

Once the configure script finishes processing, you can compile and install PHP.

$ make
$ make install

Note that the installation process is intelligent enough to place the PHP module in the correct directory for Apache 2.0 to find it.


Configuring and testing Apache with PHP

The final step consists of configuring Apache to recognize PHP scripts and then hand them over to the PHP interpreter for processing. To do this, edit the Apache configuration file, /usr/local/apache2/conf/httpd.conf, and add the following line to it:

AddType application/x-httpd-php .php

Save the file and then start the server:

$ /usr/local/apache2/bin/apachectl start [/output]

You can now test whether all is working as it should by creating a simple test script in the server's document root: /usr/local/apache2/htdocs/.

Name the script test.php, and populate it with these lines:

<?php
phpinfo();
?>

Save the file and then point your browser to

http://localhost/test.php

You should be able to see a page with the details on your Server environments.


Conclusion

With LAMP properly set up, you should be able to build your web site in a stable, reliable and efficient environment. Deploying LAMP system has substantial advantages, and these will be recognized by more and more people with time.


Reference

Linux:
http://www.linux.org/

Apache:
http://www.apache.org/

MySQL:
http://www.mysql.com/

Php:
http://www.php.net/

Navicat:
http://www.navicat.com/

This original document:
http://www.geocities.com/mchuthor/LAMPS.htm

Cheers. :D