I had been struggling to get my old Canon MP560 to work with my new Mac Mini running Bir Sur. I decided to use my Raspberry Pi 4 running Ubuntu Server 20.04 as a printer server and at the same time to see if I could finally get printing to work from my iPhone.
I discovered that it is relatively straight forward to setup printer sharing via AirPrint. I based my inital attempt on the Linux Magazine's atricle on setting up AirPrint but I have different settings for the cups configuration and didn't need to add the mime types. I also needed to adjust the firewall settings and get my printers working from Linux as I had not previously set them up for Linux, only for Windows and MacOS
CUPS installation
For the CUPS installation I used the following packages:
- cups-bsd
- avahi
- printer-driver-gutenprint
I installed CUPS and the Gutenprint printer drivers (which include drivers for both my Canon MP560 and HP Laserjet 6P) using the following steps:
I then edited the CUPS configuration and changed only the bits shown below. I left the rest of the file alone.
I then configured the firewall to allow access to CUPS and Avahi. Note the network this setup is on is 192.168.200.0 as seen in the config below - change as required.
I then added any required users to the lpadmin group. eg sudo adduser XXX lpadmin before restarting CUPS (sudo systemctl restart cups) and starting and enabling avahi-daemon.
I then connected to my Raspberry Pi on port 631 and used the CUPS admin interface to add my Canon MP560 and HP Laser 6P printers and checked that they worked by printing a test page for each.
AirPrint configuration
Once I had confirmed that the printers were setup and that the Raspberry Pi could successfully print from them, I used the 'airprint-generate.py' script from https://github.com/tjfontaine/airprint-generate/archive/refs/heads/master.zip to generate avahi service files. 'airprint-generate.py' has the following dependencies:
- python3
- python3-cups
Both of my printers were now visible to and usable from both my iPhone and Mac Mini.