I can't help but point out the irony of asking this question on a site that's driven by the efforts of office slackers. Anyway, needed to get that out of my system.
So let's start with an ethically questionable argument. Not because that's what I'll conclude on, but because I want to start exploring this as a baseline.
Is your boss unhappy about your performance? If not, what are you worrying about?
Now, before the barrage of downvotes and comments arrive on my doorstep, considering slacking off as an acceptable work pastime is obviously morally grey at the very least. This answer is not intended as a "how to get away with it" manual.
However, at the same time I also feel compelled to point out that a significant amount of office jobs have significant gaps of potential downtime. I can attest to this personally, having worked in many different workplaces, and hearing from friends and peers who also work in offices (in all kinds of roles).
A lot of people are slacking off on the internet for a decent amount of their office work time. I don't have the numbers on it but I would argue that sites like StackOverflow and StackExchange thrive specifically on that excess downtime that office workers have.
This isn't even a joke, I genuinely believe that if you haven't watched it already, you need to watch Office Space. Even though it's a comedy, it genuinely does explore the existentialism that comes with having a boring office job that keeps you wanting to slack off. How the story resolves for the protagonist might just be the resolution that you're looking for (and I'm intentionally not telling you here, it would be better to experience the narrative and not just look up the conclusion).
At the end of the day, there is no objective measure of whether you're meeting your goals, other than whether your manager is happy with your work output (whether you feel like you're meeting your own goals, if you care to evaluate yourself on this).
So if you fulfill the expectations that your employer has of you, an argument can be made that you are fulfilling the role you're employed for. It might not win you any performance awards or career progress, but no one said you have to push for those anyway.
Others may argue that your performance should be measured by what you spend your 8 hours a day doing, rather than by what you deliver in that timeframe. That's a different discussion for a different day, and it's neatly hidden in this answer under the "is management complaining about your performance" criterion, because if management were judging you on what you spend your time on, and you are slacking off, then they would inherently be calling you out on it.
they said they would only give me the job if I was willing to work out problems on my own without bothering anyone. They aren't paying me very much so they aren't taking on that much risk.
No one is really interested in assisting you, and you don't cost the company much. The economic reality here is that you have a very low bar to clear in order to be worth more than you cost. When you're a net positive, you generally don't run into management complaints (unless management squeezes everyone at all times, which is a very different fish to fry that is clearly not relevant for your current scenario).
But this is not the conclusion of the answer. You asked how to do better. Specifically:
I desperately need help. I've struggled with this bad habit for years. Tricks like blocking websites hasn't worked. I want to get to the root of the problem. What can I do to change my bad habits and improve my productivity at work?
I want to point out here that change is an action on your part. It is not something that happens automatically just because you cleverly change your surroundings (like blocking websites).
Sure, changing your surroundings might assist you in actioning this change, but the cliché quote rings true: change comes from within. Don't rely on external tooling, because if that's the only thing keeping you on task, then the moment you lose that tooling, you will fall off the wagon again.
Sure, you make sure an alcoholic doesn't have access to alcohol while they're going through withdrawal and while in recovery, but keeping them physically removed from alcohol is not a sustainable solution. It's about building an internal drive that gets them to acknowledge the problem, their weakness, powers their own agency, and drives them to act differently even when they're in the vicinity of alcohol.
That internal drive is key to solving the problem. So explore it. Why do you want to do better? If it's about not getting fired, then the previous section applies: as long as your boss is happy, you've done your (literal) job.
But do you want something more? You mention that you took this job as a means of getting experience. I assume this is a genuine feeling that you currently still have.
So act on that feeling. Don't ignore it. Worry about not gaining that experience that you need. Set long term goals for you to achieve, with a significant consequence (either negative for not achieving it, or positive for achieving it; depends on what works for you).
If everything else fails, money is a good incentive. You might be comfortable with your income today, but will that income be enough tomorrow? Would you want to be more financially stable? In order to do that, you need to progress your career. In order to do that, you need experience. In order to get experience, you need to work at problems and not avoid them (which is inherently the avoidance of experience).
Humans are inherently incentive-driven creatures. Everything we do, we do for the benefit that it gets us, whether than benefit is visible or a personal feeling (which is effectively a dopamine injection in your brain).
Find the incentive that works for you, and then use permanent glue to attach your goals to that incentive in a way that you can't back out halfway. A lot of birds only fly when they get kicked out of the nest and the alternative is falling to their death, i.e. they cannot come out of it unscathed if they end up not achieving their goal. They're committed and have to meet their goal, or else.
At the end of the day, others can't decide this for you, because that would mean that (a) you need to be mothered and aren't actually an adult nor working at becoming one, and (b) it raises a lot of eyebrows with regards to someone else having absolute authority over how you live your life.
This is not a self-help group, and I can't be your life coach (nor IA sponsor) by writing this answer. That's not to say I don't care, I've struggled with similar things in the past, but the purpose of this answer is to reframe how you think about what the problem is.