(ve):Install Cherokee LAMP on Ubuntu 9.10

  • This page was last modified on November 22, 2010, at 10:44.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents

Definition

LAMP stands for Linux, Apache, MySQL and PHP/Python/Perl systems.

In this case we are going to use Cherokee instead of Apache.

Requirements

  • Linux, Ubuntu 9.10.
  • Cherokee.
  • MySQL.
  • PHP5.

Installation

  1. Log in to your (ve) with root or sudo access:
    ssh root@example.com

    Windows users should use software like PuTTy.

  2. Make sure your server is up to date:
    # apt-get update
    # apt-get upgrade
    

Cherokee

  • Follow this guide. The process is pretty straightforward.

MySQL

  1. Install MySQL through repositories:
    # apt-get install mysql-server mysql-client
  2. During installation you'll be prompted for a password. Use a strong one and note it somewhere.
  3. Now the latest stable version of MySQL will be installed. If you want to check the version:
    mysql -V

    You'll get something like this:

    mysql Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (x86_64) using EditLine wrapper

That's it!

PHP 5

  1. Install PHP through repositories:
    # apt-get install php5-cgi php5-mysql (*)
    You can also install additional modules like php5-curl, php5-json, etc.. If you want a complete list of available php modules type:
    # aptitude search php5
  2. Check your PHP version:
    php-cgi -v

    You should see something like this:

    PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cgi-fcgi) (built: Jan  6 2010 22:50:54)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    
  3. Now, go to your cherokee-admin, click the Virtual Servers tab and create a new virtual server, or use the default one if you haven't set any before. For this example, we'll be using the default one.
    1. Click the Wizards button, select Languages and run the PHP Wizard. It'll create a new rule like this:

      Cherokee-LAMP-php-wizard-rule.png

      This rule will be applied to all the requested files that have the extension .php (Don't worry about url rewriting.).

    2. Click on the new rule, then on its Handler tab.

      The wizard has created a new information source for us:

      Cherokee-LAMP-php-wizard-source.png

    3. Click on it. We need to edit some values here. By default it will listen to localhost in a random port, usually higher than 45000. You can also use linux sockets; that's up to you.

      Cherokee-LAMP-php-source-information.png

      Note: If you are unable to launch this automatically with the Interpreter line, leave it blank.

  4. Now, create a simple phpinfo page in your virtual server's root directory:
    nano /var/www/info.php
    /var/www/info.php
    <?php
    phpinfo();
    ?>
    
  5. We're not quite done. http://yourdomain.com will give you a "503 Service Unavailable" message because PHP is not handling your request.

    So, now we will spawn a FastCGI handler. It's as easy as typing:

    spawn-fcgi -u www-data -f /usr/bin/php-cgi -a 127.0.0.1 -p 47990 -P /var/run/spawn-fcgi.pid

    • Change the port number 47990 to fit your needs.
    • This will launch a single process which will work until you stop/kill it, or your server reboots (from a crash, etc.).
  6. Now visit http://yourdomain.com in your browser. You'll see the PHP info page displaying nicely and with the FastCGI handler.
  7. To launch FastCGI automatically on startup, create the following init.d script:

    I called the file /etc/init.d/spawn-fcgi-php; the -php can help if you have multiple interpreters (php and python, php and perl, etc.).

    1. Create this file on your server:
      /etc/init.d/spawn-fcgi-php
      #! /bin/sh
      
      ### BEGIN INIT INFO
      # Provides:          spawn-fcgi-php
      # Required-Start:    $all
      # Required-Stop:     $all
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: starts FastCGI for PHP
      # Description:       starts FastCGI for PHP using start-stop-daemon
      ### END INIT INFO
      
      PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
      NAME=spawn-fcgi-php
      PID=/var/run/spawn-fcgi-php.pid
      DAEMON=/usr/bin/spawn-fcgi
      DAEMON_OPTS="-f /usr/bin/php-cgi -a 127.0.0.1 -p 47990 -u www-data -P $PID"
      
      test -x $DAEMON || exit 0
      
      set -e
      
      case "$1" in
      start)
      echo "Starting $NAME: "
      start-stop-daemon --start --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS
      echo "done."
      ;;
      stop)
      echo "Stopping $NAME: "
      start-stop-daemon --stop  --pidfile $PID --retry 5
      rm -f $PID
      echo "done."
      ;;
      restart)
      echo "Stopping $NAME: "
      start-stop-daemon --stop  --pidfile $PID --retry 5
      rm -f $PID
      echo "done..."
      sleep 1
      echo "Starting $NAME: "
      start-stop-daemon --start --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS
      echo "done."
      ;;
      *)
      echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
      exit 1
      ;;
      esac
      
      exit 0
      

      • Copy/paste this text into a plain text file on your local machine, then upload the file via FTP to /var/www, then move it to /etc/init.d/spawn-fcgi-php. Don't forget to add execution permissions to it:
      chmod +x /etc/init.d/spawn-fcgi-php
    2. Be sure to modify line 17, DAEMON_OPTS, with your own address ( -a ) and port ( -p ). The address will be localhost by default. The port is up you.
    3. Add this init.d script to the boot sequence:
      # update-rc.d spawn-fcgi-php defaults

      Restart the server or launch the spawner to start working with PHP.

FastCGI with sockets

  • Go to your source information. Change the Connection to your socket path, for example, /tmp/cherokee-source1.sock.
  • Now, edit line 17 of your /etc/init.d/spawn-fcgi-php file from:
/etc/init.d/spawn-fcgi-php
DAEMON_OPTS="-f /usr/bin/php-cgi -a 127.0.0.1 -p 47990 -u www-data -P $PID"

To:

/etc/init.d/spawn-fcgi-php
DAEMON_OPTS="-f /usr/bin/php-cgi -s /path/to/your/socket.socket -u www-data -P $PID"