Troubleshooting an issue that caused my WordPress site to not allow logins from the frontend

wordpress
wordpress

I have been adding plugins to my MultiSite WordPress site as well as adding new caching functionality to my server, initially, I did not notice any issues. It was only when I was adding a new site that is going to use Woocommerce I detected the problem, the issue was that I could not add any items to the shopping cart. While debugging I realized that there were other functionalities that did not work either as post preview, an admin-menu bar showing on frontend when logged in, a preview of theme in Appearance -> Customize.


I could log in to my WordPress site in the backend using the wp-admin link without any issues, while logged in and I viewed my site, the WordPress admin-menu was not showing anymore on the front-end, if the admin-menu do not show on the front-end I just tells you that you are not logged in, so I tried to log in from the frontend and that did not work either. I was thinking about what have I added that may cause this issue, so I started searching for the symptoms in the WordPress forums.

So I followed all the instructions outlined in the following article – http://codex.wordpress.org/Login_Trouble

  • Enable Cookies in my browser
  • Verify the DOMAIN_CURRENT_SITE value for my MultiSite Network
  • Disable Plugins
  • Deactivate Theme
  • Replaced the Login File
  • Edit Users Table
  • Resetting Password
  • Site URL Redirecting
  • Check Subdomains or Subdirectories on my MultiSite Network
  • Check Secure HTTPS
  • Headers Already Sent
  • Check URL Options
  • Check Firewall

After doing all that, I still had the same problem, by a coincidence I got on the right track. I had some planned database work, so I entered the URL for phpMyAdmin on my server, I logged in and got an error that said that I have an error with my session. My focus shifted towards the server, as not only WordPress had a problem, phpMyAdmin had a problem as well.

I tried to remember what I have done on the server in the last weeks, and luckily for me, I use my blog to add articles for any work that I do, browsing through the articles I narrowed it down to me memcached and Varnish to the server, so I took the steps to disable each service, and it turned out that the issue was with Varnish a miss configuration of the default.vcf config file.

Doing some searching, I came across this article on the WordPress forum – https://wordpress.org/support/topic/varnish-configuration-not-working-in-woocommerce?replies=9

and I added the following code to the Varnish default.vcf config file.

# Drop any cookies sent to WordPress.
sub vcl_recv {
        if (!(req.url ~ "(wp-login|wp-admin|cart|my-account|checkout|addons)")) {
                unset req.http.cookie;
        }
}
# Drop any cookies WordPress tries to send back to the client.
sub vcl_fetch {
        if (!(req.url ~ "(wp-login|wp-admin|cart|my-account|checkout|addons)")) {
                unset beresp.http.set-cookie;
        }
}

It resolved the issue I had with the Woocommerce shopping cart, I did not resolve the issue of the admin-menu bar, for now, this is good enough. I have a functional shopping cart, which gives me time to figure out how to get the admin-menu bar back by configuring the right values in the Varnish default.vcf config file.

Recommended reading about WordPress with Varnish https://www.varnish-cache.org/trac/wiki/VarnishAndWordpress

Conclusion

I started in the wrong end of troubleshooting the issue, I should have started with the server and worked my way towards the applications, I learned that next time I will start from the server end of things, will save me some time actually.

Leave a reply:

Your email address will not be published.