I do exactly this with my old MacBook Air and have done for some time. The only difference from the above posts is that instead of using macOS I wiped it clean and installed Ubuntu Server (it's still possible to reinstall macOS should I ever want to).
There are a few things you need to consider. One is that the wi-fi almost certainly won't work out of the box on Linux as it's Broadcom and depends on a proprietary driver that has to be manually installed. In my case I use a wired USB ethernet adapter which is a better fit for a server use case anyway.
To fix the lid closing issue on Ubuntu you have to edit the file /etc/systemd/logind.conf and uncomment the line #HandleLidSwitch=ignore (remove the # symbol at the start).
The other problem you'll encounter is the screen being on, which on older models means the Apple logo staying permanently lit. I would imagine this isn't good for it. On my machine I fixed this by adding a line to my crontab that automatically turns it off when the laptop boots:
Do sudo crontab -e then insert something like the line below:
@reboot echo 0 > /sys/class/backlight/intel_backlight/brightness
This may be specific to my MacBook Air but the setting looks like it probably applies to most or all Intel-based MacBooks.
Finally, I recommend controlling the machine via SSH, there is plenty about this if you are not familiar. The OpenSSH server should be enabled by default when you install Ubuntu Server iirc.