โค๏ธ Recommended by packagist.org โค๏ธ
Announcement: Composer 2 is now available!
This mirror is for Composer 1; Composer 2 is very fast on its own. We will update to support the version 2 for those need solve the slow internet access or availability problem with the main repository.
A mirror for packagist.org that regularly caches packages from one or more main mirrors to add to a distributed package repository.
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.
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.
๐ซ Amazing data mirrors used to download repositories metadata built using this recommended repository or another:
Lists are ordered by country and sync frequency.
Location | Mirror | Maintainer | Github | Sync | Since |
---|---|---|---|---|---|
China | mirrors.aliyun.com | Aliyun | Every 5 minutes | ||
China | mirrors.cloud.tencent.com | Tecent Cloud | Every day | ||
Japan | packagist.jp | Hiraku | forked | Every 2 minutes | Q4'14 |
Japan | packagist.kawax.biz | Kawax | another | Every hour | Q4'18 |
๐ Not working as a mirror of packagist.org (checked at Q1'20):
Location | Mirror | Maintainer | Github | Reason | At least |
---|---|---|---|---|---|
China | mirrors.huaweicloud.com | Huawei Cloud | Outdated | Q3'19 | |
China | packagist.phpcomposer.com | Outdated | Q4'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.
This map shows working mirrors from above at the country level. The colors represent the topology drawn below.
๐กTip: use a machine with at least 2GB of RAM to avoid using the disk or swap space during sync.
โ ๏ธ When syncing fromDATA_MIRROR
orMAIN_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.
- Docker Compose - Fully automated solution using Docker Compose.
- Docker + Nginx + PHP - Docker for cron jobs, Nginx + PHP on the host.
- Nginx + PHP - Cron + Nginx + PHP all running on the host.
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
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
betweendocker-compose
andup
ordown
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.
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
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.
Please see CONTRIBUTING and CONDUCT for details.
The following versions of PHP are supported by this version.
- PHP >=7.2
$ vendor/bin/phpunit
- composer/mirror The official composer mirrorring script (used for official packagist.org mirrors)
- composer-mirror Create a mirror (open sourced code but not maintained)
- composer-registry-manager Easily switch to the composer repository you want
- packagist-bot Yet Another Packagist Mirror
- twity Provide a web based management of private and public composer packages.
- velocita-proxy Composer caching reverse proxy
MIT License. Please see License File for more information.