CRAN Mirror HOWTO/FAQ

This page explains how to create a new CRAN mirror, which is fairly simple. If you would like to become an official CRAN mirror, please be sure to read and follow these instructions carefully. You should have the consent of your hosting company (if you aren't a hosting company yourself), and be prepared for some reasonably significant bandwidth usage. The full size of CRAN was approx 250 GB on 2019-11-29 (and we are growing all the time).

We currently have no written set of rules when we accept a new mirror into the official list. PHP accepts only up to two mirrors per country, we think there may be need to treat China different from, say, Luxembourg. So use common sense and ask yourself whether your mirror helps the R community. We want good global coverage, but also short lists on the mirror webpage or in a GUI. In addition, human time is involved in maintaining the list and monitoring it. If there is no mirror in your country, it will usually be accepted. Otherwise ask first if in doubt.


Where do I get a copy of CRAN?

The CRAN master site at WU Wien, Austria, can be found at the URLs
https://cran.r-project.org
ftp://cran.r-project.org/pub/R/
rsync: cran.r-project.org:

All you have to do is recursively mirror the complete tree to your webserver on a regular basis (at least twice a week, better every 1-2 days, but not more than twice a day). Which software you use for mirroring depends on the operating system of your server, but we strongly recommend that you use rsync. For security reasons we furthermore recommend mirroring over an SSH tunnel. You may want to call rsync using the following arguments:

 rsync -e "ssh" -rtlzv --delete cran-rsync@cran.r-project.org: /dir/on/local/disc 
or (potentially insecure):
 rsync -rtlzv --delete cran.r-project.org::CRAN /dir/on/local/disc 

For rsync over ssh please send your public SSH key to cran-sysadmin@r-project.org in advance (only requests from organizations are considered) and do not forget the --delete flag to remove files from the mirror that are no longer present on the master.

The CRAN tree uses symbolic links, and so rysnc may not work as expected on a Windows server. It may be necessary to replace -l by -L in the above (and this will also be necessary for some partial mirrors, e.g., those excluding the contrib/Archive area).


Server configuration

CRAN contains no dynamic pages, so in general no special configuration of your web server is needed. However, there are few additional settings and some settings to check.


❏ Display the common index files (usually the default setting).


❏ Files with extension .shtml need to be recognised as HTML pages (usually the default setting). The main frame of the CRAN top page banner.shtml has this extension, so you will immediately see it in case something is wrong.


❏ The following redirections need to work.

[YOUR CRAN MIRROR]/package=foo&version=bar  ➝ [YOUR CRAN MIRROR]/src/contrib/foo_bar.tar.gz IF /src/contrib/foo_bar.tar.gz EXISTS
[YOUR CRAN MIRROR]/package=foo&version=bar  ➝ [YOUR CRAN MIRROR]/src/contrib/Archive/foo/foo_bar.tar.gz IF /src/contrib/Archive/foo/foo_bar.tar.gz EXISTS
[YOUR CRAN MIRROR]/package=foo/bar  ➝ [YOUR CRAN MIRROR]/web/packages/foo/bar
[YOUR CRAN MIRROR]/package=foo  ➝ [YOUR CRAN MIRROR]/web/packages/foo/index.html
[YOUR CRAN MIRROR]/view=bar ➝  [YOUR CRAN MIRROR]/web/views/bar.html

If you use an Apache web server, this feature can be enabled by loading the mod_rewrite module. Additionally you would need either to just enable .htaccess files in the cran directory (might slow down your server), or (recommended) to add the following to the cran directory block of your apache configuration.

(goes in the <Directory [your cran directory]> ... </Directory> block)
RewriteEngine on

## package=foo&version=bar if current
RewriteCond "%{DOCUMENT_ROOT}/src/contrib/$1_$2.tar.gz" -f
RewriteRule "^package=([^/]+)&version=([^/]+)$" "/src/contrib/$1_$2.tar.gz" [R=seeother]

## package=foo&version=bar if in archive
RewriteCond "%{DOCUMENT_ROOT}/src/contrib/Archive/$1/$1_$2.tar.gz" -f
RewriteRule "^package=([^/]+)&version=([^/]+)$" "/src/contrib/Archive/$1/$1_$2.tar.gz" [R=seeother]

## package=foo/bar
RewriteRule ^package=([^/]+)/(.+) /web/packages/$1/$2 [R=seeother]

## package=foo
RewriteRule ^package=([^/]+) /web/packages/$1/index.html [R=seeother]

## view=bar
RewriteRule ^view=([^/]+) /web/views/$1.html [R=seeother]


❏ Generate listings of the directories in /src and in /bin.

For Apache servers, if .htaccess files in the cran directory are enabled (might slow down your server), it should work automatically. Alternatively (recommended) add the following to the apache configuration.

<Directory [your cran directory]/src>
        Options +Indexes
</Directory>

<Directory [your cran directory]/bin>
        Options +Indexes
</Directory>


❏ If you would like to promote the hosting institution of the mirror, you can use the environmental variable CRAN_HOST.

You would need to enable server side includes (without execution). For compatibility reasons the current syntax in banner.shtml is "pre Apache 2.4", so for it to be properly parsed by your server you might also need to include extra compatibility parameters in your configuration (for Apache see below).

If you have an Apache server, here is what you would need to include in your configuration.

  SetEnv CRAN_HOST "This server is hosted by your organization ..."
The string "This server ..." (which may contain HTML markup) will be added in the footer of the CRAN top page, see the main server for an example.

You would also need

Options +IncludesNOEXEC
in the corresponding <Directory> section, as also
  #
  # To use server-parsed HTML files
  #
  AddType text/html .shtml
<IfModule mod_include.c>
  AddOutputFilter INCLUDES .shtml
</IfModule>
in the MIME-types section of the Apache configuration, the exact syntax depends on the version of Apache. All you have to do is uncomment these (or similar) lines in the default configuration.

As mentioned above, Apache version 2.4 and newer does not recognise the syntax used in banner.shtml. If you have .htaccess files enabled (not recommended) the compatibility configuration is automatically applied. Otherwise add the following to the Directory block in the Apache configuration.

SSILegacyExprParser on


Inform us!

Once your mirror is up and running and the automatic updates work for a couple of days send email to cran@r-project.org such that we can include your site in the list of mirrors. Please include the following information in your email:

Thanks in advance for providing webspace for the R Project!


Last modified: December 9, 2019 by Gennadiy Starostin