Sync Server

I recently set up my own sync server. It is one of the requirements for a projects I am currently working on. All of the information I needed was on two separate Mozilla wiki pages: sync setup and user setup.  After spending some time in the #sync IRC Channel. I finally got it working. In order to configure a server on Fedora you will need PHP with the mbstring extension, mysql, apache, mercurial, and captcha.

Setting up the sync server:

– Get the latest server from Mozilla. You can save this directory anywhere on the hard-drive.

 hg clone http://hg.mozilla.org/services/sync-server/

– Edit the Apache config file found under etc/httpd/conf/httpd.conf

Append these two lines:

Alias /1.0 <full path to the dir you just saved>/sync-server/1.0/index.php

– Copy 1.0/default_constants.php.dist to 1.0/default_constants.php

Open this file and change the following parameters:

 define('WEAVE_AUTH_ENGINE', 'mysql');
 define('WEAVE_MYSQL_AUTH_HOST', '<db host>');
 define('WEAVE_MYSQL_AUTH_DB', '<db name>');
 define('WEAVE_MYSQL_AUTH_USER', '<db username>');
 define('WEAVE_MYSQL_AUTH_PASS', '<db password>');

Note that you have to create the database and the above user. If you have never set up mysql this blog may help.

-Make a database name it the same as above
-Make a user with and give him privileges to the

– Create three tables: wbo and collections using the following script:

 CREATE TABLE `collections` (
 `userid` int(11) NOT NULL,
 `collectionid` smallint(6) NOT NULL,
 `name` varchar(32) NOT NULL,
 PRIMARY KEY  (`userid`,`collectionid`),
 KEY `nameindex` (`userid`,`name`)
 ) ENGINE=InnoDB;

CREATE TABLE `wbo` (
 `username` int(11) NOT NULL,
 `collection` smallint(6) NOT NULL default '0',
 `id` varbinary(64) NOT NULL default '',
 `parentid` varbinary(64) default NULL,
 `predecessorid` varbinary(64) default NULL,
 `sortindex` int(11) default NULL,
 `modified` bigint(20) default NULL,
 `payload` longtext,
 `payload_size` int(11) default NULL,
 `ttl` int(11) default '2100000000',
 PRIMARY KEY  (`username`,`collection`,`id`),
 KEY `parentindex` (`username`,`collection`,`parentid`),
 KEY `modified` (`username`,`collection`,`modified`),
 KEY `weightindex` (`username`,`collection`,`sortindex`),
 KEY `predecessorindex` (`username`,`collection`,`predecessorid`),
 KEY `size_index` (`username`,`payload_size`)
 ) ENGINE=InnoDB;

This table is used by the user server:
 CREATE TABLE `users` (
  id int(11) NOT NULL PRIMARY KEY auto_increment,
  username varbinary(32) NOT NULL,
  password_hash varbinary(128) default NULL,
  email varbinary(64) default NULL,
  status tinyint(4) default '1',
  alert text,
  reset varchar(32),
  reset_expiration datetime )
ENGINE=InnoDB;

insert into users (username, password_hash, status) values ('username', md5('password'), 1);

– Ensure that the following constants are listed in the 1.0/default_constants..php file:

 define('WEAVE_MYSQL_STORE_WRITE_HOST', WEAVE_MYSQL_STORE_READ_HOST);
 define('WEAVE_MYSQL_STORE_WRITE_DB', WEAVE_MYSQL_STORE_READ_DB);
 define('WEAVE_MYSQL_STORE_WRITE_USER', WEAVE_MYSQL_STORE_READ_USER);
 define('WEAVE_MYSQL_STORE_WRITE_PASS', WEAVE_MYSQL_STORE_READ_PASS);
 define('WEAVE_PAYLOAD_MAX_SIZE', '');

Setting up the user server:

– Get the latest server from Mozilla. You can save these anywhere on the hard-drive.

hg clone http://hg.mozilla.org/services/reg-server/

– Edit the Apache config file found under etc/httpd/conf/httpd.conf

Append these lines two lines:

Alias /user/1.0 <full path to services/reg-server directory>/reg-server/1.0/index.php
Alias /user/1 <full path to services/reg-server directory>/reg-server/1.0/index.php

– Copy 1.0/weave_user_constants.php.dist  of the new directory to 1.0/weave_user_constants.php

Open this file and change the following parameters:

define('WEAVE_AUTH_ENGINE', 'mysql');
define('WEAVE_MYSQL_AUTH_HOST', '<db host>');
define('WEAVE_MYSQL_AUTH_DB', '<db name>');
define('WEAVE_MYSQL_AUTH_USER', '<db username>');
define('WEAVE_MYSQL_AUTH_PASS', '<db password>');

– To set up captcha you will need to get yourself a public key and private key from http://recaptcha.net/

-Add an alias to the 1.0/weave_user_constants.php

Alias /misc/1.0/captcha_html /reg-server/1.0/captcha.php

Once you completed this setup you need to set-up your sync profile. To do this go to the Tools=>Sync menu in Firefox or download the Sync add-on.
You will meed to set up sync to use your own serve. This tutorial will guide you through setup however it uses the Mozilla server.

View all of my blogs

Advertisements

One thought on “Sync Server

  1. Thanks Anna this looks helpful but I am still confused about a few things and I thought you might be able to help

    1) I installed the full mozilla sync server (http://hg.mozilla.org/services/server-full) using instructions from http://docs.services.mozilla.com/howtos/run-sync.html and so the directories are a bit different.

    2) i am using apache2 and do not have a directory called “1.0” as listed in your directions Setting up the Server so I am wondering what that directory contains and if there is an equivalent in the “full server” install.

    Thanks so much.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s