If you're in a city, you might try working out of a co-working space a few days a week. It would also give you a chance to socialize with other developers when you need a break from working. This can be a good thing, as long as your don't spend the whole day socializing. :)
If you live in a house and have a decently sized property, you could try building a 'Shedquarters' (Google it, there are some pretty amazing examples out there). Alternatively, you could park a camping trailer on your property and work from there.
At the end of the day, nothing will be a substitute for good work habits. And make no mistake, staying focused and on task is a skill you can develop and improve over time. Getting started is the hardest part.
In the past, I've found it helpful to ban myself from using the internet after my work hours are done for the day. Pick up some good books, and spend a couple of weeks worth of evenings just reading non-stop. It'll be hard at first, and you'll be tempted to go online. Keep on reading regardless, even if you really don't feel lie it. I've found that after a week or two, the urges to go waste time diminish. And interestingly, the strength to avoid distraction and keep plowing forward even when I don't feel like it carries carries over to the work day. I realize that this might only work for me and nobody else. But it might be worth a try if you're looking for a starting point.
Having a routine is important.
Additionally, here are a couple of things that you might consider hacks that have worked for me:
1) Front-load your day - I start my day at 4am and I start work immediately. This has a couple of benefits. For me I know I am most productive the first half of my day. Starting early eliminates a long list of distractions and interruptions simply because no one else is up to bother me. Plus, if I find myself dragging between 4pm and 6pm I don't feel guilty about cutting out because I have already put in a pretty solid day overall. This is something I read not to long ago that validated what I was already doing: https://news.ycombinator.com/item?id=12346307
2) Walk - Any time I am feeling distracted or stressed I take a walk outside. It reboots my mind and I come back refreshed. If something was eluding me before the walk it typically reveals itself quickly after returning from the walk.
3) Diet - This is from my response to this post (https://news.ycombinator.com/item?id=12684180): "In order of volume and priority...Coffee, leafy greens(in all forms, especially cabbage - all types, kale, napa, green, etc.) and protein in all forms, diversity is important, animal and vegetable sources.
I mix in other fruits and vegetables for flavoring and variety. Also, I eliminated salt and that relieved my stress in a significant, noticeable way.
I start my day at 4am, if I eat heavier, carb-based items, I notice a crash somewhere around 3 or 4 pm and the last few hours of my day are a struggle. If I stick to what I listed above, I power through the afternoon and feel more balanced when I end my day."
If this is something you do regularly, you want to try the free app Work Hard Anywhere  which lets you find the best nearby to work from. I use it every week.
Distractions are usually a consequence of being burnt out. That means you need to take more _effective_ breaks and/or work out your discipline muscle, meaning you can go longer and more effectively.
(Then again, my "problem" is the opposite and I think it's something a lot of remote workers experience — you work even more hours and even harder than in a typical office environment.)
What is the general idea behind it - and how would one get started at this practice?
It's really as simple as sitting down in front of an empty wall, closing your eyes (or not), and counting each breath 10 times (I like to count one full breath as "one count" rather than counting an inhale as one and exhale as two), then repeating back to the beginning. Whenever your thoughts go elsewhere you remind yourself to focus on the current number you're on. Really helps clear the mind and can even occasionally experience a state of euphoria in the process.