Keep packages with APT pinning

I recently switched to Debian. The thing I liked the most about this switch was the possibility to have the development environment as similar as possible to the production one of the many projects I maintain.

Very soon I found a problem though, specifically with Apache + PHP websites. Packages for PHP and Apache were too recent to work smoothly with my legacy projects.

Solution 1 – Vagrant

Vagrant helps you to keep per-project virtual environments. It works in conjunction with virtual providers like VirtualBox or VMWare. Vagrant is awesome and it was my first choice. I decided to go with this solution mainly because I didn’t want to downgrade my machine to use older software versions.

Setting up Vagrant is pretty straightforward. One problem I found though was with shared folders and Apache. Vagrant mounts your project’s folder under a /vagrant folder in the virtual machine. Having Apache to read files directly from this folder is not a good idea. In fact, you’d want to change the ownership of files under Apache to www-data. And you cannot chown a shared folder. I was not able to change this default configuration so I decided to mount the same folder under a different name. You can do it in Vagrantfile:

 # Share an additional folder to the guest VM. The first argument is
 # the path on the host to the actual folder. The second argument is
 # the path on the guest to mount the folder. And the optional third
 # argument is a set of non-required options.
 # config.vm.synced_folder "../data", "/vagrant_data"
 config.vm.synced_folder ".", "/var/www", owner: 'www-data', group: 'www-data'

It did the trick, virtual machine configured, problem solved.

Solution 2 – APT pinning

I was not completely happy with solution 1. Vagrant is perfect, but I felt like I was using it to solve the wrong problem. That little bit of overhead to startup a virtual machine for every project I had to work on was simply too much. After all this setup was only to keep older versions of two little packages, Apache and PHP.

I decided to study a little bit more on how APT works when it comes to lock packages to specific versions. I found `pinning` as a solution. Very powerful tool, highly configurable. It was enough to add this configuration in my `/etc/apt/preferences`:

Package: *php5*
Pin: release n=squeeze
Pin-Priority: 1000

Package: *apache2*
Pin: release n=squeeze
Pin-Priority: 1000

Instead of locking to a specific version I decided to use the release name, which was enough to get the job done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s