I have an old Raspberry Pi B+ since 2014. Did some experiments back then, even made it to broadcast a FM radio within 50m radius, but now I`m giving to it a new, particular tasks to do - make my simple and cheap HP LaserJet to be found in the local home network.
So, I will need a few things. Firstly, a fresh SD Card with Legacy Raspbian OS, CLI. (While installing with Raspberry Pi imager, it is convenient to set all the necessary settings like enabling ssh and home wifi , so no monitor and external keyboards will be neccessary.) Then, install PuTTY.
Finding the ip address of the pi can be done through home router (if DNA automatically assigns it), or ... attach it to separate monitor or keyboard.
Then, when you log in via ssh - first things -
sudo apt update
sudo apt upgrade
When repos are set, next thing is installing CUPS (Common UNIX printing system).
sudo apt-get install cups
It is not enough tho. HP Laserjet Pro M15a will need hp drivers. This is where hplip can be helpful.
sudo apt-get install hplip
After HP drivers are installed, the CUPS needs to be configured so its admin page is available from any computer within my network.
So a CUPS configuration file needs a few modifications.
# Listen on external interfaces for connections
# Show shared printers on the local network.
# Default authentication type, when authentication is required...
# Restrict access to the server...
# Restrict access to the admin pages...
# Restrict access to configuration files...
Require user @SYSTEM
And now I can restart the service.
sudo service cups restart
sudo /etc/init.d/cups restart
Now lets add Raspberry Pi user to the lpadmin group
sudo usermod -a -G lpadmin your-username
Now the printer should be visible in the CUPS configuration page.
Opening the CUPS conf page on the browser - CUPS port is 631
Navigate to add a printer.
Now you should be able to see a printer in the list.
In the end let`s make a Raspberry Pi having a static ip address. I have Mikrotik router.
Under the section IP find DHCP server and select the Leases tab there. Find your RPi there, click on it, and click on the button "Make Static"
Then add printer on your local devices. It should show up.