LAMPS Tutorial 1.3 (v1.3.6)

This tutorial is about the compilation, installation and configuration of a LAMPS server. It explains, among other things, the installation of Apache 1.3, Mod_Perl, PHP, Mod_SSL, MySQL, PostgreSQL and PDFLib, gives examples and shows how to test the components. The operating system is Linux. The LAMPS tutorial is intended for webmasters and web developers who want to set up a test system.

New:
New versions of MySQL, PHP and OpenSSL


1. LAMPS Tutorial Content

1. LAMPS Tutorial Content

2. The Ingredients and where to find them


2. The Ingredients and where to find them


Linux



Basically, it does not matter which Linux distribution you use. I have chosen Mandrake 7.2 to write this tutorial and verified it with RedHat 7.0, 7.2, 7.3, 8.0 Mandrake 8.0 and Debian 3.0, but all major distributions from version 6 on should work.

I will not explain the installation here, because that would go beyond the scope of this tutorial. Normally, clicking through it is sufficient to get a run capable Linux server system. In case one has forgot something, the packet can always be installed later on.

Linux distributions on Tucows
www.mandrake.com
www.redhat.de
www.suse.de
www.debian.org

Top


Apache 1.3.27



In any case, the Apache web server is needed. At the time I wrote this tutorial, version 1.3.27 was the current one. It probably works for newer versions, at least until version 2.0. However, older versions should not be used, since there are security problems up to version 1.3.26.

Apache Website
Download Apache 1.3.27 (2.2MB)

Top


MySQL 4.0.12



The MySQL version that I currently use is 4.0.12. We'll install a precompiled version of MySQL because of serveral bugs in the gcc compiler.

MySQL Website
Download MySQL 4.0.12 (Mirror)

Top


PostgreSQL 7.3.1



Instead of (or additionally to) MySQL, you may want to use PostgreSQL. PostgreSQL supports transactions, which can be very useful. However, you have to keep in mind not to forget the according entry in the configuration of PHP.

PostgreSQL Website
Download PostgreSQL 7.3.1

Top


PHP 4.3.1



One of the most important things is the current version of PHP. Version 4.3.1 has recently been released, and this is the one we use.

PHP Website
Download PHP 4.3.1

Top


mod_perl 1.27



Since some of my sites are based on Perl, I always install the Apache Perl module. A requirement therefore is, of course, that Perl is installed. But it is mostly installed together with the distribution automatically.


Mod-Perl Website
Download mod_perl 1.27

Top


OpenSSL 0.9.7a



To run Apache on SSL, OpenSSL is necessary for the compilation of the mod_ssl module. I am using OpenSSL version 0.9.7a.

OpenSSL Website
Download OpenSSL 0.9.7a

Top


mod_ssl 2.8.13



Regarding the mod_ssl module, it is important that it fits the Apache. If a newer Apache version is used you have to download the according mod_ssl version from the mod_ssl website.

mod_ssl Website
Download mod_ssl 2.8.13 for Apache 1.3.27

Top


PDFLib 4.0.3



PDFLib enables you to create PDF documents dynamically from PHP, which can be very useful.

PDFLib home page
Download pdflib-4.0.3.tar.gz

Top



3. Preparation - Unpacking the Ingredients

Before we can start, all tar.gz files have to be unpacked. You have to log in as root on the computer and to copy all the files to /usr/local/src/lamps. Of course, it is possible to choose another path, but this is the one we will use in this tutorial.

cd /usr/local/src/lamps
for i in `ls *.gz`; do tar zxf $i; done;


The archive files are no longer needed, but I would like to suggest to save them somewhere, eventually together with this tutorial, as a backup.

Top



4. Cooking - Compilation and Installation


MySQL



The following lines install MySQL. The link from current to 4.0.12 makes it easier to update the MySQL version just by modifying the link. If MySQL was installed as RPM, this section may be skipped.

cd /usr/local/src/lamps
mkdir /usr/local/mysql
mv mysql-standard-4.0.12-pc-linux-i686/ /usr/local/mysql/4.0.12
cd /usr/local/mysql
ln -s 4.0.12/ current
groupadd mysql
useradd -g mysql mysql
cd current
scripts/mysql_install_db
chown -R root .
chown -R mysql data/
chgrp -R mysql .
bin/safe_mysqld &

Afterwards, we create some symbolic links and, finally, change the root password. Of course, you should use your own password instead of 'secret'.

cd /usr/bin
ln -s /usr/local/mysql/current/bin/mysql mysql
ln -s /usr/local/mysql/current/bin/mysqldump mysqldump
ln -s /usr/local/mysql/current/bin/mysqladmin mysqladmin
ln -s /usr/local/mysql/current/bin/mysql_config mysql_config
mysqladmin -u root password 'secret'

Also, an old my.cnf in /etc/ once caused some problems (mysql_install_db installed the database at /var/lib/mysql/data instead of /home/myqsl/data and, so, MySQL did't work). In this case, delete the my.cnf file or rename it.

Additionally, I sometimes fall for missing to enter the MySQL libraries into the lib path. You will realise this after starting the Apache, when you receive an error message that the file libmysqlclient.so.10 cannot be found. If this problem occurs, you will have to open the file /etc/ld.so.conf and add /usr/local/mysql/current/lib/mysql at the end. After that, you will have to execute the following:

/sbin/ldconfig

So, now it should work. In order to start MySQL automatically at boottime, you just have to enter the following lines:

cd /usr/local/mysql/current cp support-files/mysql.server /etc/rc.d/init.d
chmod 744 /etc/rc.d/init.d/mysql.server
cd /etc/rc.d/rc2.d
ln -s ../init.d/mysql.server S20mysql.server
ln -s ../init.d/mysql.server K20mysql.server
cd /etc/rc.d/rc3.d
ln -s ../init.d/mysql.server S20mysql.server
ln -s ../init.d/mysql.server K20mysql.server

Note: Eventually, the chosen distribution uses another runlevel than rc2 or rc3. The actual runlevel can be checked by typing /sbin/runlevel in the console.

Tip: If you do not want to access mysql, mysqldump etc. via their long path, it is very useful to create some links to the programs.


Tip: If you want to use Webmin, there have to be some changes in the module configuration, i.e. regarding the path for the databases.

Top


PostgreSQL



If PostgreSQL shall not be installed, this section may be skipped. In this case, you will have to remember to omit --with-pgsql while compiling PHP.

Now, we compile and install PostgreSQL. The installation is a little trickier compared to MySQL but, at least, it takes less time.

cd /usr/local/src/lamps/postgresql-7.3.1
./configure --prefix=/usr/local/pgsql/7.3.1/
make
make install
ln -s /usr/local/pgsql/7.3.1 /usr/local/pgsql/current
cd /usr/local/pgsql/current
groupadd pgsql
useradd pgsql
mkdir data
chown -R root .
chown -R pgsql data
chgrp -R pgsql .
su - pgsql
cd /usr/local/pgsql/current
bin/initdb -D ./data
exit

As well as regarding MySQL, it is important that the lib path refers to the PostgreSQL files. Therefore, we open the file /etc/ld.so.conf in an editor and add the line /usr/local/pgsql/current/lib at the end (if it is not there yet). Afterwards, we execute /sbin/ldconifg again.

Now, we can create the database. We log in as user pgsql and execute the script initdb.

Then, we copy the start script.

cd /usr/local/src/lamps/postgresql-7.3.1
cp contrib/start-scripts/linux /etc/rc.d/init.d/pgsql
chmod 744 /etc/rc.d/init.d/pgsql

Now, we open the file in an editor and adjust the following lines:

# prefix=/usr/local/pgsql has to be changed to
prefix=/usr/local/pgsql/current

# PGDATA="/usr/local/pgsql/data" has to be changed to
PGDATA="/usr/local/pgsql/current/data"

# PGUSER=postgres has to be changed to
PGUSER=pgsql

We can now start PostgreSQL, create a test database and log in.

Note: You leave the Psql console by \q.

/etc/rc.d/init.d/pgsql start
/usr/local/pgsql/current/bin/createdb -U pgsql test
/usr/local/pgsql/current/bin/psql -U pgsql test

If you do not want to start psql via its long path, you may create a symbolic link.

ln -s /usr/local/pgsql/current/bin/psql /usr/local/bin/psql

In order to start PostgreSQL automatically at boottime, we add some start links.

cd /etc/rc.d/rc2.d
ln -s ../init.d/pgsql S20psql
ln -s ../init.d/pgsql K20psql

cd /etc/rc.d/rc3.d
ln -s ../init.d/pgsql S20psql
ln -s ../init.d/pgsql K20psql

Note: If you want to use Webmin, there have to be some changes in the module configuration, i.e. regarding the path for the databases.

Top


OpenSSL



The installation of OpenSSL is pretty simple. We specify the destination folder by --prefix and create a symbolic link.

cd /usr/local/src/lamps/openssl-0.9.7a
./config --prefix=/usr/local/openssl/0.9.7a
make
make test
make install
ln -s /usr/local/openssl/0.9.7a /usr/local/openssl/current

Does it work? Just a side node: Too much coffee is unhealthy. But it is already one third done.

Top


Apache and Mod_SSL



Now, we are going to build Apache and Mod_SSL. Thereby, Apache will be compiled as DSO version, which means that modules like PHP can be loaded dynamically.

First of all, the Apache sources for Mod_SSL have to be patched. In the same step, we will assign the compiler parameters for Apache. In this way, we will not need the ./configure later on. By --datadir we specify the path to HTML documents.

cd /usr/local/src/lamps/mod_ssl-2.8.13-1.3.27
./configure --with-apache=../apache_1.3.27/ \
--with-ssl=../openssl-0.9.7a/ \
--prefix=/usr/local/apache/1.3.27 \
--enable-module=most \
--enable-shared=max \
--enable-module=ssl

Now, we compile Apache:

cd /usr/local/src/lamps/apache_1.3.27
make

Then we create the certificates. You should answer to the questions as follows. (Of course, you should replace our example company name etc.)

make certificate TYPE=custom

Signature Algorithm: R
Country Name: "DE"
State or Province: "NRW"
Localty Name: "Duesseldorf"
Organization Name: "Mycompany"
Organizational Unit Name: "CA"
Common Name: "Mycompany CA"
Email Address: "ca@mycompany.de"
Certificate Validity: "365"

Certificate Version: 3

Country Name: "DE"
State or Province: "NRW"
Localty Name: "Duesseldorf"
Organization Name: "Mycompany"
Organizational Unit Name: "Webmaster"

Common Name: "testserver.mycompany.de"
Email Address: "www@testserver.mycompany.de"
Certificate Validity: "365"

Certificate Version: 3

Encrypt the private key now: n

Encrypt the private key now: n

That's it for OpenSSL and we can install Apache.

make install
ln -s /usr/local/apache/1.3.27 /usr/local/apache/current

In order to make Apache start while booting, we copy the start script and create links for run level two and three.

cp /usr/local/apache/current/bin/apachectl \
/etc/rc.d/init.d/httpd
chmod 744 /etc/rc.d/init.d/httpd
cd /etc/rc.d/rc2.d
ln -s ../init.d/httpd S20httpd
ln -s ../init.d/httpd K20httpd
cd /etc/rc.d/rc3.d
ln -s ../init.d/httpd S20httpd
ln -s ../init.d/httpd K20httpd

Finally, you should open the file /etc/rc.d/init.d/httpd in a text editor and on the first page you should replace 1.3.27 with current in all paths. In doing so, you will not have to overwrite the apachectl with the new version at the next update.

Now, we can compile the modules.

Top


PDFLib



The installation of PDFLib is also pretty simple. It is just three lines. As mentioned above, this section may be skipped if PDFLib is not needed.

cd /usr/local/src/lamps/pdflib-4.0.3/ ./configure --with-shared-pdflib --enable-cxx
make
make test

The fourth line creates the file pdftest.pdf in folder test. As soon as it exists, we can install PDFLib.

make install

So, PDFLib is installed. In order to make it being found, an entry in the ld.so.conf file is necessary. You have to edit the file and if the line /usr/local/lib does not exist yet, you have to add it. Afterwards, /sbin/ldconfig has to be executed.

Top


PHP



Now, we compile and install PHP. At the end, the config path is set to /etc/. Therein, also php.ini will be saved.

If PostgreSQL, MySQL or PDFLib have not been installed, the according lines in the configure command have to be omitted.

The final lines for GD support may also be omitted, but the GD module can be very helpful regarding the dynamic creation of graphics. Thereby, it has to be considered that additional packets have to be installed (i.e. regarding Redhat gd*.rpm, libjpeg*.rpm, libtiff*.rpm, freetype*.rpm and libpng*.rpm). You can, for example, check this by rpm -qa | grep libjpeg. After executing this command, two lines should appear, one of which conatains "devel".

Now, we can compile it:

cd /usr/local/src/lamps/php-4.3.1
./configure \
--with-apxs=/usr/local/apache/current/bin/apxs \
--with-mysql=/usr/local/mysql/current/ \
--with-pgsql=/usr/local/pgsql/current/ \
--with-pdflib=/usr/local/ \
--with-zlib-dir=/usr/lib/ \
--enable-calendar \
--enable-versioning \
--enable-sockets \
--enable-ftp \
--with-config-file-path=/etc \
--with-gd \
--with-jpeg-dir=/usr/lib \
--with-tiff-dir=/usr/lib \
--with-png-dir=/usr/lib \
--with-freetype-dir=/usr/lib
make
make install

The php.ini has to be copied and that's it.

cp php.ini-dist /etc/php.ini

Top


mod_perl



Configuring mod_perl is easy. A precondition is that Perl is installed. Therefore, just the RPM of your distribution is needed. You can test it by entering:

perl -v

A short message should then appear. The rest is simple:

cd /usr/local/src/lamps/mod_perl-1.27
perl Makefile.PL \
USE_APXS=1 \
WITH_APXS=/usr/local/apache/current/bin/apxs \
EVERYTHING=1

make
make install

By the next restart of Apache, mod_perl should be active.

Top


Miscellaneous and Configuration



Apache

In order to make Apache start with mod_ssl automatically, the start script has to be modified. It is to be found at /etc/rc.d/init.d/httpd. There, you have to search for the "start)" line and to modify it as follows:

start)
if [ $RUNNING -eq 1 ]; then
  echo "$0 $ARG: httpd (pid $PID) already running"
  continue
fi
#original:
#if $HTTPD ; then
#modified, -DSSL inserted:
if $HTTPD -DSSL; then
  echo "$0 $ARG: httpd started"
else
  echo "$0 $ARG: httpd could not be started"
  ERROR=3
fi
;;

If we want PHP to work properly, we have to associate PHP extensions with the module in /usr/local/apache/current/conf/httpd.conf. In the past, this was done in the Config, but from Apache 1.3.23 on, it seems that the according lines have been removed. However, in the httpd.conf you should have something as follows:

<IfModule mod_php4.c>
  AddType application/x-httpd-php .php .php3 .php4 .phtml
  AddType application/x-httpd-php-source .phps
</IfModule>

These lines should be located next to the AddType lines for .tgz and .php.

Since we normally do not want HTML files being the only index file, we have to search for the following line:

DirectoryIndex index.html

Here, we can add other index file names like index.php, index.php4 or default.htm at will and separated by spaces.

Now, the Apache can be started:

/etc/rc.d/init.d/httpd start

You can test it i.e. using Lynx, if you have it installed.

lynx http://localhost

PHP

PHP may very well be tested by creating an info.php in /home/apache/htdocs with the following content:

<?php
phpinfo();
?>

If you open it in Lynx or any other browser, you should get a status page which shows all modules and parameters of PHP. Most of all, you can check if one of the modules has not been compiled.

PDFLib

PDFLib can easily be tested by a small PHP script. (It is important that user nobody has the rights to write in the folder where the script runs.

<?PHP
$file = fopen("php.pdf", "w");
$dokument = pdf_open($file);
pdf_begin_page($dokument,200,100);
pdf_set_font($dokument,"Times-Roman",14, "winansi");
pdf_set_text_pos($dokument,20,50);
pdf_show($dokument,"Gratuliere PDFLib funktioniert");
pdf_end_page($dokument);
$dokument = pdf_close($dokument);
fclose($file);
header("location:php.pdf\n\n");
?>

Miscellaneous

Finally, we can check if SSL runs by entering https://localhost into the browser.

And to be more conform to other distributions, I create a folder /etc/httpd and set links to the conf and the logs folder of Apache:

mkdir /etc/httpd
ln -s /usr/local/apache/current/conf /etc/httpd/conf
ln -s /usr/local/apache/current/logs /etc/httpd/logs

So, the LAMPS system is ready. I would like to suggest to boot the thing in order to check if Apache and MySQL start properly.

Tip: If i.e. SSL does not work although the Apache runs, you can try to take down the firewall to check if eventually the SSL port is locked.

/etc/rc.d/init.d/ipchains stop

The same applies to iptables. But don't forget to restart the firewall by the parameter start as soon as TCP port 443 is unlocked.

Top

Disclaimer









The content of this document may be reproduced on the web, provided that a copyright notice and straight HTML hyperlink to lamps.efactory.de appear on the same page.

eFactory
GmbH & Co. KG
stengel@eFactoryy.de

Goethestraße 75
40237 Düsseldorf

Tel.: 0211 44 03 97-0
Fax: 0211 44 03 97-40