Packages, Dependencies & Environments


Posted November 11, 2019


Like Steve Martin and John Candy in Planes, Trains & Automobiles, the coding journey to add my functioning PHP app to Heroku made me wonder if I'd ever reach my destination.

Encouraged by all the PHP jobs I see posted, I read up on the language and discovered it's pretty easy to learn and in no danger of dying off anytime soon. So I found a tutorial, built a CRUD app with a remote database, learned a ton, and decided to add the app to my digital portfolio. I knew I could host my low-traffic database-driven app free on Heroku, but I also knew I'd have to tweak it to work remotely. I researched my options and decided a JawsDB add-on was the best tool for the tweaking and proceded accordingly.

The first important tip I learned about moving a PHP app to Heroku is that I needed to install the Composer package manager to create my composer.json file. This file delineates the programs used to create the app, some of which are called dependencies. As the name implies, the app is dependent on certain programs to run, and Composer manages the process of making them available in the server environment, i.e. Heroku. With my JawsDB add-on in place and my composer.json file accurately listing my dependencies, I figured I was headed the right direction.

Researching how to work with PHP and MySQL in Heroku wasn't full of hilarious road trip hijinks, but it did have a few light bulb moments. For instance, I realized that while my previous databases were stored on my computer, my current database was already remote. So maybe all this add-on, .json file stuff was a dead end. But the app stopped working once I pushed it to the Heroku environment, so something still needed tweaking. I kept researching. YouTube videos ... Stack Overflow threads ... Composer documentation ... I was determined to reach my destination, which in my case was a remotely hosted, fully functioning database-driven PHP app.

If you've ever endured a lengthy flight layover, a full-blown cancellation, unexpected rerouting or a hellish combination of the three, you empathize with Martin and Candy freezing in the back of a pickup on the outskirts of Wichita instead of safely snug-as-a-bug at home in Chicago. After 10 to 12 hours of trying new solutions, uploading revisions, and checking my still-broken app, I felt their pain too. I knew I was close to a breakthrough. But like those last hundred miles they spend in the doorless car that eventually catches fire, I still had a ways to go.

I left my app alone for a few days and pondered moving on. After all, my original goal was to create a working PHP app, and I'd done that. But if I could only demo it in my local environment, it felt like a half-baked success. Then, on my birthday, my coding mentor son-in-law stopped by. I described my problem, showed him my files, and asked his opinion. He agreed I was really close.

The step I missed was importing my already remote (and already exported) database into the new one I'd created in Heroku with JawsDB. A quick schema setup in MySQL Pro followed by an equally quick database import, and voila! I uncommented the JawsDB settings in my db_connect.php file to make them available, pushed the updated files to Heroku for what seemed like the millionth time, and my PHP app was working. Thanks to Rowan's helpful tip I was home — in time for Thanksgiving and everything!

I realize there are more roadblocks, detours, and reroutes on the dev road ahead of me. But my knowledge base grows every time I successfully navigate the hazards to reach my destination. I'm not there yet, but I see a day in the not-so-distant-future where I'm the one who says, "Yeah, just drop in that variable to replace localhost with your server and you're good to go." That'll definitely be one for the scrapbook.