The problem is solved! namely this was occurring due to incompatibility between PHP 5.4.16-46.el7 and Magento 1.9.4.2.
Yes! their official document states this PHP version is supported. But certain segments of code in their Authorizenet core module are written in a coding structure that is not supported until PHP version 5.5 and above.
Section 1 below will illustrate said segments and how I overcame this.
So why were the errors not showing? (1)
The reason no errors were being displayed or logged in the magento logs was simple.
When the file(s) containing the incompatible segments of code is/are parsed, it will attempt to compile the code. But, when it reaches the incompatible segment it won't understand it and how to process this. Thus, causing a fatal error to be thrown, and in return caused the 500 internal server error.
As stated by interServer:
"The 500 Internal Server Error is the general catch all error when the
server throws an exception. ... Simply, the 500 Internal Server Error
is a general http status code that means something has gone wrong on
the website's server, but the server could not be more specific on
what that exact problem is."
This then prevented anything to be logged in magento.
As stated by media temple here:
...With any error message, particularly one as broad as the 500
Internal Server Error, you will first want to check any Apache and PHP
error logs for your server. These logs can provide valuable context
related to any code failures or other potential causes of a site
failure.
How did I overcome this? (2)
As we are all aware, the 1.9.4.2 is a minor update from 1.9.4.1. Where there are some small bug fixes and enhancements. I.e. Escaping HTML and introducing a new mailiciousFilter()
. No drastic changes, so this made me ask myself What possibly could have changed that caused this?
From here I formulated a simple plan of action:
- Using the fantastic tool DiffMerge, I compared two fresh untouched versions of Magento 1.9.4.2 and 1.9.4.1;
Then I traversed the list of changes, seeing what was exactly changed in the update. And, sequentially applying and testing each change. Whereby, I Backtracked until the culprit change was identified and scope for possible causes was made smaller;
Please Note: No changes were made on Production site at this point, and as per industry standard done in a like for like staging site.
From here, I was left with a very small scope for the cause. Namely, one perpetrating module: the AuthoriseNet Module, which as stated above, I do not use. But, it would still be parsed/compiled in magento when checking-out.
Analysing the changes in the module I was able to pinpoint that the following files:
- ../app/code/core/Mage/Authorizenet/Model/Directpost.php
- ../app/code/core/Mage/Authorizenet/Model/Directpost/Request.php
- ../app/code/core/Mage/Authorizenet/Model/Directpost/Response.php
All have one commonality, where they are passing the return of a function into the empty()
function. For example,
`$hashConfigKey = !empty($response->getData('x_SHA2_Hash')) ? 'signature_key' : 'trans_md5';`
This duly causing a parse error, since as stated above in the question update and on the php official documentation:
Prior to PHP 5.5, empty() only supports variables; anything else will
result in a parse error.
This left two options:
- Update the server to PHP 5.5 or above;
- And, amend the incompatible code.
Unfortunately, At this present moment in time Centos officially only supports 5.4. Thus, ruling out option 1. Yes! I am fully aware I could use another repository like the EPEL. But, unfortunately a decision has been made above myself to wait until Centos officially supports a newer version.
Luckily, magento is highly customisable and lends itself to overrides without even needing to create our own module.
Please Note! Never make changes to the core code. Instead make a local override and make changes there. Deepak Mishra (2014) has written a fantastic guide here, where he explains the simplest method to override core files in magento.
Following suite, I made a local override for the three afore bulleted files. And, amended them as guided by Magentary(2019):
--- app/code/core/Mage/Authorizenet/Model/Directpost.php
+++ app/code/local/Mage/Authorizenet/Model/Directpost.php
@@ -389,7 +389,8 @@
public function validateResponse()
{
$response = $this->getResponse();
- $hashConfigKey = !empty($response->getData('x_SHA2_Hash')) ? 'signature_key' : 'trans_md5';
+ $response_getData_hash = $response->getData('x_SHA2_Hash');
+ $hashConfigKey = !empty($response_getData_hash) ? 'signature_key' : 'trans_md5';
//hash check
if (!$this->getConfigData($hashConfigKey)
--- app/code/core/Mage/Authorizenet/Model/Directpost/Request.php
+++ app/code/local/Mage/Authorizenet/Model/Directpost/Request.php
@@ -187,7 +187,8 @@
{
$fpTimestamp = time();
- if (!empty($this->_getSignatureKey())) {
+ $this_getSignatureKey = $this->_getSignatureKey();
+ if (!empty($this_getSignatureKey)) {
$hash = $this->_generateSha2RequestSign(
$this->getXLogin(),
$this->_getSignatureKey(),
--- app/code/core/Mage/Authorizenet/Model/Directpost/Response.php
+++ app/code/local/Mage/Authorizenet/Model/Directpost/Response.php
@@ -56,14 +56,17 @@
*/
public function isValidHash($storedHash, $merchantApiLogin)
{
- if (empty($this->getData('x_amount'))) {
+ $this_getData_x_amount = $this->getData('x_amount');
+ if (empty($this_getData_x_amount)) {
$this->setData('x_amount', '0.00');
}
- if (!empty($this->getData('x_SHA2_Hash'))) {
+ $this_getData_x_SHA2_Hash = $this->getData('x_SHA2_Hash');
+ $this_getData_x_MD5_Hash = $this->getData('x_MD5_Hash');
+ if (!empty($this_getData_x_SHA2_Hash)) {
$hash = $this->generateSha2Hash($storedHash);
return $hash == $this->getData('x_SHA2_Hash');
- } elseif (!empty($this->getData('x_MD5_Hash'))) {
+ } elseif (!empty($this_getData_x_MD5_Hash)) {
$hash = $this->generateHash($storedHash, $merchantApiLogin, $this->getXAmount(), $this->getXTransId());
return $hash == $this->getData('x_MD5_Hash');
Now, upon clearing cache and other prerequisites of changes, the checkout is working again with no errors whatsoever. This is because magento instead of reading the core files with the incompatible segments, it will read from our local override where we have corrected the segments to be compatible with PHP 5.4.
php_value memory_limit 256M