❤️ 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.
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.
- Support for Drupal metadata
- Translate readme.md and index of mirror.
- Fully IaC with terraform.
- More recipes to AWS/Azure/GCP/DigitalOcean and another cloud providers.
- Support for Heroku.
- Support for kubernetes.
- Support gz disabled for limited configuration access to Apache/Nginx.
- Support full mirror mode: Github/Gitlab.
- Integration with twity.
- Integration with composer-registry-manager.
The following versions of PHP are supported by this version.
- PHP >=7.2
$ vendor/bin/phpunit
- prestissimo Downloads packages in parallel to speed up the installation process.
- composer-mirror Create a mirror (open sourced code but not maintained)
- packagist-mirror Create a mirror (outdated)
- packagist-crawler Create a mirror (outdated)
- 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.