Indefero

InstallationOnMacOSXTips


Table of Contents

Tips on how to install on Mac OSX Snow Leopard

Introduction

Here are some tips on how I installed indefero on OSX Snow Leopard. It might not be the perfect setup as I am not an expert but it worked for me. I used Macports and tried to keep the default settings as much as possible. This is not a step-by-step guide, I just collected some hints on how to deal with more complex things than installing Macports and stuff.

Let's start.

Macports

I now use Porticus to manage my ports. I installed PHP 5.3 and MySQL from Macports. You can install the php5_pcntl port if you don't want to have to deal with Python later on.

Install indefero

Just follow the documentation that comes with indefero. Then there are two problems you will have to deal with, which might be fixed in later releases of indefero.

Path to pear

Indefero thinks pear is installed in /usr/share/php but on osx it is in /usr/lib/php. This causes a problem with PHP 5.3 and other PHP releases which are more careful about static calls. When you try to run the migrate.php script, you will probably get an error from Pluf error handler telling you that PEAR::raiseError cannot be called statically. This is because Pluf, the framework behind indefero has its own error handler, it intercepts the error and stop the script. It is kind of a chicken and egg problem.

To fix this, I hard changed the path to pear in Pluf.php error handling function.

0 === strpos($file, Pluf::f('pear_path','/usr/lib/php/'))

Deprecated errors with PHP 5.3

Those might also have been fixed in a more recent release of indefero. To get rid of these, in Pluf.php I changed the error handler declaration to :

set_error_handler('PlufErrorHandler', E_ALL & ~E_DEPRECATED); 

Create a git user

To create the git user, the one that will deal with your repositories, I wrote a samll shell script. There is no adduser command in Leopard, so that's one way to go.

#!/bin/bash

# We loop to find a numeric value which is not a users uniqueid or a groups
# primary group id starting at 501
typeset -i uid=501
while [[ "$( dscl . search Users UniqueID $uid && 
             dscl . search Groups PrimaryGroupID $uid )" ]] ; do
    let ++uid
done

dscl . create /Users/git
dscl . create /Users/git UniqueID $uid
dscl . create /Users/git PrimaryGroupID $uid
dscl . create /Users/git NFSHomeDirectory /Users/git
dscl . create /Users/git Password '*'
dscl . create /Users/git UserShell /bin/sh
dscl . create /Users/git RealName 'Git Admin User'

dscl . create /Groups/git
dscl . create /Groups/git PrimaryGroupID $uid
dscl . create /Groups/git RealName 'Git Admin Group'
dscl . append /Groups/_www GroupMembership git

if [[ ! -d /Users/git ]] ; then
    mkdir /Users/git
    mkdir /Users/git/.ssh
fi
touch /Users/git/.ssh/authorized_keys
chmod 0700 /Users/git/.ssh
chmod 0600 /Users/git/.ssh/authorized_keys
chown -R git:git /Users/git

Then your system will have a git user and _www will be a member of the git group.

Configuration of indefero

As stated previously, I am using Git, which was also installed by Macports. In consequence, here is my indefero configuration idf.php file.

<?php
$cfg = array();
$cfg['debug'] = true;
$cfg['debug_scm'] = true; 
$cfg['git_remote_url'] = 'git://demo.mamasam.com/%s.git';
$cfg['git_write_remote_url'] = 'git@demo.mamasam.com:%s.git';
$cfg['admins'] = array(array('Admin', 'bertrand@mamasam.com'));
$cfg['send_emails'] = true;
$cfg['mail_backend'] = 'smtp';
$cfg['mail_auth'] = true;
$cfg['mail_host'] = 'ssl://smtp.gmail.com';
$cfg['mail_port'] = 465;
$cfg['mail_username'] = 'demo@gmail.com';
$cfg['mail_password'] = 'password';
$cfg['idf_base'] = '';
$cfg['url_base'] = 'http://demo.mamasam.com';
$cfg['url_media'] = 'http://demo.mamasam.com/media';
$cfg['url_upload'] = 'http://demo.mamasam.com/media/upload';
$cfg['upload_path'] = '/web/demo.mamasam.com/indefero/www/media/upload';
$cfg['upload_issue_path'] = '/web/demo.mamasam.com/indefero/attachments';
$cfg['secret_key'] = 'FBRFbJfm5ZZSO9S5YOTXcVwR0JLRtFBRFbJfm5ZZ'; 

$cfg['from_email'] = 'demo@mamasam.com';
$cfg['bounce_email'] = 'demo@mamasam.com';

$cfg['tmp_folder'] = '/tmp';

$cfg['db_login'] = 'root';
$cfg['db_password'] = 'password';
$cfg['db_server'] = ':/opt/local/var/run/mysql5/mysqld.sock';
$cfg['db_version'] = '5.1';
$cfg['db_table_prefix'] = ''; 
$cfg['db_engine'] = 'MySQL';
$cfg['db_database'] = 'indefero';
$cfg['time_zone'] = 'Europe/Paris';
$cfg['pear_path'] = '/usr/lib/php';
$cfg['login_success_url'] = $cfg['url_base'].$cfg['idf_base'];
$cfg['after_logout_page'] = $cfg['url_base'].$cfg['idf_base'];
$cfg['cache_engine'] = 'Pluf_Cache_File';
$cfg['cache_timeout'] = 300;
$cfg['cache_file_folder'] = $cfg['tmp_folder'].'/cache';
$cfg['template_folders'] = array(dirname(__FILE__).'/../templates');

$cfg['installed_apps'] = array('Pluf', 'IDF');
$cfg['pluf_use_rowpermission'] = true;
$cfg['middleware_classes'] = array(
         'Pluf_Middleware_Csrf',
         'Pluf_Middleware_Session',
         'IDF_Middleware',
         'Pluf_Middleware_Translation',
         );
$cfg['template_context_processors'] = array('IDF_Middleware_ContextPreProcessor');
$cfg['idf_views'] = dirname(__FILE__).'/urls.php';
$cfg['languages'] = array('en', 'fr'); 

$cfg['allowed_scm'] = array('git' => 'IDF_Scm_Git');
$cfg['idf_mimetypes_db'] = '/opt/local/apache2/conf/mime.types';

$cfg['idf_exec_cmd_prefix'] = '/usr/bin/env -i ';
$cfg['git_path'] = '/opt/local/bin/git'; 

$cfg['git_repositories'] = '/Users/git/repositories/%s.git';
$cfg['git_remote_url'] = 'git://demo.mamasam.com/%s.git';
$cfg['idf_plugin_syncgit_path_gitserve'] = '/web/demo.mamasam.com/indefero/scripts/gitserve.py';
$cfg['idf_plugin_syncgit_path_authorized_keys'] = '/Users/git/.ssh/authorized_keys';
$cfg['idf_plugin_syncgit_sync_file'] = '/tmp/SYNC-GIT';
$cfg['idf_plugin_syncgit_remove_orphans'] = false;
$cfg['idf_plugin_syncgit_git_home_dir'] = '/Users/git';
$cfg['idf_plugin_syncgit_base_repositories'] = '/Users/git/repositories';

return $cfg;

So what's worth noting :

  • I use MySQL sockets to connect to the database, don't forget the colon in front of the socket path.
  • I use the Apache mime file which is installed by default by Macports.
  • The path to the Python gitserve.py script will probably be useless in a future version of indefero.
  • I called my database 'indefero'.
  • I use the Gmail smtp to send notification emails.

Other parameters are more or less the defaults, except paths which depend on your installation.

Creating the admin user

Once you have used the migrate.php script to install the database, you can proceed to create the admin account for your indefero application.

Note on include_path : I had to make sure everywhere that PHP could find Pluf.php. It seems that sometimes, the path to Pluf framework is not set, so I just added when necessary :

set_include_path(get_include_path().PATH_SEPARATOR.'/web/demo.mamasam.com/pluf/src');

In other cases, you might have to uncomment the line that disable the Pluf include_path. I have no idea why they are commented in some sources.

Cron job configuration

You need to run a cron job every now and then to synchronize the SSH keys.

Note: Apple recommends using launchd instead of crontab, or at least done its best to discourage us from using it.

launchd

If not exists, create the LaunchDaemons dir:

$ sudo mkdir /Library/LaunchDaemons

Creates a plist file and load it with launchd:

$ sudo mate /Library/LaunchDaemons/my.indefero.cron.plist
$ sudo launchctl load /Library/LaunchDaemons/my.indefero.cron.plist

Here is my plist for running the gitcron script every 5 minutes (300 seconds):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>my.indefero.cron</string>
    <key>UserName</key>
    <string>git</string>
    <key>ProgramArguments</key>
    <array>
        <string>php</string>
        <string>/Library/WebServer/share/indefero/scripts/gitcron.php</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
    <key>StandardErrorPath</key>
    <string>/tmp/my.indefero.cron.log</string>
</dict>
</plist>

Note: StartInterval is the number of seconds between each launch command. It can not be less than 60, because launchd scans its list of launch every 60 seconds. To manage the schedule for dates, use StartCalendarInterval instead of StartInterval (see launchd.plist man).

crontab

OK, the easiest way to install the crontab for me was :

$ sudo crontab -u git -e

And then this will run the gitcron script every 5 minutes :

*/5 * * * * /opt/local/bin/php /web/demo.mamasam.com/indefero/scripts/gitcron.php

If you want a shorter cron schedule, refer to cron documentation to change the period.

Important: In scripts/gitcron.php and gitserve.php make sure your include_path are set correctly. In my version, path to Pluf were commented which lead to Pluf.php not found errors.

Install the git daemon

To install the git daemon, I used Lingon in expert mode, but you could as well do it from the command line. Anyway, here is my Launchd configuration :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>git</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/local/bin/git</string>
        <string>daemon</string>
        <string>--user=git</string>
        <string>--group=git</string>
        <string>--verbose</string>
        <string>--reuseaddr</string>
        <string>--base-path=/Users/git/repositories/</string>
        <string>/Users/git/repositories/</string>
    </array>
</dict>
</plist>

This configuration is saved in /Library/LaunchDaemons/git.plist

When using gitserve.py

At the moment, indefero uses Python to deal with git push requests. To have the Python script work, you will probably have to hard code your path to the git command. Another thing that will be fixed when indefero will use pcntl_exec() from PHP instead of Python.

So in gitserve.py, change this line :

os.execvp('/opt/local/bin/git', ['/opt/local/bin/git', 'shell', '-c', output.strip()])

Serve.php

It seems that my git installation from Macports doesn't come with all the aliases like git-receive-pack, git-daemon, etc. Instead I have to write git receive-pack. So to make sure it is not a problem, I changed the last line of function serve() in Serve.php with :

if ($verb == 'git-receive-pack') {
  $verb = 'git receive-pack';
} elseif ($verb == 'git-upload-pack') {
  $verb = 'git upload-pack';
}
$new_cmd = sprintf("%s '%s'", $verb, $fullpath);
return $new_cmd;

Now, I have a nice indefero setup. I hope these hints will help you deal with most problems you encounter when installing on OSX. Good luck !

Created: 11 years 3 months ago
by Natalie Adams

Page rendered in 0.04592s using 24 queries.