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 410 GB on 2024-02-22 (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.
https://cran.r-project.organd can also be accessed via rsync to cran.r-project.org::CRAN.
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" -rptlzv --delete cran-rsync@cran.r-project.org::CRAN /dir/on/local/disc
or (potentially insecure):
rsync -rptlzv --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).
It is a good practice to consider your file system permissions/users schema beforehand to ensure that every synchronization will be successful and that afterwards the server software (e.g. Apache) will be able to access all the files required. Depending on your server environment it might be achieved by careful planning, adjusting permissions/ownership in your rsync script, or by additional parameters to rsync itself.
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.
For the last, when using Apache servers, if .htaccess files in the CRAN directory are enabled (will 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>
Please make persistent links to specific package source versions, e.g., https://CRAN.R-project.org/package=uuid&version=1.2-1, work by adding rewrite rules for this mechanism. For Apache, you can use:
## 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 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]
For nginx, Alexandr Šabacký successfully used the following (for a CRAN mirror located in /R):
location ~ ^\/R\/package=([^/]+)&version=([^/]+)$ { try_files "/R/src/contrib/$1_$2.tar.gz" /fallback_CRAN; add_header Content-Disposition 'attachment; filename="$1_$2.tar.gz"'; } location /fallback_CRAN { try_files "/R/src/contrib/Archive/$1/$1_$2.tar.gz" =404; add_header Content-Disposition 'attachment; filename="$1_$2.tar.gz"'; }
If you would like to promote the hosting institution of the mirror, you can use the environmental variable CRAN_HOST.
In that case, you would need to enable server side includes (without execution).
If you have an Apache 2.4+ 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 additionally 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.
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!