julmajanne.com

LAMP on Debian (Etch)

This document tries to describe how to install LAMP on Debian (etch) from source.

Disclaimer! This is not definitive guide, but a personal notes of how to do this kind of stuff. So everything you read from these pages you shall comprehend at your own risk!

Foreplay

Meaning the stuff you'll need to take under consideration before you start to install LAMP on Debian from source code. So get all the needful things you need at hand, like smokes, coffee, alcohol, vintage Hustler magazines, etc...

Step 1 - Install Debian

Install Debian Etch as small as you can! I use net-install CD-image to do this. Don't install any additional software! Uncheck all the choices when the installation process asks you to choose what additional software you'd like to install. After installation upgrade your system ( apt-get upgrade ).

Step 2 - Install necessary development packages

Use apt-get to install some necessary software we'll need to perform the task at hand.

Install ssh and basic development packages:

server:~#apt-get install ssh dpkg-dev file gcc g++ libc6-dev make patch perl autoconf flex bison bzip2 less

Step 3 - Install Apache

Get apache source code and install it:

server:~#cd /usr/local/src
server:~#wget http:///apache/httpd/httpd-2.0.61.tar.bz2

I want to use secure socket layer with apache, so we'll need to install some additional packages for it:

server:~#apt-get install openssl libssl-dev ca-certificates

Unpack the source code, configure and install:

server:~#tar -xjvf httpd-2.0.61.tar.bz2
server:~#./configure --prefix=/usr/local/apache2 --enable-mods-shared=most \
--enable-so --with-mpm=prefork --enable-ssl --with-ssl=/usr
server:~#make && make install

Start up the server:

server:~#/usr/local/apache2/bin/apachectl start
server:~#/usr/local/apache2/bin/apachectl stop

Create a start up script in /etc/init.d called apache:

#! /bin/bash
#
# apache        Start the apache HTTP server.
#


NAME=apache
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/local/apache2/bin/httpd
PIDFILE=/usr/local/apache2/logs/httpd.pid
CONF=/usr/local/apache2/conf/httpd.conf
APACHECTL=/usr/local/apache2/bin/apachectl

trap "" 1
export LANG=C
export PATH

test -f $DAEMON || exit 0
test -f $APACHECTL || exit 0

# ensure we don't leak environment vars into apachectl
APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL"

if egrep -q -i "^[[:space:]]*ServerType[[:space:]]+inet" $CONF
then
    exit 0
fi

case "$1" in
   start)
     echo -n "Starting web server: $NAME"
     start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON
     ;;

   stop)
      echo -n "Stopping web server: $NAME"
      start-stop-daemon --stop --pidfile $PIDFILE --oknodo
      ;;

   reload)
      echo -n "Reloading $NAME configuration"
      start-stop-daemon --stop --pidfile $PIDFILE \
        --signal USR1 --startas $DAEMON
      ;;

   reload-modules)
      echo -n "Reloading $NAME modules"
      start-stop-daemon --stop --pidfile $PIDFILE --oknodo \
        --retry 30
      start-stop-daemon --start --pidfile $PIDFILE \
        --exec $DAEMON
      ;;

   restart)
      $0 reload-modules
      exit $?
      ;;

   force-reload)
      $0 reload-modules
      exit $?
      ;;

   *)
      echo "Usage: /etc/init.d/$NAME {start|stop|reload|reload-modules|force-reload|restart}"
      exit 1
      ;;
esac

if [ $? == 0 ]; then
        echo .
        exit 0
else
        echo failed
        exit 1
fi

Make it start at system startup:

server:~#update-rc.d apache defaults 99 20

Step 4 - Install MySQL-server

Install ncurses library and get MySQL source code and unpack it:

server:~#apt-get install libncurses5-dev
server:~#wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51.tar.gz/from/http://mysql.tonnikala.org/
server:~#tar -xzvf mysql-5.0.51.tar.gz

Create a user and a group for the MySQL server:

server:~#groupadd mysql
server:~#useradd -g mysql -c "MySQL Server" -d /dev/null -s /usr/sbin/nologin mysql

Configure and compile MySQL:

server:~#cd mysql-5.0.51
server:~#./configure --prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--disable-maintainer-mode \
--with-mysqld-user=mysql \
--with-unix-socket-path=/tmp/mysql.sock \
--without-comment \
--without-debug \
--without-bench
server:~#make && make install

Compiling is going to take some time! Where did I put those Hustler magazines???

Install internal database:

server:~#/usr/local/mysql/bin/mysql_install_db --user=mysql

Change ownership of folders:

server:~#chown -R root:mysql /usr/local/mysql
server:~#chown -R mysql:mysql /usr/local/mysql/data

Copy MySQL's configuration file to /etc -directory and change ownership:

server:~#cp /usr/local/src/mysql-5.0.51/support-files/my-medium.cnf /etc/my.cnf
server:~#chown root.sys /etc/my.cnf
server:~#chmod 644 /etc/my.cnf

Copy the start-up script from support-files and test if MySQL starts up:

server:~#cp /usr/local/src/mysql-5.0.51/support-files/mysql.server /etc/init.d/mysql
server:~#chown root.root /etc/init.d/mysql
server:~#chmod 755 /etc/init.d/mysql
server:~#/etc/init.d/mysql start
server:~#update-rc.d mysql defaults 99 20

Change root password:

server:~#cd /usr/local/mysql/bin
server:/usr/local/mysql/bin#./mysqladmin -u root password "new-password"
server:/usr/local/mysql/bin#./mysqladmin -u root -h "yourhostname" password "new-password"

Step 5 - Install PHP 5

Yep! Now comes the icky part! The hard part in here is to find all the necessary packages you'll need to install PHP. It'll depend on what parts of PHP you want to install. So it's handy to learn how to use Debian websites package search tool.

Here is the configuration options that I've used:

./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--enable-inline-optimization \
--enable-magic-quotes \
--with-openssl \
--with-ldap \
--with-ldap-sasl \
--enable-bcmath \
--enable-calendar \
--with-gdbm \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-iconv \
--enable-sockets \
--enable-wddx \
--enable-ftp \
--enable-xml \
--with-xsl \
--with-bz2 \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-xmlrpc \
--with-pspell \
--enable-sysvsem \
--enable-mbstring \
--with-curl \
--with-curlwrappers \
--with-gettext=/usr/bin \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-mcrypt \
--enable-pcntl

To make this kind-of options to compile I needed to install these packages:

server:~#apt-get install libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libgd-xpm-dev \
libpng12-0 libpng12-dev libc-client2002edebian libc-client-dev libpam0g libldap2 \
libldap2-dev libsasl2-dev libltdl3 libmcrypt4 libmcrypt-dev libmhash2 libaspell15 \
libtidy-0.99-0 libxml2 libxml2-dev libxslt1.1 libxslt1-dev libcurl3 libcurl3-dev \
libbz2-dev libpspell-dev libgdbm-dev

Get PHP source, unpack it and configure:

server:~#wget http://fi2.php.net/get/php-5.2.5.tar.bz2/from/this/mirror
server:~#tar -xjvf php-5.2.5.tar.bz2
server:~#cd php-5.2.5
server:~#./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--enable-inline-optimization \
--enable-magic-quotes \
--with-openssl \
--with-ldap \
--with-ldap-sasl \
--enable-bcmath \
--enable-calendar \
--with-gdbm \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-iconv \
--enable-sockets \
--enable-wddx \
--enable-ftp \
--enable-xml \
--with-xsl \
--with-bz2 \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-xmlrpc \
--with-pspell \
--enable-sysvsem \
--enable-mbstring \
--with-curl \
--with-curlwrappers \
--with-gettext=/usr/bin \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-mcrypt \
--enable-pcntl

If the configure didn't went through without warnings, install necessary packages and try again. Otherwise make and install it:

server:~#make && make install

Copy php.ini file to /usr/local/php/lib directory:

server:~#cp php.ini-dist /usr/local/php/lib/php.ini

Add the necessary lines to httpd.conf at the end of file and change the directory index value. (Re)start Apache:

(/usr/local/apache2/conf/httpd.conf)
....
DirectoryIndex index.php index.phtml index.html index.html.var
....
AddType application/x-httpd-php .php .phtml

Step 6 - Install APC cache

This is necessary to get your crappy code to run a little faster! Get source code for it and unpack it:

server:~#cd /usr/local/src
server:~#wget http://pecl.php.net/get/APC-3.0.14.tgz
server:~#tar -xzvf APC-3.0.14.tgz
server:~#cd APC-3.0.14

Phpize, configure, compile and install it:

server:/usr/local/src/APC-3.0.14# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
server:/usr/local/src/APC-3.0.14#./configure --enable-apc-mmap \
--with-apxs=/usr/local/apache2/bin/apxs \
--with-php-config=/usr/local/php/bin/php-config
server:/usr/local/src/APC-3.0.14#make && make install

Edit your php.ini file. You need to tell php where to find these extensions:

....
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613"
....
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1

Restart Apache:

server:/usr/local/src/APC-3.0.14#../../apache2/bin/apachectl restart