Building a Magento Testing and Development Environment – Setup a local APT proxy

Part 5, Setup a local APT proxy

Most of the hosts in my Magento development environment are going to be running Ubuntu. I will want to install security and application updates, but I don’t want to kill the Ubuntu repositories with my requests.  I’d also like a little bit of control over the updates.  If I want to install an update on production I need to test it first, and make sure the version I install on production is the same version I installed in the test enviroment.  For this I’ll use an APT caching proxy.

Apt-Cacher NG is a caching proxy for Debian/Ubuntu APT. It can act as a proxy for all of the servers needing APT based updates, and it can cache those updates that have been installed.  Allowing you do disable new updates coming into the server so you can test the updates that are already cached and roll those out to production.

The installation is fairly simple, not much need for screen captures here.  So, let’s begin. First you need to SSH into your system.  If you setup your Ansible server using the instructions in the previous post your account should be created, your keys distributed, and you have sudo access. So, do the following to install Apt-Cacher NG.

ssh servername
sudo su -
apt update
apt upgrade
apt install apt-cacher-ng

At this point you can use your server as an APT proxy without any other changes.  However, to fully make use of the system’s features you need to do a little more. First, we need to edit the security config to create an admin user. To do that edit the security.conf file and uncomment the #AdminAuth line by removing the # symbol.  Then change the “moopa:moopa” to a username and password in the format username:password.

nano -w /etc/apt-cacher-ng/security.conf

AdminAuth: username:password

Save the changes to the file. Now lets copy the existing packages that were downloaded during the servers apt update and upgrade to seed the cache. To do this we’ll need to create an import directory, set the permissions on that directory and copy the files.

mkdir /var/cache/apt-cacher-ng/_import/
chown -R apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng/_import
cp /var/cache/apt/archives/*.deb /var/cache/apt-cacher-ng/_import/

Now we need to import those and make a few configuration changes.  So, open a browser and go to the link http://server_ip:3142/acng-report.html.  Once there change your settings to the same as below. If you are prompted for a username and password use the one you created in the security.conf file.

Magento APT caching proxy setup
APT-Cache NG configuration

Now, we need to download and import the packages that were already installed on our system. So click the icon Start Import.

Magento APT caching proxy setup
APT-Cache NG download and import

You should see the system downloading and importing the packages.  You will need to do this periodically although there are ways to automate this using cron jobs and bash scripts.  Also, you can setup a mirror so your server will act more like a full repository.  However this takes much more setup.  If you are interested in either of those options let me know and I will try to add them to this post later.

Your APT caching system is now setup and ready to use by all of your Debian/Ubuntu systems.

Intro – Magento Development Environment
Part 1 – Installing Proxmox
Part 2 – Creating the Virtual Machines
Part 3 – Setup MySQL Master-Master
Part 4 – Setup Ansible
Part 5 – Setup APT Proxy

Leave a Reply