Friday, November 25, 2005

Simple LAMP Setup

Installation

To install, we first need to extract each package. To do this, go into the directory containing the files you have just downloaded. Then type the following command:

# tar -xzvf apache_1.3.xx.tar.gz

# tar -xzvf mysql-3.23.xx.tar.gz

# tar -xzvf php-4.x.x.tar.gz

Next, We need to compile PHP and Apache. In this article we are going to opt for the fastest and best way to run PHP and Apache. That is by compiling them together into one executable. To do this, go into the apache directory and type the following:

# ./configure --prefix=/usr/local/apache

Next, Back out of the apache directory and go into the php directory. Then type the following:

# ./configure --with-mysql --with-xml --enable-track-vars --with-apache=../apache_1.3.xx

# make

# make install

Then, Back out again and go back into the apache directory and type:

# ./configure --prefix=/usr/local/apache --enable-module=rewrite --activate-module=src/modules/php4/libphp4.a

# make

# make install

This will compile and install Apache and PHP into the /usr/local/apache directory.

Now we need to compile and install the MySQL software. To do this, go into the mysql directory and type the following:

#./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --enable-large-files -without-debug

# make

# make install

This will compile MySQL and install its files to /usr/local/mysql. Next, We need to create the user account 'mysql'. This user account is the account mysql runs as. To do this type the following:

# groupadd mysql

# useradd -g mysql mysql

Then we need to install the database files and make some minor ownership changes as follows:

# ./scripts/mysql_install_db

# chown -R root:mysql /usr/local/mysql

# chown -R mysql:mysql /usr/local/mysql/data

Then add the line to your '/etc/ld.so.conf' file:

/usr/local/mysql/lib/mysql

Next we run the mysql daemon. To do this, type the following:

# cd /usr/local/mysql/bin

# ./safe_mysqld --user=mysql &

Finally, we set the root password of the mysql database. To do this, type the following:

# ./mysqladmin -u root password new_password

We should now have Apache, PHP, and MySQL compiled and installed. We now just need to configure them.

Configuration

To configure PHP, copy the php.ini-dist from the php directory to '/usr/local/lib/php.ini'. This file contains most of the settings you would want but you may want to edit it. The one setting you might want to enable is 'register_globals' to 'On' since a lot of PHP scripts use global variables for form data. Other than you may leave it unchanged.

Next we configure Apache. To do this open the file '/usr/local/apache/conf/httpd.conf ' and add the following line right after the line 'AddType image/x-icon .ico':

AddType application/x-httpd-php .php

Then we start the Apache daemon. To do this, type the following:

# /usr/local/apache/bin/apachectl start

To test our PHP and Apache setup create a file in the '/usr/local/apache/htdocs' directory called test.php and put the following code:



Finally, Fire-up your web browser and point it to 'http://localhost/test.php' and you should see a php info webpage complete with settings of php.

Apache, MySQL, and PHP are all configured now and are ready to go!


Originally found here: http://www.sysbotz.com/articles/amp.htm

Friday, June 24, 2005

SCP without passwords

http://www.justenoughlinux.com/2004/04/14/scp_without_passwords.html
http://www.linuxgazette.com/node/193


In this article I'll show you how to use scp without passwords. Then I'll show you how to use this in two cool scripts. One script lets you copy a file to multiple linux boxes on your network and the other allows you to easily back up all your linux boxes.

If you're a linux sysadmin, you frequently need to copy files from one linux box to another. Or you need to distribute a file to multiple boxes. You could use ftp, but there are many advantages to using scp instead. Scp is much more secure than ftp, as scp travels across the LAN /WAN encrypted, while ftp uses clear text (even for passwords.

But what I like best about scp is that it's easily scriptable. Suppose you have a file that you need to distribute to 100 linux boxes. I'd rather write a script to do it than type 100 sets of copy commands. If you use ftp in your script it can get pretty messy, because each linux box you log into is going to ask for a password. But if you use scp in your script, you can set things up so the remote linux boxes don't ask for a password. Believe it or not, this is actually much more secure than using ftp!

Here's an example demonstrating the most basic syntax for scp. To copy a file named 'abc.tgz' from your local pc, to the /tmp dir of a remote pc called 'bozo' use:

scp abc.tgz root@bozo:/tmp

You will now be asked for bozo's root password. So we're not quite there yet. It's still asking for a password so it's not easily scriptable. To fix that, follow this one time procedure (then you can do endless "passwordless" scp copies):

1. Decide which user on the local machine will be using scp later on. Of course root gives you the most power, and that's how I personally have done it. I won't give you a lecture on the dangers of root here, so if you don't understand them, use a different user. Whatever you choose, log in as that user now for the rest of the procedure, and log in as that user when you use scp later on.

2. Generate a public / private key pair on the local machine. Say What? If you're not familiar with Public Key Cryptography, here's the 15 second explanation. In Public Key Cryptography, you generate a pair of mathematically related keys, one public and one private. Then you give your public key to anyone and everyone in the world, but you never ever give out your private key. The magic is in the mathematical makeup of the keys - anyone with your public key can encrypt a message with it, but only you can decrypt it with your private key. Anyway, the syntax to create the key pair is:

ssh-keygen -t rsa

3. In response you'll see:
"Generating public/private rsa key pair"
"Enter file in which to save the key ... "
Just hit enter to accept this.

4. In response you'll see:
"Enter passphrase (empty for no passphrase):"
You don't need a passphrase, so just hit enter twice.

5. In response you'll see:
"Your identification has been saved in ... "
"Your public key has been saved in ... "
Note the name and location of the public key just generated (it will always end in .pub).

6. Copy the public key just generated all your remote linux boxes. You can use scp or ftp or whatever to do the copy. Assuming your're using root (again see my warning in step 1. above), the key must be contained in the file /root/.ssh/authorized_keys (watch spelling!). Or if you are logging in as a user, e.g. clyde, it would be in /home/clyde/authorized_keys. Note that the authorized_keys file can contain keys from other PC's. So if the file already exists and contains text in it, you need to append the contents of your public key file to it.

That's it. Now with a little luck you should be able to scp a file to the remote box without using a password. So let's test it by trying our first example again. Copy a file named 'xyz.tgz' from your local pc, to the /tmp dir of a remote pc called 'bozo'

scp xyz.tgz root@bozo:/tmp

Wow !!! It copied with no password!!

A word about security before we go on. This local PC just became pretty powerful, since it now has access to all the remote PC's with only the one local password. So that one password better be very strong and well guarded.

Now for the fun part. Let's write a short script to copy a file called 'houdini' from the local PC to the /tmp dir of ten remote PC's, in ten different cities (with only 5 minutes work). Of course it would work just the same with 100 or 1000 PC's. Suppose the 10 PC's are called: brooklyn, oshkosh, paris, bejing, winslow, rio, gnome, miami, minsk and tokyo. Here's the script:

#!/bin/sh
for CITY in brooklyn oshkosh paris bejing winslow rio gnome miami minsk tokyo
do
scp houdini root@$CITY:/tmp
echo $CITY " is copied"
done

Works liek magic. With the echo line in the script you should be able to watch as each city is completed one after the next.

By the way, if you're new to shell scripting, here's a pretty good tutorial:
http://www.freeos.com/guides/lsst/.

As you may know, scp is just one part of the much broader ssh. Here's the cool part. When you followed my 6 stop procedure above, you also gained the ability sit at your local PC and execute any command you like on any of the remote PC's (without password of course!). Here's a simple example, to view the date & time on the remote PC brooklyn:

ssh brooklyn "date"

Now let's put these 2 concepts together for one final and seriously cool script. It's a down and dirty way to backup all your remote linux boxes. The example backs up the /home dir on each box. It's primitive compared to the abilities of commercial backup software, but you can't beat the price. Consider the fact that most commercial backup software charges licence fees for each machine you back. If you use such a package, instead of paying licence fees to back remote 100 PC's, you could use the script back the 100 PC's to one local PC. Then back the local PC to your commercial package and save the license fee for 99 PC's ! Anyway the script demostates the concepts so you can write you own to suit your situation. Just put this script in a cron job on your local PC (no script is required on the remote PC's). Please read the comments carefully, as they explain everything you need to know:

#!/bin/sh

# Variables are upper case for clarity

# before using the script you need to create a dir called '/tmp/backups' on each
# remote box & a dir called '/usr/backups' on the local box

# on this local PC
# Set the variable "DATE" & format the date cmd output to look pretty
#
DATE=$(date +%b%d)

# this 'for loop' has 3 separate functions

for CITY in brooklyn oshkosh paris bejing winslow rio gnome miami minsk tokyo
do

# remove tarball on remote box from the previous time the script ran # to avoid filling up your HD
# then echo it for troubleshooting
#
ssh -1 $CITY "rm -f /tmp/backups/*.tgz"
echo $CITY " old tarball removed"

# create a tarball of the /home dir on each remote box & put it in /tmp/backups
# name the tarball uniquely with the date & city name
#
ssh $CITY "tar -zcvpf /tmp/backups/$CITY.$DATE.tgz /home/"
echo $CITY " is tarred"

# copy the tarball just create from the remote box to the /usr/backups dir on
# the local box
#
scp root@$CITY:/tmp/backups/$CITY.$DATE.tgz /usr/backups
echo $CITY " is copied"

done

# the rest of the script is for error checking only, so it's optional:

# on this local PC
# create error file w todays date.
# If any box doesn't get backed, it gets written to this file
#
touch /u01/backup/scp_error_$DATE

for CITY in brooklyn oshkosh paris bejing winslow rio gnome miami minsk tokyo

do

# Check if tarball was copied to local box. If not write to error file
# note the use of '' which says do what's after it if what's before it is not # true
#
ls /u01/backup/$CITY.$DATE.tgz echo " $CITY did not copy" >> scp_error_$DATE

# Check if tarball can be opened w/o errors. If errors write to error file.
tar ztvf /u01/backup/$CITY.$DATE.tgz echo "tarball of $CITY is No Good" >> scp_error_$DATE

done

That's about it. In this article I've tried to give examples that demonstate the concepts, not necessarily to be use "as is". Some of the syntax may not work in all distros, but in the interest of brevity I could not include all the possibilities. For example, if you are using Red Hat 6.2 or before, the syntax will require some changes (I'd be happy to give it to you if you email me). So be creative and hopefully you can use some of this in your own environment.

Optimizing High Traffic Servers

Here is some very valuable information that I'm archiving.

Original URL: http://www.crucialparadigm.com/resources/tutorials/server-administration/optimize-tweak-high-traffic-servers-apache-load.php

Focus: Linux, Apache 1.3+, [PHP], [MySQL]
Notes: Use at your own risk. If this has any errors, please let me know and I will correct them.

Summary
If you are reaching the limits of your server running Apache serving a lot of dynamic content, you can either spend thousands on new equipment or reduce bloat to increase your server capacity by anywhere from 2 to 10 times. This article concentrates on important and poorly-documented ways of increasing capacity without additional hardware.

Problems
There are a few common things that can cause server load problems, and a thousand uncommon. Let's focus on the common:
Drive Swapping - too many processes (or runaway processes) using too much RAM
CPU - poorly optimized DB queries, poorly optimized code, runaway processes
Network - hardware limits, moron attacks

Solutions: The Obvious
Briefly, and for completeness, here are the most obvious solutions:

Use "TOP" and "PS axu" to check for processes that are using too much CPU or RAM.
Use "netstat -anp sort -u" to check for network problems.

Solutions: Apache's RAM Usage
First and most obvious, Apache processes use a ton a RAM. This minor issue becomes a major issue when you realize that after each process has done its job, the bloated process sits and spoon-feed data to the client, instead of moving on to bigger and better things. This is further compounded by a bit of essential info that should really be more common knowledge:

If you serve 100% static files with Apache, each httpd process will use around 2-3 megs of RAM.
If you serve 99% static files & 1% dynamic files with Apache, each httpd process will use from 3-20 megs of RAM (depending on your MOST complex dynamic page).

This occurs because a process grows to accommodate whatever it is serving, and NEVER decreases again unless that process happens to die. Quickly, unless you have very few dynamic pages and major traffic fluctuation, most of your httpd processes will take up an amount of RAM equal to the largest dynamic script on your system. A smart web server would deal with this automatically. As it is, you have a few options to manually improve RAM usage.

Reduce wasted processes by tweaking KeepAlive
This is a tradeoff. KeepAliveTimeout is the amount of time a process sits around doing nothing but taking up space. Those seconds add up in a HUGE way. But using KeepAlive can increase speed for both you and the client - disable KeepAlive and the serving of static files like images can be a lot slower. I think it's best to have KeepAlive on, and KeepAliveTimeout very low (like 1-2 seconds).

Limit total processes with MaxClients
If you use Apache to serve dynamic content, your simultaneous connections are severely limited. Exceed a certain number, and your system begins cannibalistic swapping, getting slower and slower until it dies. IMHO, a web server should automatically take steps to prevent this, but instead they seem to assume you have unlimited resources. Use trial & error to figure out how many Apache processes your server can handle, and set this value in MaxClients. Note: the Apache docs on this are misleading - if this limit is reached, clients are not "locked out", they are simply queued, and their access slows. Based on the value of MaxClients, you can estimate the values you need for StartServers, MinSpareServers, & MaxSpareServers.

Force processes to reset with MaxRequestsPerChild
Forcing your processes to die after a while makes them start over with low RAM usage, and this can reduce total memory usage in many situations. The less dynamic content you have, the more useful this will be. This is a game of catch-up, with your dynamic files constantly increasing total RAM usage, and restarting processes constantly reducing it. Experiment with MaxRequestsPerChild - even values as low as 20 may work well. But don't set it too low, because creating new processes does have overhead. You can figure out the best settings under load by examining "ps axu --sort:rss". A word of warning, using this is a bit like using heroin. The results can be impressive, but are NOT consistent - if the only way you can keep your server running is by tweaking this, you will eventually run into trouble. That being said, by tweaking MaxRequestsPerChild you may be able to increase MaxClients as much as 50%.

Apache Further Tweaking
For mixed purpose sites (say image galleries, download sites, etc.), you can often improve performance by running two different apache daemons on the same server. For example, we recently compiled apache to just serve up images (gifs,jpegs,png etc). This way for a site that has thousands of stock photos. We put both the main apache and the image apache on the same server and noticed a drop in load and ram usage. Consider a page had about 20-50 image calls -- the were all off-loaded to the stripped down apache, which could run 3x more servers with the same ram usage than the regular apache on the server.


Finally, think outside the box: replace or supplement Apache

Use a 2nd server
You can use a tiny, lightning fast server to handle static documents & images, and pass any more complicated requests on to Apache on the same machine. This way Apache won't tie up its multi-megabyte processes serving simple streams of bytes. You can have Apache only get used, for example, when a php script needs to be executed. Good options for this are:

TUX / "Red Hat Content Accelerator" - http://www.redhat.com/docs/manuals/tux/
kHTTPd - http://www.fenrus.demon.nl/
thttpd - http://www.acme.com/software/thttpd/

Try lingerd
Lingerd takes over the job of feeding bytes to the client after Apache has fetched the document, but requires kernel modification. Sounds pretty good, haven't tried it. lingerd - http://www.iagora.com/about/software/lingerd/

Use a proxy cache
A proxy cache can keep a duplicate copy of everything it gets from Apache, and serve the copy instead of bothering Apache with it. This has the benefit of also being able to cache dynamically generated pages, but it does add a bit of bloat.

Replace Apache completely
If you don't need all the features of Apache, simply replace it with something more scalable. Currently, the best options appear to be servers that use a non-blocking I/O technology and connect to all clients with the same process. That's right - only ONE process. The best include:

thttpd - http://www.acme.com/software/thttpd/
Caudium - http://caudium.net/index.html
Roxen - http://www.roxen.com/products/webserver/
Zeus ($$) - http://www.zeus.co.uk

Solutions: PHP's CPU & RAM Usage
Compiling PHP scripts is usually more expensive than running them. So why not use a simple tool that keeps them precompiled? I highly recommend Turck MMCache. Alternatives include PHP Accelerator, APC, & Zend Accelerator. You will see a speed increase of 2x-10x, simple as that. I have no stats on the RAM improvement at this time.

Solutions: Optimize Database Queries
This is covered in detail everywhere, so just keep in mind a few important notes: One bad query statement running often can bring your site to its knees. Two or three bad query statements don't perform much different than one. In other words, if you optimize one query you may not see any server-wide speed improvement. If you find & optimize ALL your bad queries you may suddenly see a 5x server speed improvement. The log-slow-queries feature of MySQL can be very helpful.

How to log slow queries:

# vi /etc/rc.d/init.d/mysqld

Find this line:
SAFE_MYSQLD_OPTIONS="--defaults-file=/etc/my.cnf"

change it to:
SAFE_MYSQLD_OPTIONS="--defaults-file=/etc/my.cnf --log-slow-queries=/var/log/slow-queries.log"

As you can see, we added the option of logging all slow queries to /var/log/slow-queries.log
Close and save mysqld. Shift + Z + Z

touch /var/log/slow-queries.log
chmod 644 /var/log/slow-queries.log

restart mysql
service myslqd restart
mysqld will log all slow queries to this file.

References
These sites contain additional, more well known methods for optimization.

Tuning Apache and PHP for Speed on Unix - http://php.weblogs.com/tuning_apache_unix
Getting maximum performance from MySQL - http://www.f3n.de/doku/mysql/manual_10.html
System Tuning Info for Linux Servers - http://people.redhat.com/alikins/system_tuning.html
mod_perl Performance Tuning (applies outside perl) - http://perl.apache.org/docs/1.0/guide/performance.html

Once again, if this has any errors or important omissions, please let me know and I will correct them.
If you experience a capacity increase on your server after trying the optimizations, let me know!

Article written by spagmoid additions by: albo,huck on the ev1 forums.

Tuesday, February 15, 2005

Setting up a WAMP Server

Originally from http://www.sitewip.com/wamp/

Overview
This document is intended to walk you through the steps to create a full development server on your win32 system. I have tried to include all the steps I used to create a system that will allow you to develop on your local machine and match 95% of actual environment you will experience on a live *nix server.

I have completed this on Windows 95, Windows 98, Windows 2000 Professional +, and Windows XP (both home and professional). Windows 95 & 98 will require you to start the services listed below manually as they do not have a "Services" system like the others.

Required Downloads
The following is a list of the requirements for installing your system. 98% of all software we will discuss will be Open Source (free). Please support Open SourceYou should download these files and store them on your system in a place easy to find later. Once you have all these programs you are ready for the next step. This document will assume you have a c:\disks\ directory and create a new directory for each download ex: c:\disks\mysql\, c:\disks\php\, etc..

MySQL
Site: http://www.mysql.com/
Documentation: http://www.mysql.com/doc/en/index.html
Download: http://www.mysql.com/downloads/index.html (Production release)
The MySQL database server is the world's most popular open source database. Its architecture makes it extremely fast and easy to customize. Extensive reuse of code within the software and a minimalistic approach to producing functionally-rich features has resulted in a database management system unmatched in speed, compactness, stability and ease of deployment. The unique separation of the core server from the table handler makes it possible to run with strict transaction control or with ultra-fast transactionless disk access, whichever is most appropriate for the situation.

PHP
Site: http://www.php.net/
Documentation: http://www.php.net/manual/en/
Download: http://www.php.net/downloads.php (Latest stable version of PHP - Windows Binaries - Zip version not installer Example: PHP 4.3.2 zip package)
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

Apache
Site: http://httpd.apache.org/
Documentation: http://httpd.apache.org/docs/
Download: http://httpd.apache.org/download.cgi (Latest version of Apache Windows Version 1.3.xx - Win32 Binary (MSI Installer) EX: Apache 1.3.28)
The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.Apache has been the most popular web server on the Internet since April of 1996. The July 2003 Netcraft Web Server Survey found that 63% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined.

phpMyAdmin
Site: http://www.phpmyadmin.net
Download: http://www.phpmyadmin.net/ (Downloads Section)
phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the WWW. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields.

Optional Downloads
The following is a list of the optional conponents for your system.
Zend Optimizer
Site: http://www.zend.com/store/products/zend-optimizer.php
Download: http://www.zend.com/store/products/zend-optimizer.php (Free Download)
The Zend Optimizer is a free application that runs the files encoded by the Zend Encoder and Zend SafeGuard Suite, while enhancing the running speed of PHP applications.

Development Tools
The following is a list of development tools that will help you a great deal. If you already have your favorites then stay with them, this is a list of my favorites.

FileZilla
Site: http://filezilla.sourceforge.net/
Documentation: http://filezilla.sourceforge.net/documentation/
Download: http://sourceforge.net/project/showfiles.php?group_id=21558 (Newest Version)
FileZilla is a fast FTP client for Windows with a lot of features. FileZilla Server is a reliable FTP server.

WebDrive
Site: http://www.webdrive.com/products/webdrive/index.html
Documentation: http://www.webdrive.com/support/webdrive/webhelp/webdrive.htm
Download: http://www.webdrive.com/download/index.html (Newest Version)
WebDrive is not free, but in my opinion is one of the greatest time saver tools I have for web development. This tool allow you to map a remote FTP drive to your local drive letter. This allows you to edit files live while online. No more download, modify, upload, view, etc..WebDrive integrates your web or FTP server into the Windows file system by mapping it to a drive letter. This enables you to connect to the server and perform familiar file operations like copy, move, and directory functions with the Windows explorer. Using simple drag and drop, you can transfer individual or multiple files - even entire directory structures. WebDrive offers FTP client functionality that's feature-rich and easy to use.

PuTTY
Site: http://www.chiark.greenend.org.uk/~sgtatham/putty/
Documentation: http://www.chiark.greenend.org.uk/~sgtatham/putty/docs.html
Download: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html (Newest Version)
PuTTY is a free implementation of Telnet and SSH for Win32 platforms, along with an xterm terminal emulator. It is written and maintained primarily by Simon Tatham.

Shell Utils
Download: shell_tools.zip
This is a collection of shell tools that allow you to type unix style commends on your win32 system. While it is allways recommended you use the build in functions of PHP, there are times when you need to make a shell call. These tools will allow the command to run and will preform the task correctly (if applicable), and if not (ex: chmod) will not return an error.

TortoiseCVS
Site: http://www.tortoisecvs.org/
Documentation: http://www.tortoisecvs.org/support.shtml
Download: http://www.tortoisecvs.org/download.shtml (Stable Version)
This software is ONLY valuable if you are developing using a CVS server.TortoiseCVS is an extension for Microsoft Windows Explorer that makes using CVS fun and easy. Features include: coloured icons, tight integration with SSH, and context-menu interactivity.

7-Zip
Site: http://www.7-zip.org/
Documentation: http://www.7-zip.org/support.html
Download: http://www.7-zip.org/download.html (7-Zip for Windows 98/ME/NT/2000/XP)
I do not use this program, I use WinZip but this is a free product so I am listing it.7-Zip is a file archiver with the highest compression ratio. The program supports 7z, ZIP, RAR, CAB, GZIP, BZIP2 and TAR formats. Compression ratio in the new 7z format is 30-50% better than ratio in ZIP format. 7-Zip has powerful command line version.

WinSCP
Site: http://winscp.sourceforge.net/eng/index.php
Documentation: http://winscp.sourceforge.net/eng/docs/
Download: http://winscp.sourceforge.net/eng/download.php (Latest Version)
This is a great and secure alternative to FTP. WinSCP is an open source SFTP client for Windows using SSH. Legacy SCP protocol is also supported. Its main function is the safe copying of files between a local and a remote computer. Beyond this basic function, WinSCP manages some other actions with files.

Install MySQL
Installing MySQL should be very quick and painless. The install program should take care of everything you need.

The MySQL database server is the world's most popular open source database. Its architecture makes it extremely fast and easy to customize. Extensive reuse of code within the software and a minimalistic approach to producing functionally-rich features has resulted in a database management system unmatched in speed, compactness, stability and ease of deployment. The unique separation of the core server from the storage engine makes it possible to run with strict transaction control or with ultra-fast transactionless disk access, whichever is most appropriate for the situation.

The MySQL database server is available without a license fee under the GNU General Public License (GPL). Commercial non GPL licenses are available for users who prefer not to be restricted by the terms of the GPL.

  1. Unzip the install file. EX: c:\disks\mysql\mysql-4.0.14b-win.zip
  2. Run setup.exe (leave destination c:\mysql, unless you want to move it.)
  3. Select Typical install, or custom if you wish to see / change options
  4. Let Install finish.
  5. Run c:\mysql\bin\winmysqladmin.exe, and set your username and password for this tool. This will start the mysql service.
  6. Reboot your computer
  7. Open 'Services' located in control panel Administrative Tools. You will should see mysql listed.
  8. Open a command prompt Start Programs Accessories Command Prompt
  9. Change Directory to the MySQL bin directory (c:\mysql\bin\)
  10. We are not going to change your root passwordType mysqladmin -uroot password ex: mysqladmin -uroot password secret.Make a note of this password. It will be your superuser root access password for MySQL.

You are all finished installing MySQL !!

Install PHP
We will now install and configure your PHP.

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

PHP stands for PHP: Hypertext Preprocessor. This confuses many people because the first word of the acronym is the acronym. This type of acronym is called a recursive acronym.

  1. Unzip the install file. EX: c:\disks\php\php-4.3.2-Win32.zip
  2. Create the php directory c:\php
  3. Copy the contents of the zip file into c:\php, the php.exe program should be in c:\php\
  4. Copy the contents of the dll directory to your system32 directory (ex: c:\winnt\system32)
  5. Copy 'php4ts.dll' to your system32 directory (ex: c:\winnt\system32)
  6. Copy c:\php\php.ini-dist to c:\php\php.ini and open this file in a text editer.
  7. Locate the section for "Paths and Directories" and change the ;include_path = to 'include_path = ".;/php/pear"'
    This will set the path for PHP to look for files. First it will look in the current directory and this will also allow you to use PEAR tools.
  8. Locate the 'register_globals' variable and insure it is set to 'register_globals = On'. NOTE: For a production server it is safer to have this set to off, but for development I have found many times that other programmers do not code for this, so I must keep it on.
  9. Locate the 'extension_dir' variable and insure that it is set to 'extension_dir = C:/php/extensions/', this will allow PHP to find the extentions.
  10. Locate the 'SMTP' varable and modify this to your needs. This is the server that will send out emails in PHP. In most cases you can set this to you mail server for your web host, in other cases you may need to set this to the server of your ISP.
  11. Move c:\php\php.ini to your windows directory ex: c:\winnt

You are all finished installing PHP!!

Install Apache
We will now install and configure your Apache.

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

Apache has been the most popular web server on the Internet since April of 1996. The July 2003 Netcraft Web Server Survey found that 63% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined.

  1. Run the install program located in your download directory (ex: c:\disks\apache\apache_1.3.28-win32-x86-no_src.msi)
  2. When prompted for 'Server Information' enter the name of the computer in the domain and server names. Enter your email address in the email address line.
    If you are unsure of your computer name you should find it in your 'Network Identification' tab of your system properties
  3. Select 'Complete' for the install type.
  4. You should now see Apache listed in your services.
  5. To test your install open a browser and enter the address 'http:///' and you will see a welcome page from apache. ex: (http://my-computer/)
  6. Create a working directory for web sites. If you work with only one server you can have this match the live server you use, or you can set your own. I use c:\www this way I can backup one directory and have all my working web sites. ex: (c:\www)
  7. Open the httpd.conf file in your apache install directory. (C:\Program Files\Apache Group\Apache\conf)
    This file control your web server and allows you to create web sites. We will simply update your working directory.
    Locate 'DocumentRoot' and update this to your web root directory we just created. ex:
    DocumentRoot "C:/www"
    Locate

    Directory "C:/Program Files/Apache Group/Apache/htdocs"

    and update this to match the same as above. ex:

    Directory "C:/www"

    Locate 'DirectoryIndex' and add 'index.php, index.php3' the end of the line. (ex: DirectoryIndex index.php, index.php3, index.html)
  8. At the very bottom of this file add the following lines.

    # Load PHP & USE vhost.conf for domains
    LoadModule php4_module "C:\php\sapi\php4apache.dll"
    AddModule mod_php4.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3
    #include conf/vhost.conf

    This section will tell Apache to process all .php & .php3 files through PHP and in advanced features we can setup new domains on this web server. You can add different extensions for PHP if you wish, but for now this should work.
  9. From your 'Services' program restart Apache. NOTE: All changes to php.ini or httpd.conf REQUIRE your to restart apache for them to go into effect.
  10. Create a file named 'phpinfo.php' in your new web root (ex: c:\www) and add the following code to the file. This program will help you to text and find important information your server.


    Point your browser to http://your_server_name/phpinfo.php and you should see the phpinfo screen. This will tell you that you have apache working with PHP.

Congratulation you are all finished installing Apache!!

Install phpMyAdmin
Installing phpMyAdmin should be very simple and will test to insure PHP, MySQL, and Apache are all talking.

phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the WWW. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields.

  1. Unzip the install file. EX: c:\disks\phpmyadmin\phpMyAdmin-2.5.3-rc2-php.zip
  2. Create a directory in your web root named 'phpMyAdmin'. I recommend keeping the same case as listed as modt live web servers do as well. (ex: c:\www\phpMyAdmin\).
  3. Copy the contents of the zip into this new folder.
  4. Edit the c:\www\phpMyAdmin\config.inc.php file and modify

    $cfg['Servers'][$i]['password']='';

    to

    $cfg['Servers'][$i]['password']='YOURPASSWORDHERE';

    This is the password your created when intalling MySQL.
  5. Point your browser to http:///phpMyAdmin/ (ex: http://my-computer/phpMyAdmin/)

You are all finished installing phpMyAdmin !!

Resource Links
These links have been invaluable resources and are my favorites.
*** HotScriptsHotScripts is one of the best resources for open source PHP code.
*** SourceForgeSourceForge is one of the best resources for all types of open source code.
*** PHP ClassesPHP Classes has a great resource of Open Source PHP classes.

Help & Tutorial Links

Developer ShedDevShed has a user run forum.

Copyright © 2003 Amalla International, All rights reserved.
http://www.amalla.com/

Wednesday, February 09, 2005

This is some good general linux information... Not php, but very useful...

Title Detecting hardware from outside the box
Date 2005.02.02 10:07
Author Beret
Topic
http://enterprise.linux.com/article.pl?sid=05/02/02/159213
Linux comes with several good utilities for getting detailed information on what's inside the box. Here are three recipes for getting information from lspci, dmesg, and /proc.


This article is excerpted from the recently published book "The Linux Cookbook."

Detecting hardware with lspci

You're looking at new systems, or installing Linux on a box that used to run a different OS, and you're wondering if all the components -- video, modem, Ethernet, sound -- will work on Linux. The vendors can't, or won't, tell you if their products will work on Linux. You need to know what the chipsets are, to find out if there are Linux drivers.

Alternatively, you want to know what components are installed inside a computer, and you don't feel like hauling the thing out, popping the case open, and tearing it apart.

Solution: Use lspci:

# /sbin/lscpi# /sbin/lspci -v# /sbin/lspci -vv

To show a summary of all devices connected to the PCI bus, use:

$ /sbin/lspci
00:00.0 Host bridge: VIA Technologies, Inc. VT8363/8365 [KT133/KM133] (rev 02)
00:01.0 PCI bridge: VIA Technologies, Inc. VT8363/8365 [KT133/KM133 AGP]
00:06.0 Ethernet controller: Linksys Network Everywhere Fast Ethernet 10/100 model NC100 (rev 11)
...

Use the -v or -vv flags to display more information:

# /sbin/lspci -v
0000:01:00.0 VGA compatible controller: 3Dfx Interactive, Inc. Voodoo 3 (rev 01) (prog-if 00 [VGA])
Subsystem: 3Dfx Interactive, Inc.: Unknown device 1252
Flags: 66MHz, fast devsel, IRQ 10
Memory at d4000000 (32-bit, non-prefetchable) [size=32M]
Memory at d8000000 (32-bit, prefetchable) [size=32M]
I/O ports at c000 [size=256]
Expansion ROM at [disabled] [size=64K]
Capabilities: [54] AGP version 1.0
Capabilities: [60] Power Management version 1

If you're looking for drivers, you can now take this output (e.g., VT8363/8365 or 3Dfx Interactive, Inc. Voodoo 3 (rev 01)) to run a Google search.

lspci reads some information from the PCI bus, then displays additional information from its own database of hardware IDs -- vendors, devices, classes and subclasses -- at /usr/share/misc/pci.ids. There is even a command to update this file:

# update-pciids

The lspci maintainers welcome submissions of new data; please read /usr/share/misc/pci.ids for how to make submissions.

If there is a device attached to the system that the lspci simply does not recognize, such as a very old, odd ISA device, you'll have to open the case to see what it is. Or try running dmesg (Recipe 5.3).

Using dmesg to collect hardware information

PCI is fine, but it's yesterday's news; you need an inventory of all the devices on the system, not just PCI devices. You're interested in USB devices, SCSI devices, memory configuration, even the CPU.

Solution: Use dmesg. dmesg is a record of everything detected by the kernel.

To view all dmesg output, use:

$ dmesg less

You can also filter the output of dmesg to find specific devices. For example, to list all USB devices, use:

$ dmesg grep -i usb

To list ISA devices, use:

$ dmesg grep -i isa
isapnp: Scanning for PnP cards...
isapnp: SB audio device quirk - increasing port range
isapnp: Card 'SupraExpress 56i Voice'

To see how much physical memory is on the system, use:

$ dmesg grep -i memory
Memory: 256492k/262080k available (1467k kernel code, 5204k reserved, 516k data, 96k init, 0k highmem)

This shows IDE devices using the SCSI emulation subsystem, which is used on 2.4 and older kernels:

$ dmesg grep -i scsi
Kernel command line: root=/dev/hda6 ro hdb=scsi hdc=scsi
ide_setup: hdb=scsi
ide_setup: hdc=scsi
SCSI subsystem driver Revision: 1.00
hdb: attached ide-scsi driver.
hdc: attached ide-scsi driver.
scsi0 : SCSI host adapter emulation for IDE ATAPI devices
...

Here are what "real," not emulated, SCSI devices look like:

$ dmesg grep -i scsi
SCSI subsystem driver Revision: 1.00
scsi0 : Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev 6.2.8

aic7892: Ultra160 Wide Channel A, SCSI Id=7, 32/253 SCBs
...Vendor: IBM-PSG Model: DPSS-336950M M Rev: S9HA
Attached scsi disk sda at scsi0, channel 0, id 0, lun 0
(scsi0:A:0): 160.000MB/s transfers (80.000MHz DT, offset 63, 16bit)
SCSI device sda: 71096640 512-byte hdwr sectors (36401 MB)
Partition check:
sda: sda1 sda2 sda3 sda4 <>

Shown here is information about a USB camera that is connected to the system, including its location in the filesystem. Typically, USB output runs to a dozen lines or more:

$ dmesg grep -i usb
...
usb.c: registered new driver ibmcam
ibmcam.c: IBM PC Camera USB camera found (model 2, rev. 0x030a)
usbvideo.c: ibmcam on /dev/video0: canvas=352x240 videosize=352x240

To show serial ports, use:

$ dmesg grep -i tty
ttyS00 at 0x03f8 (irq = 4) is a 16550A

To show CPU or CPUs, use:

$ dmesg grep -i cpu
Initializing CPU#0
CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line)
CPU: L2 Cache: 64K (64 bytes/line)
Intel machine check reporting enabled on CPU#0.
CPU: After generic, caps: 0183f9ff c1c7f9ff 00000000 00000000
CPU: Common caps: 0183f9ff c1c7f9ff 00000000 00000000
CPU: AMD Duron(tm) Processor stepping 01

Note that these searches only return lines containing your search string. There is often more information adjacent to these lines, which you'll find by eyeballing the whole file:

Initializing CPU#0
Detected 801.446 MHz processor.

dmesg always provides up-to-date information, even if you're changing hardware frequently (for example, plugging in and detaching hotplug USB devices).

Getting live hardware snapshots with /proc

You want to monitor a running system in real time, and view things like physical memory and CPU information, or identify drives.

Solution: Read the /proc virtual filesystem. Use only cat to read /proc, or utilities designed expressly for it, such as sysctl, lspci, ps, and top. The syntax is the same as for reading any file:

$ cat /proc/filename

You can explore /proc just like any filesystem and easily find the information you want. Look to the named folders for hardware information:

$ ls /proc
bus cmdline cpuinfo devices dma driver filesystems ide kcore kmsg ksyms loadavg
meminfo misc modules mounts mtrr partitions pci scsi swaps sys tty

For example, to show CPU information, use:

$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 3
model name : AMD Duron(tm) Processor
stepping : 1
cpu MHz : 801.442
...

To show physical memory and swap usage, use:

$ cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 262746112 237740032 25006080 0 11575296 150138880
Swap: 534601728 81661952 452939776
MemTotal: 256588 kB
MemFree: 24420 kB
...

To tell all about an IDE hard drive, use:

$ cat /proc/ide/via
-------VIA BusMastering IDE Configuration---------
Driver Version: 3.37
South Bridge: VIA vt82c686a
Revision: ISA 0x22 IDE 0x10
Highest DMA rate: UDMA66
BM-DMA base: 0xd400
PCI clock: 33.3MHz
...

To see disk geometry, both real and logical, use:

$ cat /proc/ide/ide0/hda/geometry
physical 39870/16/63
logical 2501/255/63

To identify a drive, use:

$ cat /proc/ide/ide0/hda/model
IBM-DTLA-305020

To show driver versions for all IDE drivers, use:

$ cat /proc/ide/drivers
de-scsi version 0.93
ide-cdrom version 4.59-ac1
ide-floppy version 0.99.newide
ide-disk version 1.17
ide-default version 0.9.newide

To show capabilities of CD drives, use:

$ cat /proc/sys/dev/cdrom/info
CD-ROM information, Id: cdrom.c 3.12 2000/10/18
drive name: sr1 sr0
drive speed: 40 32
...
Can read multisession: 1 1
Can read MCN: 1 1
Reports media changed: 1 1
Can play audio: 1 1
Can write CD-R: 1 0
Can write CD-RW: 1 0
Can read DVD: 0 1
Can write DVD-R: 0 0
Can write DVD-RAM: 0 0

To show SCSI devices, using the following command. Note that it does not differentiate between devices attached to the SCSI bus and IDE devices using the SCSI-emulation subsystem. These are IDE CD drives:

$ cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: TOSHIBA Model: DVD-ROM SD-M1202 Rev: 1020
Type: CD-ROM ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: LITE-ON Model: LTR-24102B Rev: 5S54
Type: CD-ROM ANSI SCSI revision: 02

For AMD Users
Since AMD went to "performance ratings," instead of plain ole gigahertz, CPU ratings can be confusing. Your shiny new Athlon 3200 won't appear in /proc/cpuinfo as "cpu MHz 3200" -- instead, it will be something like 2800. You're not being ripped off; that's a result of how AMD chooses to rate the performance of their processors. In a nutshell, they claim that clock speed alone is not an accurate measure of performance, so they devised a different scale that more accurately reflects the CPU's true abilities. Visit http://www.amd.com for details.

On the other hand if your Pentium 3200 shows up in /proc/cpuinfo as a number other than 3200, there is a problem, because Intel uses the literal clock speeds.

This following command is just plain fun and has absolutely no practical value. It requires a functioning sound system. Warning: it's noisy -- this is the sound of your CPU in action. Ctrl-C stops it:

# cat /proc/kcore > /dev/dsp
Disk geometry, as expressed by /proc or any other utility, is largely a fiction. Modern drives are far more complex than the old "heads sectors cylinders" model.

As mentioned earlier, to read /proc use only cat or utilities designed expressly for it, such as sysctl, lspci, ps, and top. Pagers like less and more give a different picture, because they re-read /proc with each page. And you don't want to use a text editor, or any utility with write powers, because you can mess up your system in a heartbeat.


Links

--------------------------------------------------------------------------------


"The Linux Cookbook" - http://%0D%0Aservice.bfast.com/bfast/click?bfmid=2181&sourceid=39391960&isbn=0596006403
"http://www.amd.com" - http://www.amd.com/

Monday, February 07, 2005

I thought i'd like writing about programming, but since i do it all day long at work, it's kinda boring... sorry folks...