Wednesday, February 5, 2020

Apache Mixed Content Error

Mixed Content is the most common issue in an apache website. The perfect solution is, you need to find all urls and replace http with https but it may be time consuming and most probably this solution is at developer's end.
If you want to fix it at apache's end, here is the solution. Atleast you should give a try.

First enable module headers in apache

sudo a2enmod headers
sudo service apache2 reload

Now add the line in virtualhost, your 443 port virtualhost where you have defined ssl keys. People add it in 80 port virtual host and complains it does not work.
Header always set Content-Security-Policy "upgrade-insecure-requests;
If you do not have virtualhost access, add the line in .htaccess
Header always set Content-Security-Policy "upgrade-insecure-requests;
Now check the urls in updated version of firefox / chrome / your browser.

If you get internal server error, it means header module is not enabled.

Magento bccomp Error

[Fri Jan 17 11:51:13.302280 2020] [php7:error] [pid 2430] [client 172.17.0.1:44334] PHP Fatal error:  Uncaught Error: Call to undefined function Magento\\InventorySales\\Model\\IsProductSalableForRequestedQtyCondition\\bccomp() in vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition/IsSalableWithReservationsCondition.php

Solution :

Install php bcmath package and restart apache.
sudo apt-get install php-bcmath
The solution is for apache installed on Ubuntu. If you have installed php using different command like sudo apt-get install php7.0 or sudo apt-get install php7.2 or sudo apt-get install php5.6, you need to install the package using similar method i.e. sudo apt-get install php7.0-bcmath or sudo apt-get install php7.2-bcmath or sudo apt-get install php5.6-bcmath etc.

Mongodb - Import JS file

Importing database file in mongdb can be a headache if you haven't done it before. The most common way of exporting and importing database using commands mongodump and mongorestore. But what if you have js file to import.
Here is the way to import js file in mongo database.

Solution :

mongo 127.0.0.1/dbname exportedjsfilename.js