Skip to content


Setting Up LAMP

Presented by Chad Kersey on September 3, 2008

Table of Contents

1. Before you Begin

Before you begin, you need the following:

  • Linux distro (Arch Linux was used in the presentation)
  • Installed packages for Apache, MySQL, and mod_php, perl, or
    mod_python
  • The ability to accept connections initiated on port 80.
    • Fedora has it blocked in iptables.

2. Configuring Apache

  • Know what you’re doing before setting up a production
    server.
    It’s very easy to set up something that is
    insecure.
  • See
    http://httpd.apache.org/docs/2.2/configuring.html
    , the
    official httpd documentation for help with configuration. It
    includes a detailed list of directives.
  • Find your httpd.conf. Arch, for instance, puts it in
    /etc/httpd/conf/httpd.conf
  • The Listen directive can be used to set a nonstandard
    port, or to only listen to requests on a particular IP address.
  • Include allows other .conf files to be
    imported, usually for module configuration.
  • LoadModule [mod_name] [mod_path] includes a module,
    like mod_php, mod_python, etc.

    • mod_userdir allows per-user web space
      at /~username/.
  • Directory allows configuring per-directory behavior,
    such as setting custom handlers (like using a specially-compiled
    php-cgi).

3. Compiling Extra Functionality into PHP

  • Start by getting the PHP source from
    http://www.php.net
  • Unpack the tarball and cd to the directoy it contains.
    From there, you can run ./configure --help | less to get
    a list of compile options.

    • Generally, you want to recompile PHP because it
      needs an obscure --with-X that
      your distro didn’t ship with, or you need a
      different version. Don’t forget
      --with-mysql if you plan to be using a
      MySQL database.
  • Run make. The Apache module is in
    sapi/apache/. The cgi version is in sapi/cgi/.

4. Running PHP as CGI (Only When Necessary)

This should only ever be done on a server on which you can’t install
your own mod_php. Since a new process must be spawned for every request,
php-cgi is very slow, especially under load.

  • Copy sapi/cgi/php-cgi to your cgi-bin directory.
  • Add the following to the .htaccess file in the
    directory you want to use the custom PHP,

    AddHandler phpFive .php

    Action phpFive [web path to php-cgi]

    replacing [web path to php-cgi] with the path on your
    server to where the php-cgi executable is located.

5. The .htaccess File

  • Acts on its directory and all subdirectories.
  • AddHandler mentioned in previous section.
  • To set a custom error document,
    ErrorDocument 404 [file], where [file] is the
    HTTP path (absolute or relative) to your error doc.

6. ModPython

No one is this excited over
PHP or Perl.

  • Start by installing your distro’s mod_python package.
  • If it wasn’t done for you by the installer, you may have to add
    LoadModule python_module /usr/lib/apache/mod_python.so
    to your httpd.conf. Note that this line may vary based
    on where mod_python is installed.
  • There is a simple example application using mod_python at

    http://www.modpython.org/examples/
    .

    • Examine its .htaccess to see how
      mod_python applications specify a handler.
  • 7. Adding Users and Databases to MySQL

    • Example- creating a database (new_db.sql):


      CREATE DATABASE lamp_test;

      USE lamp_test;

      CREATE TABLE birds (

      name VARCHAR(80),

      color VARCHAR(20),

      birthday DATE,

      wingspan INT

      );

    • Allowing non-root user to access this database:
      GRANT ALL ON lamp_test.* TO "lamp" IDENTIFIED BY
      "password";
    • There are many other permissions that can be tinkered with– all
      of which are in the “user” table– to take a look at what users
      exist and a few of their permissions on a few databases:


      USE mysql;

      SELECT host, user FROM user;

      SELECT

      host, user, select_priv, insert_priv, delete_priv

      FROM db WHERE db="lamp_test";

      SHOW FIELDS FROM db;

      Altering the fields of this table will change configuration.

    • http://dev.mysql.com/doc/refman/5.0/en/


      for the documentation.

    8. Installing and Using a Simple LAMP Application, PhpMyAdmin

    • Go to

      http://www.phpmyadmin.net


      and download phpmyadmin tarball into an htdoc subdirectory.

    • Point browser to that directory to see databases through Web
      interface. You will be brought to a configuration page.
    • Use the user you just created to access your new database.

    Posted in Articles.