[Solved] While executing: attempt to write a readonly database error

make sure the ownerhips are correct in directory /etc/pihole. (you can find right ownership list @deHakkelaar post below.)

usermod -aG pihole www-data

reboot

this solved my problem. some of the files owned by root and that's why readonly error occured.