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.
1 |
sudo apt install -y apt-mirror |
Configuration
The configuration file is /etc/apt/mirror.list
. Just add the apt links for what you want. Here is some of mine:
1 2 3 4 5 6 7 8 9 10 |
set base_path /var/www/html deb-amd64 http://ppa.launchpad.net/ondrej/apache2/ubuntu xenial main deb-amd64 http://ppa.launchpad.net/ondrej/apache2/ubuntu bionic main deb-amd64 http://ppa.launchpad.net/ondrej/php/ubuntu xenial main deb-amd64 http://ppa.launchpad.net/ondrej/php/ubuntu bionic main deb-amd64 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial main deb-amd64 http://ppa.launchpad.net/certbot/certbot/ubuntu bionic main clean http://ppa.launchpad.net |
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
1 |
sudo apt-mirror |
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
1 |
0 0 * * * root /usr/bin/apt-mirror >/dev/null 2>&1 |
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:
1 |
add-apt-repository -y ppa:ondrej/php |
Afterwards I modified the source file /etc/apt/sources.list.d/ondrej-ubuntu-php-xenial.list
1 2 3 |
#deb http://ppa.launchpad.net/ondrej/php/ubuntu xenial main deb [arch=amd64] http://apt-mirror.lupecode.com/mirror/ppa.launchpad.net/ondrej/php/ubuntu xenial main # deb-src http://ppa.launchpad.net/ondrej/php/ubuntu xenial main |
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.