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.