Termux works great as a server environment really. The trickiest part is to start phone without old battery and actually have automatic booting after power outage.
I accidently discovered earlier today that the Fairphone 3 works without it's (easily swappable) battery. So maybe other brands still build them like this.
Since we're talking about an Android phone for self hosting, if the phone is glued/the battery is soldered, after rooting it, the Advanced Charging Controller App* may be an option.