Tag Archives: primer

Installing MySQL, Apache, PHP & mod_perl on Debian from source

Introduction

I am writing this article because I believe it may be useful to people other than just myself. I am new to Linux. However, the command-line environment is not unfamiliar to me. I have been avidly using FreeBSD since 1996 (2.1.5) and I am usually found with my head in a Cisco or Juniper terminal most of the day. Even with this experience, I found installing installing MySQL, Apache, PHP and mod_perl on Debian to be laborious and tedious. You see, on a FreeBSD server, you can nearly install Apache right out of the box. Install the perl and libxml2 packages and you’re ready to go. For whatever reason, the people driving Debian’s development have decided that you either need to install everything using apt-get (a package manager similar to FreeBSD’s pkg_add or Redhat’s rpm) which is a horrifically terrible idea in a production environment, or jump though a plethora of hoops to install from source. I mean, Debian doesn’t even include gcc in the base install. Huh?

One thing FreeBSD does not do well, yet, is virtualization. Today, I needed a virtual box and my choices were between six different flavors of Linux and a few flavors of Windows. Windows is completely out of the question, so I was left to decide which Linux distribution I wanted to meander through. I recently worked for a company that used Debian (5.0 Lenny) as well as FreeBSD. I made a calculated decision that they, FreeBSD lovers, chose Debian because it closely resembled FreeBSD. I have still not decided whether or not my calculations were correct or not. Either way, I am armed with my good friend Google, who seldom lets me down when I encounter Linux issues. It would seem that someone has already been there, done that, fixed it and shared it. This is my attempt to give back.

Audience

Anyone looking to install MySQL 5.1, Apache 2.2, PHP 5.3 and mod_perl 2.0 on a Debian install.

Prerequisites

You will obviously need a box running Debian. I happen to be running Debian 6.0 Squeeze with the Linux 2.6 kernel.

Linux server 2.6.32-5-xen-amd64 #1 SMP Tue Mar 8 00:01:30 UTC 2011 x86_64 GNU/Linux

You will also need to download the source tarballs for MySQL, Apache, PHP and mod_perl

http://www.mysql.com/downloads/mysql/5.1.html
http://httpd.apache.org/download.cgi
http://www.php.net/downloads.php
http://perl.apache.org/download/index.html

Assumptions

  • You have a fresh Debian install
  • You have root privileges
  • You’ve downloaded all your sources to ‘/usr/local/src’
  • You’re installing MySQL in ‘/usr/local/mysql’
  • You’re installing Apache in ‘/usr/local/httpd’
  • You’ve created a user named ‘mysql’

Dependencies

During my installation, I tripped over several missing updates and libraries. In order for you to avoid encountering the same issues, please install the following updates and required libraries:

# apt-get update && apt-get upgrade
# apt-get install build-essential
# apt-get install libncurses5-dev
# apt-get install libxml2-dev
# apt-get install zlib1g-dev
# apt-get install libssl-dev
# apt-get install libgdbm3
# ln -s /usr/lib/libgdbm.so.3 /usr/local/lib/libgdbm.so
# ln -s /usr/lib/libperl.so.5.10 /usr/local/lib/libperl.so

The nitty gritty

Unpack the tarballs

# cd /usr/local/src
# tar xvfz mysql-5.1.60.tar.gz
# tar xvfz httpd-2.2.21.tar.gz
# tar xvfz php-5.3.8.tar.gz
# tar xvfz mod_perl-2.0-current.tar.gz

Configure, make and install MySQL

# cd /usr/local/src/mysql-5.1.60
# ./configure ––prefix=/usr/local/mysql ––with-plugins=innobase
# make
# make install
# ./scripts/mysql_install_db
# chown -R mysql:mysql /usr/local/mysql/var
# /usr/local/mysql/bin/mysqld_safe ––bind-address=127.0.0.1 &
# /usr/local/mysql/bin/mysqladmin -u root password 'your-new-password-here'

Configure, make and install Apache

# cd /usr/local/src/httpd-2.2.21
# ./configure ––prefix=/usr/local/httpd ––enable-modules=all ––enable-mods-shared=all ––enable-so ––enable-ssl
# make
# make install

Configure, make and install PHP

# cd /usr/local/src/php-5.3.8
# ./configure ––with-mysql=/usr/local/mysql ––with-apxs2=/usr/local/httpd/bin/apxs
# make
# make install
# cp php.ini-production /usr/local/lib/php.ini

Add the following lines to your httpd.conf file

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Insert them right after the following line:

AddType application/x-gzip .gz .tgz

Configure, make and install mod_perl

# cd /usr/local/src/mod_perl-2.0.5
# perl Makefile.PL MP_APXS=/usr/local/httpd/bin/apxs
# make
# make install

Add LoadModule config to your httpd.conf

LoadModule perl_module modules/mod_perl.so

Add that line where all the other LoadModule declarations are located.

And to finish it off…

Don’t forget your start-up scripts!

Conclusion

Once all the speed bumps are removed, installing from source is a piece of cake and doesn’t take long at all. Obviously, this is a very straight forward install and most of the time you’ll want to add several configuration options, especially to PHP.

I hope that you found this useful.