LAMP From Source (Fedora)

Created on: 05.01.2011 3:57 PM
Edited on: 03.12.2012 5:40 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 are for getting things running on a Fedora 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.

    Fedora (release 15)



    Compared to the Debian server above, my Fedora server was relatively bare bones with regard to installed components, so the steps below may include some packages you already have installed. This should be fine and when using yum, it'll simply tell you that the package is already installed and ignore it.

  • GCC

  • yum install gcc gcc-c++

    MySQL won't compile without the C++ extensions


  • ZLIB

  • yum install zlib zlib-devel


    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

  • yum install cmake


  • BISON

  • yum install bison


  • NCURSES

  • yum install ncurses ncurses-libs ncurses-devl

    Note: ncurses-devel is important, as my compilation filed with an obscure library error without it


  • LIBAIO

  • yum install libaio libaio-devel


    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 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/local/mnt/mysql/var/ -DCMAKE_INSTALL_PREFIX=/local/mnt/mysql -DCURSES_LIBRARY=/lib/libncurses.so.5 -DCURSES_INCLUDE_PATH=/usr/include -DHAVE_LIBAIO_H=/usr/include/ -DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF


  • For the Fedora install, I needed to explicitly include -DCURSES_LIBRARY and -DCURSES_INCLUDE_PATH.

  • 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 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

    For these library installs, I also included the [name]-devel package. You might not need it but it doesn't hurt anything.

  • FREETYPE

  • yum install freetype freetype-devel


  • LIBJPEG

  • yum install libjpeg-turbo libjpeg-turbo-devel


  • LIBTIFF

  • yum install libtiff libtiff-devel


  • LIBPNG

  • yum install libpng libpng-devel


  • LIBXML (libxml2)

  • yum install libxml2 libxml2-devel


    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