LAMP From Source (Debian)

Created on: 05.01.2011 3:57 PM
Edited on: 03.12.2012 5:42 PM

After years of using older/outdated version of the LAMP setup (Apache, MySQL, PHP running on Linux), I decided that it was time to upgrade and get everything working with the new versions.

While I am a fan (sometimes) of package management, in the instances where you need more flexibility, compiling from source is the way to go. Unfortunately, after digging around on the web, it was hard to find a comprehensive up-to-date guide for doing so. In this guide, I am still using package management for installing things like libraries and compilers but for the main applications themselves, we'll compile them from the source code.

We'll still use some package management for some things like libraries but we'll get the main components compiled and working together from source.

This HOWTO was written using the following versions:

  • MySQL 5.5.14 (also works with 5.5.21)

  • Apache 2.2.19 (also works with 2.2.21)

  • PHP 5.3.6 (also works with 5.3.10)


  • These instructions for compiling LAMP on a Debian (lenny) system.

    Before We Start / Disclaimer


    Everyone will have a different setup in mind, so you should be aware that unless you want to copy my installation preferences verbatim, you'll probably need to change a few things such as paths and whatnot. You may also need to tweak the configuration options if you need to add or remove components.

    If there winds up being enough feedback for a certain option or method, I can always update this page with alternative instructions.

    It is assumed that you have already downloaded the necessary files from their respective websites and placed them into some kind of temp directory. Additionally, you should either be root or using sudo where appropriate.

    Lastly, because I feel I have to, I'm not making any guarantee that this guide will work for you, solve all of your problems, and not completely break your server. You should have a good idea about what you're doing before working through this guide.

    Debian (lenny)



    MySQL


    The first thing to note is that newer versions of MySQL have done away with using GNU configure/make. Installation now requires cmake, among other dependencies. (Most/all should be available via package repositories.)

    Prerequisites

  • CMAKE

  • apt-get install cmake


  • BISON

  • apt-get install bison


  • LIBNCURSES (libncurses5)

  • apt-get install libcurses5


  • LIBAIO

  • apt-get install libaio1

    apt-get install libaio-dev


    Configure / Install

  • Unpack the MySQL release

  • tar xzfv mysql-5.5.14.tar.gz


  • cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DCMAKE_INSTALL_PREFIX=/local/mnt/mysql -DINSTALL_LAYOUT=STANDALONE -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF -DENABLED_PROFILING=ON -DMYSQL_DATADIR=/local/mnt/mysql/var/


  • make / make install


  • Post-Install

  • cd /local/mnt/mysql


  • Note: The install seems to ignore the DATADIR directive, at least for this run-through. Instead of creating "var", it auto-creates a "data" directory instead. (Could just be the default.)

  • rm -rf $MYSQL/data

  • mkdir $MYSQL/var

  • chown mysql:mysql $MYSQL/var

  • ./scripts/mysql_install_db --user=mysql --datadir=/local/mnt/mysql/var --basedir=/local/mnt/mysql


  • cp ./support-files/mysql.server /etc/init.d/mysql

  • chmod +x /etc/init.d/mysql


  • Starting / Configuring

  • /etc/init.d/mysql start


  • Note: You will need to do some additional configuration (not listed here) to get it to auto-start on reboot.

  • ./bin/mysqladmin -u root password new-password


  • Additional Security:

  • Log in to mysql from command line:

    ./bin/mysql -p

    drop database test;
    use mysql;
    delete from db;
    delete from user where not (host="localhost" and user="root");
    flush privileges;


    MySQL should be all set now.

    Apache (httpd)


    Compared to dealing with the new version of MySQL, getting Apache compiled and installed is relatively painless.

    Note: This does not cover setting up Apache to use SSL as I did not have a need for it during this run-through. I can always put up a separate HOWTO for that if needed later.

    Configure / Install

  • Unpack the httpd release

  • tar xzfv httpd-2.2.19.tar.gz


  • ./configure --prefix=/local/mnt/httpd --enable-so --enable-cgi --enable-info --enable-rewrite --enable-speling --enable-usertrack --enable-deflate --enable-mime-magic


  • make / make install


  • Post-Install

  • Edit $HTTPD/conf/httpd.conf to your liking:

  • Default run-as user is daemon. I changed this to nobody.

    Update ServerAdmin and ServerName as needed.

    Update DirectoryIndex to include index.php (and index.htm)


    Note: Near the bottom of the config file, there are options to include various "extra" config files. This is not needed for default operation but you'll likely want to uncomment "vhosts" among others to enable that functionality.

    Starting / Configuring

  • $HTTPD/bin/apachectl start



  • PHP


    Before starting with the compilation of PHP, I include a number of additional components/libraries for my desired install. These may or may not already be included on a standard system.

    Prerequisites

    Note: As with the MySQL install above, the below components were installed using Debian package management. You will need to adjust these according to your OS.

  • FREETYPE (libfreetype6)

  • apt-get install libfreetype6


  • LIBJPEG (libjpeg62)

  • apt-get install libjpeg62


  • LIBTIFF (libtiff4)

  • apt-get install libtiff4


  • LIBPNG (libpng3)

  • apt-get install libpng3


  • LIBXML (libxml2)

  • apt-get install libxml2


    Configure / Install

  • Unpack the PHP release

  • tar xzfv php-5.3.6.tar.gz


  • ./configure --with-apxs2=/local/mnt/httpd/bin/apxs --with-mysql=/local/mnt/mysql --with-mysqli=/local/mnt/mysql/bin/mysql_config --with-pdo-mysql=/local/mnt/mysql --enable-sockets --with-zlib --with-regex=system --with-gettext --with-gd --enable-xml --enable-wddx=shared --enable-mbstring --enable-magic-quotes --enable-inline-optimization --enable-ftp --enable-soap --disable-debug --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir


  • make / make install


  • Post-Install

    While the PHP install will update httpd.conf to auto-load the new module, you generally have to add handlers for .php files manually.

  • Edit $HTTPD/conf/httpd.conf and search for AddType. Paste the following:

  • AddType application/x-httpd-php .php

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


  • Restart Apache and you should be good to go.



  • Contact


  • I can be reached at: rp [at] rpiz.com