Tuesday, June 25, 2019

Fixing 500 internal server error in Magento 2

Hello

Many times we are facing issues with 500 error code. There are many possible ways to come for it.  Here I display some solution for it. I hope it will help you to come out.

500 internal server error is a common one in hosting environment. It causes hiding actual PHP error then tells you contact admin system to report the real error. You can see this error when updating, installing, and removing components or after backup, etc.

This tutorial will show you solutions for fixing 500 error in Magento 2.
At first, you need to enable Developer mode, which allows you to debug Magento to see detail exceptions on error page instead of showing 500 internal server error.

First to enable Developer mode in Magento 2:

Open ssh client and add command:

Php bin/magento deploy:mode:set developer

Now you can see the error. Let’s start fixing it!


There are 4 ways for you to fix 500 internal server errors in Magento 2.

1: Change file permission
500 internal server errors appears when logging to admin panel, so to solve it, you need to change permission of index.php file in root from 664 to 644.

Additionally, another index.php file in downloader/index.php should be changed permission to 644 to avoid error when navigating to System> Magento Connect> Magento Connect Manager.

2 : Increase php_value memory_limit
If seeing 500 errors in specific pages like checkout page or product page, it means your server lacks of resource for running Magento. So you need to expand memory for your server.

For htaccess file:
Add lines below:
<IfModule mod_php5.c>
Php_value memory_limit 256M
</IfModule>

For ini file:
Add following line and change it:
memory_limit = 256M
3 : Rename/remove .htaccess file
Wrong settings in .htaccess file can cause error. In this case, you should try renaming/removing .htaccess file.

4 : Disable maintenance mode
The maintenance mode may cause changing file permission of index.php to 666 and make it appear error as web browsers is able to execute.

Do as follows to disable maintenance mode:

  • Remove var/.maintenance.flag file
  • Change php permission to 755
  • Clear cache


That’s all solution for fixing 500 internal server error in Magento 2. Hopefully all of you can perform.

Friday, June 21, 2019

Add Water Mark to Image in PHP

Hello

Today i saw you how to add watermark image to your image  with small and simple php script. If you have image based website than it is possible that someone copied your images and misuse it. So avoid to this, i suggest to implement this. Using PHP GD library you can do any type of image merging and image alteration. It is very useful library so we’ll use this library to add simple water mark/logo of your company on image dynamically using PHP GD library.


$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');

$stamp is your watermark png file. $im is your actual jpg image file.

$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

Set the margins for the stamp and get the height/width of the stamp image


imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

Copy the stamp image onto our photo using the margin offsets and the photo width to calculate positioning of the stamp.

Using header content type generate the final output :-
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);

addWatermark() : using below function and pass your watermark and actual image path to generate image with water mark.
function addWatrmark($image, $waterMark) {
$stamp = imagecreatefrompng($waterMark);
$im = imagecreatefromjpeg($image);

$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);


Call the above function:-
 addWatrmark('photo.jpeg', 'stamp.png')
                   or
 addWatrmark($im, $stamp)

Run jQuery in phtml file

Hello

Here I saw you how to run jQuery in phtml file.

<script type="text/javascript">
//<![CDATA[
 require([
    'jquery'
], function($) {
 
    setTimeout(function() {
        $( "#iwd_opc_shipping_method" ).append( "<div class='iwd_opc_section_delimiter'></div>" );
        $( "#iwd_opc_discount" ).insertAfter( "#onepage-checkout-shipping-method-additional-load" )
      }, 2500);
     
      //$( "#iwd_opc_discount" ).insertAfter( "#onepage-checkout-shipping-method-additional-load" )
   }
 );
//]]>
</script>

**********************************************************************

<script type="text/javascript">
//<![CDATA[
 require([
    'jquery',
    'Magento_Ui/js/modal/alert'
], function($, alert) {
   $('#id-of-element').on('click', function(event){
        alert({
           content: $(event.target).parent().val()
        })
      })
   }
 );
//]]> 
</script>

****************************************************************

<script type="text/javascript">
//<![CDATA[
require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal'
    ],
    function(
        $,
        modal
    )
    {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: true,
            title: 'Qty Estimator',
            buttons: [{
                text: $.mage.__('Continue'),
                class: '',
                click: function () {
                    this.closeModal();
                }
            }]
        };

        var popup = modal(options, $('#popup-modal'));
        $("#click-me").on('click',function(){
            $("#popup-modal").modal("openModal");
        });

$('#rate, #box').keyup(function(){
var rate = parseFloat($('#rate').val());
var box = parseFloat($('#box').val());

$('#amount').val(rate * box);
var amount = rate * box;

if(amount != null || amount != undefined) {
  $('#amount2').val(amount / 20);
 }
 });
    }
  );

//]]>
</script>

Thursday, June 13, 2019

make magento faster

Hello

Use these settings to make magento more faster.

1. Disable Signed content (Don't need for developer mode)

insert into core_config_data (scope, scope_id, path, value) values ('default',0, 'dev/static/sign', 0);


2. Make sure you have used SSD for store Magento 2 Source Code.

3. Make sure you have used the latest MySQL version.

4. You are developing, please enable developer mode and doing step 1.

5. If your site got too many products, please run php bin/magento catalog:image:resize

6. The suggestion is Use Redis cache and saves the session to DB or Redis

These will help you to make fast magento website. 


Thursday, June 6, 2019

Be careful while display show/hide editor in magento 2

Hello.

Please be careful while click on show/hide editor in any page. It removes javascripts from that code.
Now you click on show editor, it looks like this :-

When you once again click it, JavaScript will be removed from your code. See this :-

How to set HTML Auto Indent format on Sublime Text 3?

Hello

To auto indent on Sublime text 3 with a key bind try going to
Preferences > Key Bindings - users

And adding this code between the square brackets

{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}

 it sets shift + alt + f to be your full page auto indent.


Wednesday, June 5, 2019

Magento 2 Useful Commands List

Hello

Here I display some useful commands for magento 2.

If magento website is not loading properly and admin is not open and display as 404 error, Use these commands:-

chmod -R 777 /var/www/html/MAGENTO_2_ROOT_DIRECTORY/

sudo a2enmod rewrite

sudo service apache2 restart

Install php 7, use this command :-
sudo apt-get install php7.1 libapache2-mod-php7.1 php7.1-mbstring php7.1-mysql php7.1-mcrypt php7.1-xsl php-imagick php7.1-gd php7.1-cli php-pear php7.1-intl php7.1-curl php7.1-zip php7.1-gd php7.1-soap php7.1-xml -y
sudo service apache2 restart


Setup Upgrade Using Command Line
php bin/magento setup:upgrade

If you don’t want to remove pub/static files while installing/updating database then use following command.
php bin/magento setup:upgrade --keep-generated

Cache Clean Using Command Line
php bin/magento cache:clean

Cache Flush Using Command Line
php bin/magento cache:flush

View cache status Using Command Line
php bin/magento cache:status

Enable Cache Using Command Line
php bin/magento cache:enable [cache_type]

Disable Cache Using Command Line
php bin/magento cache:disable [cache_type]

Static Content Deploy Using Command Line (Use -f for force deploy on 2.2.x or later)
php bin/magento setup:static-content:deploy

Static Content Deploy For Particular Language Using Command Line
php bin/magento setup:static-content:deploy en_US

Static Content Deploy For Magento Backend Theme Using Command Line (Working on 2.1.1 or later)
php bin/magento setup:static-content:deploy --theme="Magento/backend"

Static Content Deploy For Specific Themes Using Command Line (Working on 2.1.1 or later)
php bin/magento setup:static-content:deploy --theme Magento/luma --theme Magento/second_theme

Exclude Themes on Static Content Deploy and does not minify HTML files Using Command Line (Working on 2.1.1 or later)
php bin/magento setup:static-content:deploy en_US --exclude-theme Magento/luma --no-html-minify


Reindexing Using Command Line
php bin/magento indexer:reindex


View the list of indexers Using Command Line
php bin/magento indexer:info

View indexer status Using Command Line
php bin/magento indexer:status

Show the mode of all indexers Using Command Line
php bin/magento indexer:show-mode

See all modules Status Using Command Line
php bin/magento module:status

Enable module Using Command Line
php bin/magento module:enable Namespace_Module

Disable module Using Command Line
php bin/magento module:disable Namespace_Module

Uninstall Module Using Command Line
php bin/magento module:uninstall Namespace_Module

Check Current Mode Using Command Line
php bin/magento deploy:mode:show

Change To Developer Mode Using Command Line
php bin/magento deploy:mode:set developer

Change To Production Mode Using Command Line
php bin/magento deploy:mode:set production

Run the single-tenant Compiler Using Command Line
php bin/magento setup:di:compile

Unlock Admin User Using Command Line
php bin/magento admin:user:unlock adminusername

Enable Maintenance Mode Using Command Line
php bin/magento maintenance:enable

To enable maintenance mode for all clients except 192.0.0.1 and 192.0.0.2:
php bin/magento maintenance:enable --ip=192.0.0.1 --ip=192.0.0.2

To clear the list of IPs.
php bin/magento maintenance:enable --ip=none

Disable Maintenance Mode Using Command Line
php bin/magento maintenance:disable

Check Maintenance Mode Status Using Command Line
php bin/magento maintenance:status

Allow IP on Maintenance Mode Using Command Line
php bin/magento maintenance:allow-ips --ip=192.0.0.1 --ip=192.0.0.2

Set Magento crontab Using Command Line
php bin/magento cron:install --force

Use --force to rewrite an existing Magento crontab.
To view the crontab, enter the following command as the Magento file system owner.
crontab -l

Remove Magento crontab Using Command Line
php bin/magento cron:remove

It will be updated when I get new commands.