Are you sure that's "illegal" or just "illegal to take money for it" ? Here (Poland) you can do it just fine on your own stuff as long as you don't pretend to be electrician and sell your service, with caveats (only touching anything after power company stuff IIRC)
In much of the US, you are allowed to do any work that you want to on your own property, though if a professional would be required to get permits and inspections to do the same work then you usually still have to get those permits/inspections.