S3 notes – how to make all s3 images public


aws configure --profile myproject
// to test if it works or not

aws s3 ls --profile myproject

aws s3 cp \
      --exclude "*" \
      --include "*.jpeg" \
      --content-type="image/jpeg"  \
      --metadata-directive="REPLACE" \
      --recursive \
	  --acl public-read \
       s3://myproject/ \
       s3://myproject/ \
	   --dryrun --profile myproject
aws s3 cp \
      --exclude "*" \
      --include "*.jpg" \
      --content-type="image/jpeg"  \
      --metadata-directive="REPLACE" \
      --recursive \
	  --acl public-read \
       s3://myproject/ \
       s3://myproject/ \
	   --dryrun --profile myproject
aws s3 cp \
      --exclude "*" \
      --include "*.jpeg" \
      --content-type="image/jpeg"  \
      --metadata-directive="REPLACE" \
      --recursive \
	  --acl public-read \
       s3://myproject/ \
       s3://myproject/ \
	   --dryrun --profile myproject
// not needed 
aws s3 sync . s3://my-bucket/path --acl public-read
	   

Dont forget to remove dryrun flag once you are sure.

How to fix Magento2 apis not working? fix coupon apis and other PUT OPTIONS APIs

The issue is actually related to your server’s configuration. By default all types of requests are not allowed. Please add the following to your .htaccess file

<Limit GET POST OPTIONS PUT DELETE PROPFIND>
    Order allow,deny
    Allow from all
    Require all granted
</Limit>

CSS Flashy button with glaze effect


.flashybtn
{
    display: block;
    text-align: center!important;
    text-decoration: none!important;
    font-weight: 800!important;
    font-size: 1.5em;
    text-transform: uppercase!important;
    color: #fff!important;
    padding: 1em 0.1em 1em 0.1em!important;
    background-size: 200% auto!important;
    box-shadow: 0 4px 6px rgba(50,50,93,.11),0 1px 3px rgba(0,0,0,.08)!important;
    background-image: linear-gradient(to right,#ff473d 0%,#ff379d 50%,#f13790 100%)!important;
    animation: gradient 1.5s ease infinite!important;
    width: 100%;
    position: relative; //change to fixed to make it sticky
    bottom: 0;
    left:0;
    z-index: 9999;
	}
.flashybtn:before {
    content: "";
    display: inline-block;
    position: absolute;
    background: rgb(255,255,255);
    width: 30px;
    height: 2em;
    left: 0;
    bottom: 0;
    filter: blur(1.5em);
    animation: 2s glaze infinite;
}
@keyframes glaze{
    from{
        transform: translateX(0) skewX(-15deg);
        opacity:1;
        }
    to {
        transform: translateX(100vw) skewX(-15deg);
        opacity:1;
       }
}

I am FLASHY

How to put a site in maintenance? [Apache web server]

ErrorDocument 403 /index.html
DirectoryIndex index.html
<Files ~ "index\.html">
	Order Allow,Deny
	Allow from all
</Files>
Deny from all

Content of your .htaccess file

If you want to whitelist any IP, use this

ErrorDocument 403 /index.html
DirectoryIndex index.html
<Files ~ "index\.html">
	Order Allow,Deny
	Allow from all
</Files>
Order Allow,Deny
Allow from xx.xxx.xx.xx
Deny from all

Here is a sample htaccess for a wordpress website with 1 IP whitelisted 4.129.45.44 and all others are banned. So you only will be able to load the website while everyone else will see contents of index.html with HTTP Status code 403

ErrorDocument 403 /index.html
DirectoryIndex index.php
<Files ~ "index\.html">
    Order Allow,Deny
    Allow from all
</Files>
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^4\.129\.45\.44$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REMOTE_ADDR} !^4\.129\.45\.44$
RewriteRule . /index.php [L]

Allow from 4.129.45.44
Deny from all

How to generate a patch with edited files? How to zip latest committed changes only

zip archive.zip $(git diff-tree --no-commit-id --name-only -r latest-commit-id)

Reference: https://stackoverflow.com/a/42971972/2229148

sometimes you need all the files that were updated so you can patch an external app which doesnt uses same git project or many other scenarios in which we need a zip or tar of those files. Use the above command to do so

There is a smarter way also, if you want all the changes from last 5 commits, use the command like this:

zip archive.zip $(git diff-tree --no-commit-id --name-only -r HEAD~5 HEAD)

Basic Authentication in nginx for any domain, server or location block

sudo yum install httpd-tools
sudo htpasswd -c /etc/nginx/conf.d/vhosts/.htpasswd USERNAME
Enter Password: xxxxx
sudo chmod 644 /etc/nginx/conf.d/vhosts/.htpasswd

Update the domain.conf file like /etc/nginx/conf.d/vhosts/myrestricteddomain.com.ssl.conf

Ideally, use it in server config

server {
satisfy all; 
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/conf.d/vhosts/.htpasswd; 
	location / {

Save and restart nginx

How to fix Invalid template file error in Magento2 after version upgrade?

This is a very common issue you will face if you using windows machine for development.

Usual error message is:

Invalid template file: '/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'

So whats the solution?

In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php

protected function isPathInDirectories($path, $directories)
{
    $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }

    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

Reference:

https://magento.stackexchange.com/a/255585/32283

How to update customer password in Magento 2 database?

UPDATE `customer_entity`
SET `password_hash` = CONCAT(SHA2('SaltPASSWORD', 256), ':SALT:1')
WHERE `entity_id` = 7615;

Please note that if SPJ9WIp7 is the salt and User’s password is 7qLzX33ETxYE, the following will be your query:

UPDATE `customer_entity`
SET `password_hash` = CONCAT(SHA2('SPJ9WIp77qLzX33ETxYE', 256), ':SPJ9WIp7:1')
WHERE `entity_id` = 7615;

7615 is the customer id