La version Française est disponible ici: Installer son propre serveur Firefox sync avec PHP-FPM et Nginx
Introduction
Mozilla foundation offers synchronisation facilities, so that you can get back you browser environment when you work on another desktop. If you can just use Mozilla's storage infrastructure, you also have the choice to build your own.
The most paranoid of us will see the opportunity to get rid of Mozilla foundation for that purpose and ensure that Mozilla won't ever have the opportunity to get into their privacy. Personnaly, I don't believe that could happen: this is not the way Mozilla wants to spread the web and all informations you send to them are encrypted.
But deploying and maintaining an IT infrastructure to support Sync facilities cost money, a lot of... Installing your own Sync server makes Mozilla save some. Not a lot of course, but if millions of Firefox users install their own Sync server, Mozilla could save a lot of money.
Finally, as I operate my own web server, my own mail server, my own jabber server, and so on..., and since I like discovering new things, I decided to install my own Sync server. A matter of independance :)
Préparation
Here we are. So, I want to setup my own Firefox Sync server onto my Nginx and PHP-FPM stack.
Base setup is described here:
- Nginx: automatic vhosts configuration with subdomains, SSL and authentication support - second version
- PHP-FPM, application server made by PHP
Based on the configuration describe above, we have to setup an "application pool". That means that Firefox Sync server will be available for different domains and, of course, for many users.
Lets create directories tree:
Once done, we can configure PHP-FPM:
Yes, you read it, Firefox Sync minimal server can run in chroot. Happy :)
Firefox Sync minimal server needs SQlite support in PHP. Lets install it:
Here we are with PHP. It's now time to configure NGinx. README file suggest to use an Alias, with Apache. Since we use NGinx, we can't do this way. In fact, It's just about making sure that every request will be rewritted to use index.php with PATH_INFO variable setted. Here's what you can do with NGinx:
Beware with fastcgi_split_path_info directive. In official NGinx documentation, used regex is ^(.+\.php)(.*)$. Unfortunatly, Firefox Sync client performs a request like /1.0/user/username/info/collections?v=1.6.2. With regex from documentation, the query string ?v=1.6.2 is included in PATH_INFO declaration, which makes first connection failed. Even if further synchronisations will complete, you won't be able, as an example, to see tabs from other computers. Bad, isn't it ? :-/
This regex: ^(.+\.php)([^?]*).*$; solves the problem.
Now, you juste have to include this configuration file into the vhost one, like:
Firefox Sync minimal server installation
Now, you just have to install PHP code. Nothing difficult here:
Last command is important since SQlite DB will be written is root directory. Therefore, the user fsync needs write grants.
Database initialisation
DB creation will be made upon first connection. Just use your favorite brower (who say Chrome O_o ?) and point it to http://fsync.domain.tld/1.0/blah/info/collection using login blah and password garbage. Authentication will fail but DB should be now created.
Last step, populate you DB with users:
Simple, efficient.
Now you can configure you Sync account on you browser. Don't forget to use Custom Sync server to point you own one. It seems that Modification of an existing account is not enough, so I suggest you to delete it and create a completely new one.
Have fun !
Sources and references
Firefox sync
- Firefox Sync
- http://mozillalabs.com/sync/
- https://wiki.mozilla.org/Labs/Weave/Sync/1.0/API
- Minimal server
- http://tobyelliott.wordpress.com/2009/09/11/weave-minimal-server/
- http://rabenau.org/blog/posts/creating-your-own-firefox-sync-server
NGinx
- fastcgi_split_path_info
- http://nginx-maillist.blogspot.com/2011/01/re-fastcgisplitpathinfo-capture-group_20.html
- http://forum.nginx.org/read.php?2,168078,168097#msg-168097
