Home

Awesome

๐Ÿ“ฆ Packagist Mirror

Build Status docker Status docker pulls Minimum PHP Version Packagist Codecov Quality Score Mentioned in Awesome composer

โค๏ธ Recommended by packagist.org โค๏ธ

A mirror for packagist.org that regularly caches packages from one or more main mirrors to add to a distributed package repository.

Mirror creation

If you're using PHP Composer, commands like create-project, require, update, remove are often used. When those commands are executed, Composer will download information from the packages that are needed also from dependent packages. The number of json files downloaded depends on the complexity of the packages which are going to be used. The further you are from the location of the packagist.org server, the more time is needed to download json files. By using a mirror, it will save you time when downloading json because the server location is closer.

โš™๏ธ How it works?

This project aims to create a local mirror with ease, allowing greater availability for companies/countries that want to use composer without depending on the infrastructure of third parties. It is also possible to create a public mirror to reduce the load on the main repository and better distribute requests around the world, helping make the packagist ecosystem faster as a whole!

When creating a mirror, you add a list of other mirrors to use for initial sync, which pulls all packages to your local machine. After the mirror is created and synced, the next runs will only pull updates. If any mirror fails to deliver a metadata file, the client will fallback to its configured main mirror, whether that be packagist.org or otherwise. If the client encounters an installation problem or loses connection to a mirror, it can return from where it stopped running.

Mirror creation

๐ŸŒŽ Packagist public metadata mirrors observatory around the world

๐Ÿ›ซ Amazing data mirrors used to download repositories metadata built using this recommended repository or another:

Lists are ordered by country and sync frequency.

LocationMirrorMaintainerGithubSyncSince
Brazilpackagist.com.brWebysthermainContinuouslyQ3'17
Chinaphp.cnpkg.orgEagle WuforkEvery minuteQ3'18
Chinapackagist.mirrors.sjtug.sjtu.edu.cnShanghai Jiao Tong UniversityforkEvery hourQ2'19
Czech Republicpackagist.hostuj.toHOSTUJ TOforkEvery 5 minutes๐Ÿ†•Q1'20
Finlandpackagist.fiNiko GranรถforkEvery 5 minutes๐Ÿ†•Q2'20
Francepackagist.frBaptiste PillotforkEvery minute๐Ÿ†•Q4'20
Germanypackagist.hesse.imBenjamin HesseforkEvery minute๐Ÿ†•Q3'20
Indiapackagist.inVarun SridharanforkEvery minuteQ2'19
Indiapackagist.vrkansagara.inVallabh KansagaraforkEvery 5 minutesQ4'19
Indonesiapackagist.phpindonesia.idIndra GunawanforkEvery 30 secondsQ3'18
Indonesiapackagist.ianmustafa.comIan MustafaforkEvery 30 secondsQ3'19
Indonesiapackagist.telkomuniversity.ac.idTelkom UniversityforkEvery 5 minutes๐Ÿ†•Q1'20
Japanpackagist.dev.studio-umi.jpStudio UmiforkEvery minute๐Ÿ†•Q1'20
South Africapackagist.co.zaSolidWorxforkEvery 5 minutesQ3'18
South Koreapackagist.krPackagistKRforkEvery minuteQ3'18
Thailandpackagist.mycools.in.thJarak KritkiattisakforkEvery 5 minutesQ4'19
USApackagist-mirror.wmcloud.orgWikimediaforkEvery 5 minutesQ3'18
Taiwanpackagist.twPeterforkEvery 5 minutes๐Ÿ†•Q2'20
Taiwanrepo1.packagist.twPeterforkEvery 5 minutes๐Ÿ†•Q2'20
Vietnampackagist.ondinh.netLong NguyenmainEvery 5 minutes๐Ÿ†•Q3'20

โš ๏ธ Not based on this source code:

LocationMirrorMaintainerGithubSyncSince
Chinamirrors.aliyun.comAliyunEvery 5 minutes
Chinamirrors.cloud.tencent.comTecent CloudEvery day
Japanpackagist.jpHirakuforkedEvery 2 minutesQ4'14
Japanpackagist.kawax.bizKawaxanotherEvery hourQ4'18

๐Ÿ›‘ Not working as a mirror of packagist.org (checked at Q1'20):

LocationMirrorMaintainerGithubReasonAt least
Chinamirrors.huaweicloud.comHuawei CloudOutdatedQ3'19
Chinapackagist.phpcomposer.comOutdatedQ4'19

If you know any new mirror based or not on this one, please create a issue or a pull request with the new data.

Check status page for health mirror's.

World Map

This map shows working mirrors from above at the country level. The colors represent the topology drawn below.

๐Ÿš€ Create your own mirror

Topology

๐Ÿ’กTip: use a machine with at least 2GB of RAM to avoid using the disk or swap space during sync.

โš ๏ธ When syncing from DATA_MIRROR or MAIN_MIRROR, your server encodes and decodes all packages as .gz files to save disk space. You may need to enable server-side decoding for legacy composer clients that ask for decompressed packages.

There are currently three supported methods for creating your own mirror.

In all three methods, you need to clone the repository and copy .env.example to .env and modify to include your values instead of the defaults.

# Clone this repository
$ git clone https://github.com/websyther/packagist-mirror.git

# Setup environment variables
$ cd packagist-mirror
$ cp .env.example .env
$ nano .env

Docker Compose

Run the following commands to start a container for Nginx, PHP-FPM, and a worker that runs cron jobs.

# Start all Docker containers
$ docker-compose up -d

# Follow log output
$ docker-compose logs -f

Once the initial sync has finished, open https://localhost:9248 to see your site.

๐Ÿ’กTip: Add -f docker-compose.prod.yml between docker-compose and up or down while running the above commands. If you are using traefik, the services in this docker-compose file contain labels used by a running traefik container to automatically route traffic matching those labels to that container. It even auto-renews LetsEncrypt certificates for you.

Docker Nginx PHP

First, add the following line to /etc/crontab to tell the host to start a container for the packagist-mirror image on boot, replacing the values for each -e flag with your own. This will start the initial sync and generate the website files to be served by nginx.

Learn about more the available options for this docker image here.

* * * * * root docker run --name mirror --rm -v /var/www:/public \
-e MAINTAINER_REPO='packagist.com.br' \
-e APP_COUNTRY_NAME='Brazil' \
-e APP_COUNTRY_CODE='br' \
-e MAINTAINER_MIRROR='Webysther' \
-e MAINTAINER_PROFILE='https://github.com/Webysther' \
-e MAINTAINER_REPO='https://github.com/Webysther/packagist-mirror' \
-e URL='packagist.com.br' \
webysther/packagist-mirror

Next, add the following to /etc/nginx/sites-available/packagist.com.br.conf to host the website files:

server {
    index.html;

    server_name packagist.com.br www.packagist.com.br;

    location / {
        try_files $uri $uri/ =404;
        gzip_static on;
        gunzip on;
    }
}

To monitor sync progress, run the following command:

docker logs --follow --timestamps --tail 10 mirror

Nginx PHP

After cloning the repository, run the following commands to configure for your host.

$ cd packagist-mirror && composer install
$ cp .env.example .env

Then, schedule the command to create and update the mirror:

$ php bin/mirror create -vvv

Nginx will now serve your mirror at the configured URL.

๐Ÿง Development & Contributing

Please see CONTRIBUTING and CONDUCT for details.

๐Ÿ›ฃ๏ธ Roadmap

2020

2021

๐Ÿ“‹ Requirements

The following versions of PHP are supported by this version.

๐Ÿงช Testing

$ vendor/bin/phpunit

๐Ÿฅ‚ Credits

๐Ÿ’™ Other correlated projects

โ˜ฎ๏ธ License

MIT License. Please see License File for more information.

FOSSA Status