Setting Up a Local Apt Mirror for PPAs

I use the PPAs for both Apache and PHP. I know that when running apt update downloading from the PPAs takes a while. This post describes how to set up a local apt mirror to speed that up.

Note

This post assumes that you are running Ubuntu. Can’t use the PPAs without running Ubuntu. You can set up apt-mirror for Debian though, just replace the apt links with what you need. I’m also going to assume that you have a server ready to go.

Weather you want to run this on a dedicated server or an existing server with other things, that is up to you.

Beware this will consume a lot of disk space.

Requirements

  • You’ll need a bit of disk space.
  • A web or ftp server must be installed.

Installation

The actual setup is easy.

Configuration

The configuration file is /etc/apt/mirror.list. Just add the apt links for what you want. Here is some of mine:

I have both xenial and bionic servers that I use with this, which is why I have both. I also set deb-amd64 to reduce the disk space usage. I’m not running any 32-bit versions of Ubuntu.

Set your base_path to the document root of your web server, or one of its virtual hosts. That is another topic not covered by this guide. In my example, I have set it up in the default Apache folder.

Test

To run a test just run

and it should download all it needs. This will take some time.

Cron-ify

You can add a line similar to the following to your /etc/crontab file

This will updated the mirror once per day. That means that your mirror is at most 24 hours behind. That’s great!

Setting Up Clients

Your client devices will need to point correctly.

So that I didn’t have to worry about having the correct GPG keys, I set up my PPAs the normal way. Like this for PHP:

Afterwards I modified the source file /etc/apt/sources.list.d/ondrej-ubuntu-php-xenial.list

I commented out the first line, and added the second, just inserted apt-mirror.lupecode.com/mirror/ before the ppa domain and added the amd64 so that it would not look for the 32bit versions.

You’ll have to put your own domain, replacing apt-mirror.lupecode.com with what you have, even if it is just the IP address. apt-mirror.lupecode.com does not resolve outside my network.