Why setup a private mirror?
Only customers of the “enterprise” offer have the required access to setup a private mirror with rsync (which is what’s described on this page).
They typically have very large setup with several thousands of servers needing access to the PHP LTS repositories and it makes sense for them to have their own local copy of the repository, both to save bandwidth and to limit their dependency to external infrastructure that is not under their control.
Step by step explanation to setup a private mirror
The explanations are tailored for Debian systems (version 10 or newer). Adapt them accordingly if you use some other operating system. You must have the rsync username and password given to you by Freexian. The rsync access is provided only to customers with a Pro or Business subscription.
Create a dedicated user
We recommend that you run the mirror under a dedicated user. It makes it easier to setup SSH push mirroring later on and is part of good security practice to isolate external interactions as much as possible.
For the purpose of this explanation, we will call the dedicated user mirror.
Let’s create the user with adduser and fill in the various fields:
$ sudo adduser --disabled-password mirror
Adding user 'mirror' ...
[...]
Is the information correct? [Y/n]
Installing the mirroring tool
We use the ftpsync tool developed by Debian to mirror APT Debian
repositories. You can install it with apt install ftpsync or install
it manually from this
archive
by following the instructions in the provided README.
Configuring the mirroring tool
In the dedicated user’s home directory, you will create the
~/.config/ftpsync/ftpsync-php.freexian.com.conf configuration file as
well as a log directory. We will configure the mirror so that it stores
the files in /srv/mirrors/php.freexian.com.
Note: you must change the value assigned to RSYNC_USER and RSYNC_PASSWORD to match the credentials that you have been given by Freexian.
# sudo mkdir -p /srv/mirrors/php.freexian.com
$ sudo chown mirror:mirror /srv/mirrors/php.freexian.com
$ sudo su - mirror
mirror$ mkdir -p .config/ftpsync log
mirror$ export RSYNC_USER=megacorp
mirror$ export RSYNC_PASSWORD=sekret1
mirror$ cat >.config/ftpsync/ftpsync-php.freexian.com.conf <<END
TO="/srv/mirrors/php.freexian.com/"
BASEDIR="$HOME"
LOGDIR="$HOME/log"
RSYNC_HOST="php.freexian.com"
RSYNC_PATH="php"
RSYNC_USER="$RSYNC_USER"
RSYNC_PASSWORD="$RSYNC_PASSWORD"
END
mirror$
Running the mirror regularly
Running the mirror with cron
To keep your mirror up-to-date, you have to run ftpsync sync:archive:php.freexian.com while being the mirror user.
We recommend that you run it from cron four times a day with a cron entry like this one (assuming that the system time is in UTC):
mirror$ (crontab -l; echo "17 2-23/6 * * * ftpsync sync:archive:php.freexian.com") | crontab -
The freexian package repository is updated at 0h, 6h, 12h, 18h (all times in UTC) and you want to avoid updating your local mirror at those times. Thus the suggestion is to use 2h, 8h, 14h, 20h. You are also invited to tweak the precise minute (17 in the example above) to a random value between 0 and 59 to spread the load so that not all servers connect at the same time.