Java LAMP How-To:

Installing Linux with Apache, MySQL, PHP and the Tomcat java server

Note From The Author:
 
I hope you find this How-To useful. This work is the result of my wasting probably 80 hours of time trying to bring a new system online to support specific 3rd party applications that required Apache, MySQL, and a Java Server. Those applications preferred Apache 2.0 over 1.3, required MySQL 4.1.x and would not work with MySQL 5.x, and had no particular preference for a PHP version. I attempted many times to install this combination of AMP on Fedora Core 5 Linux, but the biggest problem seemed to be MySQL version 5.x that was included in the FC5 distribution, and I just could not manage to get a 4.1.x version to peacably co-exist with the FC5 RPM-based implementation. While I really do appreciate the nature of RPM's, and I likely could have located just the right RPM's for this combination, I wanted more specific control over the options during configuration.
 
 have written my fair share of PHP/mysql applications, but I had never really built the system from the ground up. So, after a crapload of experimentation, I decided to take a fresh approach to this challenge - and build a system from source code for Apache 2.0.59, MySQL 4.1.21, and PHP 5.1.4. In the steps that follow I try to do more than just tell you what to do. I also want to tell you why I did them. I just hate reading so-called tutorials that assume you know the reasons for making a particular choice. So for you folks that are farther ahead in your understanding, I apologize in advance. You can skip over those sections.
 
I designed this document so you can just copy and paste each line or block of commands into your shell session and it will work as I describe it. These commands do work properly via copy and paste. If
you are having problems and you are not using copy and paste, please re-check your typing before sending me an email saying it doesn't work.
 

Text in a command box like this one is a literal Linux command-line, and should be typed or pasted exactly as written.


Initial System Preparation

 
Please remember that you should only be doing a source-based installation if you need to alter settings in one or more components of the Java LAMP (e.g., you need a feature in PHP or MySQL that isn't in the default RPM build). If you are just getting started with a LAMP-style system, use the binaries provided by your RPM distribution because it is a lot easier to upgrade later using tools like YellowDog Updater (YUM) with RPM's. Going the source route is more complex, so take notes during you implementation and create a README file for yourself so you can review it a couple months or years from now - especially if you memory is like mine.
 
Most out-of-the-box Red Hat Linux installations will have one or more of the Jave LAMP components installed via RPM files. Installing certain applications from source provides the most control over which features are compiled into the application. Source code installations will undoubtably cause un-predictable behavior - if they work at all - if overlaid on top of RPM installs. RPM's will most likely not share the same directories as a source intstallation unless you are painstakingly explicit in the configuration options. So lets avoid all that hassle.
 
If you have not yet installed your Linux OS, or just for future reference, do not choose to install Apache, PHP, or MySQL during the system installation. Then you can immediately proceed with the source-based install listed here.
 

 
Tech Note: To install applications from source code, you will need a C++ compiler (gcc++) installed before we begin. This is generally taken care of during a default installtion of your distribution. You can use your distribution's install CDs to get the proper version of the compiler. Or, if you are using an RPM based distrubution, you can use a site like http://www.rpmfind.net/ to locate the correct RPM version for your system. On a Fedora system, you can do this command:
 
su - root
yum install gcc gcc-c++
 


Log in as root

 
Because we will be installing software to directories that regular users don't have write access to, and also possibly uninstalling RPM versions of some applications, we will log in as the root user. The only steps that need root access are the actual installation steps, but by doing the configure and make steps as root, the source code will also be inaccessible to regular users.
If you do not have direct access (via keyboard) to the server, PLEASE use Secure Shell (SSH) to access the server and not telnet! Whenever you use telnet (or plain FTP for that matter), you are transmitting your username, password, and all session information in plain text. This means that anyone who can access a machine someplace between your PC and your server can snoop your session and get your info. Use encryption wherever possible!
 

su - root



Remove RPM Versions of the Applications

 
Before we start with our source code install, we need to remove all the existing RPM files for these products. To find out what RPMs are already installed, use the RPM query command:
 

rpm -qa

 
in conjunction with grep to filter your results:
 
rpm -qa | grep -i apache
rpm -qa | grep -i httpd
rpm -qa | grep -i php
rpm -qa | grep -i mysql
 
 
The 'httpd' search is included just in case you have Apache2 installed via RPM. I mentioned earlier to avoid installing the applications altogether during your Linux installation, but double check! You might be surprised at how pervasive your distribution is.
For any of the previous commands that generate a result on the command line, remove their associated RPMs with this command...
 

rpm -e filename

Tech Note: If you have any content in your MySQL database already, the RPM removal step should not delete the database files. When you reinstall MySQL, you should be able to move all those files to your new MySQL data directory and have access to them all again. In some cases an RPM module may have dependencies and if you remove it the dependant module may fail. Record any such dependencies. In our case we had a dependency upon the mysql-client module. Be sure any dependants are tested and any dependencies are accomodated for.


Get the Source Code for all Applications

 
We want to put all our source code someplace central, so it's not getting mixed up in someone's home directory, etc.
 

cd /usr/local/src

 
One way application source code is distributed is in what are known as "tarballs." The tar command is usually associated with making tape backups - tar stands for Tape ARchive. It's also a handy way to pack up multiple files for easy distribution. Use the man tar command to learn more about how to use this very flexible tool.
 
When I wrote this document, I had a specific requirement for MySQL version 4.1.xx and not 5.x, so these are the versions of all the components I am using in this How-To:

MySQL - 4.1.21
Apache - 2.0.59
PHP - 5.1.4

Please note: these are the only versions I have verified these steps against. If you use another version of any component, especially a newer version, this HOWTO may not be totally accurate, and I can't provide free support under any circumstances. These are the names of the source packages I used in this example. Please visit apache.org, mysql.org and php.net (respectively) in order to download these versions or the versions of your choice:

httpd-2.0.59.tar.gz
mysql-4.1.21.tar
php-5.1.4.tar.tar
 

Unpack the Source Code

 

tar xf php-5.1.4.tar.tar
tar zxf httpd-2.0.59.tar.gz
tar xf mysql-4.1.21.tar

 
This should leave you with the following directories:
 
/usr/local/src/php-5.1.4
/usr/local/src/apache_2.0.59
/usr/local/src/mysql-4.1.21