Jump to content
J_Szwarga

Please help! Error in production environment only!

Recommended Posts

Spent hours on this yesterday and just a dead end. If you have any ideas here PLEASE help 🙂

Here's the background:

Running local on windows with MAMP PRO. Deploying to server pilot setup on ubuntu with atomic sftp deploys through git. Been using this setup on about 5 sites on daily basis for over 3 years and never ran into this yet.

Don't know if this is related to my problem, but right before this issue came up, I tried adding an external library (postmark's official php sdk) with `composer require`. Not realizing that processwire already checks for the vendor/autoload.php and loads it automatically (in the root index.php), I added a line to require_once the vendor/autoload.php file.

Worked fine on my local, but when I deployed to production, got an error about the autoload.php file not being found (incorrect path). So I removed the reference to autoload.php. Production environment still having issues with autoload.

Hmm, "that's weird" i thought. I'm not requiring autoload anymore. Maybe one of the composer dependencies are? OK, let me revert all my changes back to BEFORE I added this composer stuff in, so at least I can get the site to run.

Removed all the new dependencies in /vendor and also from composer.json. Commented out all my code that referenced these dependencies. Site still runs fine in development. 

Push to production....and now I get 'Fatal Error: Uncaught Error: Call to a member function addHookBefore() on null`. This is referencing a line in my ready.php that sets hooks on $forms:

$forms->addHookBefore('FormBuilderProcessor::saveEntry', function ($e) {})

Why all of a sudden does my production environment see $forms as NULL in ready.php? But development works fine? I tried changing $forms to $wire->forms or wire('forms') or $this->wire->forms but all end up with same result.

So I commented out all my code that set hooks on $forms, just to get my site to load. Once I do that...it does load. Almost. But now it gets to my page template and my menu has a reference to the MarkupSimpleNavigation module. 

$menu = $modules->get("MarkupSimpleNavigation");

And I'm adding a hook right after that:

 $menu->addHookAfter

And I get the SAME ERROR: Fatal Error: Uncaught Error: Call to a member function addHookAfter() on null

?????

My processwire production install is no longer recognizing any site modules???? But my development is.

I tried recreating a brand new server, deployment from scratch, just to the git commit BEFORE things started breaking...and STILL $forms is NULL, and $menu is NULL.

I totally deleted the /vendor folder and still nothing better.

Please if you have any idea why processwire wouldn't be recognizing any modules let me know. THANK YOU

Share this post


Link to post
Share on other sites

I'd try to remove as much as possible and then add features step by step and see when things start breaking. After each action check

  • Site Frontend (different pages, does the problem occur on one special page or on all?)
  • Site Backend (sometimes I had problems with my own code, so the frontend was broken but the backend worked)

This is what I'd do:

  • Add a "return;" on top of ready.php, init.php and maybe other files that you load on every request; 
  • Remove all modules (eg by renaming the /site/modules folder to /site/modules_tmp

The frontend will likely break if your modules are not available, but the backend should work. If your site works again, move over the modules 1-by-1 from modules_tmp to modules and see what happens.

Share this post


Link to post
Share on other sites

@bernhard OK you got me on a track here to finding this...thank you!

I was able to get logged into backend (with notifications telling me about modules that are not available) and finally found if I could do "Refresh" on the modules menu, then all the site comes back to work again!

So my question is....what does that Modules Refresh do? it refreshes the modules cache, but I'm wondering how I broke the modules cache to begin with?...

If I restored a backup of the database but didn't include the "caches" table, then that could cause all my modules to be "disabled" I'm thinking?

Share this post


Link to post
Share on other sites
1 hour ago, bernhard said:

Remove all modules (eg by renaming the /site/modules folder to /site/modules_tmp

Don't forget that Tracy's Module Disabler panel can quickly disable all autoload modules and includes a restore feature if those changes break things.

  • Like 2

Share this post


Link to post
Share on other sites
6 minutes ago, adrian said:

Don't forget that Tracy's Module Disabler panel can quickly disable all autoload modules and includes a restore feature if those changes break things.

It's impossible to know all features of Tracy 😉 Just getting used to the API Explorer. So useful!! Thx (over and over) again!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...