KrnlPanic's Linux Notes and Tips

Working with linux since kernel version 2.0.30

LAMP – Linux Apache, MySQL, PHP Installation

Apache, MySQL, PHP Installation

Linux Apache MySQL PHP (LAMP) Guide
by Wicked187, ddortch@netscape.net
Created on November 20th, 1999
Last modified on 29 November 2001 by KrnlPanic, krnl@krnlpanic.com.

This tutorial will explain how to install the Apache webserver, first and foremost, but also includes the steps to installing mod_php, mod_perl and MySQL. Apache + MySQL + PHP. You probably already have Linux up if you have come this far, if not you can get help setting it up throughout this site

First of all, download the latest stable sources of Apache, MySQL, and PHP, you can find them at www.apache.org, www.mysql.com, and www.php.net, respectively.

I would move them into /usr/local/src for consistency, as well as making sure you get the tarball versions. Next, unpack them by typing:

tar -zxvf filename.tar.gz

  • MySQL Installation
  • (skip this if just building Apache)

    Now, we are going to setup MySQL first cd into the mysql directory, maybe /usr/local/src/mysql-3.22.27. Then configure it by typing:

    ./configure –prefix=/usr/local/mysql

    This will put it in it’s own directory, which I always put things in /usr/local as a standardization. Run the make command:

    make

    Run the make install command:

    make install

    Now it is installed. You need now to set it up. Add the MySQL Libraries to the ldconfig file:

    echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf

    Now have it cache all of the libraries:

    ldconfig -v | grep libmysqlclient

    You should now see something returned like:

    libmysqlclient.so.6 => libmysqlclient.so.6.0.0

    Now have MySQL start at boot time:

    echo “/usr/local/mysql/bin/safe_mysqld > /dev/null &” >> /etc/rc.d/rc.local

    Now you must make the initial databases the MySQL needs to run:

    ./scripts/mysql_install_db

    Now start up the service daemon for MySQL:

    /usr/local/mysql/bin/safe_mysqld > /dev/null &

    Now add it to the path:

    PATH=”$PATH:/usr/local/mysql/bin”

    Now you should test MySQL:

    mysqladmin version

    This should give you back all kinds of info on MySQL. Now create a password for the SuperUser:

    mysql -u root -p

    It will then prompt your for a password:

    Enter password:

    And MySQL should be setup.

  • Apache Setup
  • (configure so PHP and/or perl can built)
    Now the next part is making the new Apache/PHP setup. If you are currently using Apache and have stuff that you would like to keep, do a backup on your data (specifically httpd.conf or vhost.conf).

    cd /usr/local/src/apache_1.3.X

    Configure apache:

    ./configure –prefix=/usr/local/apache

  • PHP4 Config and Install
  • Now change into the PHP source directory:

    cd /usr/local/src/php-4.X.XX

    And run the configuration of php to support MySQL and Apache:

    ./configure –with-apache=../apache_1.3.X –with-mysql=/usr/local/mysql

    Now run the make command to compile php4:

    make

    Now run the make install command:

    make install

  • Mod_perl Installation and Configuration
  • cd /usr/local/src/mod_perl-1.XX

    perl Makefile.PL

    As you go through the mod_perl install, you may come across some missing dependencies. If you have CPAN installed on your system, you can install the failed dependencies using the CPAN shell. You will need the following in order to install mod_perl.

    CGI.pm
    LWP::UserAgent
    HTML::HeadParser

    To install them, you can enter the CPAN shell with the following command:

    perl -MCPAN -e shell

    Now use the install command in CPAN like this:

    install HTML::HeadParser
    If dependencies were not met on the first run of perl Makefile.PL, you will need to re-run it prior to moving on to the next step.

    Once you are satisfied with the configuration of mod_perl, go ahead and build it with:

    make

    And install it with:

    make install

    Installation of mod_perl is now complete.

    Back to Apache

    Now change back into the apache source directory:

    cd ../apache_1.3.X

    Now you have to reconfigure Apache, because we have added in the PHP Module. This will have it use the module you provided:

    ./configure –prefix=/usr/local/apache –activate-module=src/modules/php/libphp.a

    This will configure it. Now you must run the the make and make install commands:

    make

    make install

    There is a possibility that it will complain about not having an ANSII C compiler. If so, goto the FAQ on the www.php.net site. There are some common fixes there. If everything went well, you now have a few last minute setup processses to go through. Rename the http daemon:

    mv /usr/local/apache/bin/httpd-1.3.X /usr/local/apache/bin/httpd

    Now make a sybolic link and startup the http daemon:

    ln -s /usr/local/apache/bin/httpd /usr/sbin/httpd

    /usr/sbin/httpd

    Now that it is up, test and see the version information:

    httpd -v

    Now you have to add a couple of pieces of info to the apache configuration files. They are located iusr/local/apache/conf/

    vi httpd.conf

    Find the AddType section and uncomment the following lines:

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

    This will make apache understand that it needs to pass these extensioned file to the php engine. Now find the DirectoryIndex section and add some info for php. It should look like this:

    DirectoryIndex index.html index.phtml index.php index.phps

    That should do it. Now restart the Apache http daemon:

    killall -HUP httpd

    Apache should be up with support for php. You can now add the phpMyAdmin tool that is found at www.phpwizard.net or anyting else you would like.

    If you need help, let us know and we’ll be happy to do what we can. Hell, I might even build it for ya ;-)

    KrnlPanic

    One Comment on “LAMP – Linux Apache, MySQL, PHP Installation

    Leave a Reply