I once inherited a mission-critical PHP project which had no version control, no tests, and no development environment (all edits were made directly on the server). It used a custom framework of the original author’s own devising which made extensive use of global variables and iframes and mostly lived in several enormous PHP files. I was able to clean it up somewhat, but there was one particularly important file that was so dependent on global variables and runtime state that I never dared touch it.
It wasn't mission critical but my very first production programming project (n.b. I'm not a programmer and never had any classical training or education as one) was an abomination. I'd like to think the realisation of how bad it was, despite it just about working, was a call to arms to up my game a little. I ended up learning a lot about data structures, writing understandable code and comment, when not to write code, all that OOP stuff and things like STI, Generics (still not sure what they are), testing (TDD AND BDD!!! Yea, Cucumber!) and a plethora of other useful things.
My first thought when reading this description was that step one is to make a local copy, get a development environment setup where you can toy around, see how things fit together. The 'stupid'er the setup (like using plain old files instead of a database), the easier that actually gets (apt install apache2 php; rsync da:files /var/www). Wouldn't that have helped solve this particularly important but untouchable file?
If I remember correctly, the file was processing global state from other parts of the system, and it was such a Byzantine bit of code that I had almost no hope of understanding what it was actually doing without being able to observe state in the production system as it was being used. Plus at the time I wasn’t a particularly competent programmer myself (this was my first programming job). In the end I figured it wasn’t worth risking breaking it when its replacement was on the way.
When I was finally able to retire the project several years later, I first replaced the home page with this picture: http://2.bp.blogspot.com/-6OWKZqvvPh8/UjBJ6xPxwjI/AAAAAAAAOv...