Author: Sam

Listing sizes in AWS S3 Buckets

Getting the whole bucket size

aws s3 ls s3://$BUCKETNAME/ --recursive --human-readable --summarize | tail -n2

Tail is used because otherwise all files will be printed on screen (but you may want that for some reason).

Getting the size of a specific directory/file

You just need to add the path to the bucket name:

aws s3 ls s3://$BUCKETNAME/some/dir --recursive --human-readable --summarize | tail -n2

Getting the size of all subdirs

If you imagine there is something like ncdu or du -ha -d 1 /foo/bar you’re wrong. If you want to get the size of all subdirs you have to do it yourself:

Your Bucket contains in $BUCKETNAME/some/dir multiple subdirs (for e.g. 2020, 2019 and 2018) and you want to see the size of these 3 directories.

S3PATH='s3://$BUCKETNAME/some/dir/'
for dir in $(aws s3 ls "${S3PATH}" | grep PRE | awk '{print $2}'); do 
    echo "${S3PATH}${dir}:"
    aws s3 ls "${S3PATH}${dir}" --recursive \
                                --human-readable \
                                --summarize\
    | tail -n2
done

A | column after done could improve the readability.

Send A Test Mail via Exim Command line

Sending a test mail from a server with a configured exim is easy as pie.

From your user shell:

  1. tell exim that we want to send a mail to an recipient and tell us about the details of the sending procedure
    $ exim -v receipient@foo.bar
    
  2. Tell exim about the sender, the subject and input some text.
    From: user@your.domain.example
    Subject: Foobar
    Text Text Text
    
    I like Pie!
    
  3. Press Ctrl+d
  4. You should see the details about the SMTP connection. You can return to your shell with Ctrl+c

This guide will show you how to extend or resize an ext2/3/4 and XFS File System without LVM at runtime. This could be a root partition configured with ext2/3/4 or XFS filesystem but without any LVM configured.

Step 1: Check your current root disk capacity

For this demonstration, I have a CentOS 7 VM with below partition scheme.

$ lsblk 
 NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 sr0     11:0    1 1024M  0 rom  
 vda    253:0    0   10G  0 disk 
 └─vda1 253:1    0   10G  0 part /

As seen from the output, the root filesystem is on /dev/vda1 partition without LVM.

Step 2: Extend your OS root disk

I will extend my root block device to 30GB. I use KVM virtualization technology, so this guide works for me:

For KVM I can check virtual disk path using the command below:

$ sudo virsh domblklist centos7 
 Target   Source
-------------------------------------------------
 vda      /var/lib/libvirt/images/centos7.qcow2
 sda      -

$ sudo fdisk -l /var/lib/libvirt/images/centos7.qcow2
Disk : 10 GiB, 10739318784 bytes, 20975232 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

$ sudo qemu-img resize /var/lib/libvirt/images/centos7.qcow2 +20G
Image resized.

If you’re on a different Virtualization platform, refer to its documentation for how to extend OS virtual disk.

Step 3: Grow VM partition

Start your VM and ssh as a user with sudo privileges. The first thing to do is to confirm the new disk size.

$ lsblk 
 NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 sr0     11:0    1 1024M  0 rom  
 vda    253:0    0   30G  0 disk 
 └─vda1 253:1    0   10G  0 part /

We can see the disk has grown by 20GB, from 10GB to 30GB. The next action is to expand the partition (Partition 1) in our example, to the maximum size the disk provides.

Install cloud utils package

For those new to growpart, it is a Linux command line tool used to extend a partition in a partition table to fill available space. This command is provided by cloud utils package.

On Ubuntu / Debian system, run:

sudo apt -y install cloud-guest-utils gdisk

For CentOS / RHEL / Fedora server, run:

sudo yum -y install cloud-utils-growpart gdisk

Help page can be viewed by passing -h argument

# growpart -h
growpart disk partition
   rewrite partition table so that partition takes up all the space it can
   options:
    -h | --help       print Usage and exit
         --fudge F    if part could be resized, but change would be
                      less than 'F' bytes, do not resize (default: 1048576)
    -N | --dry-run    only report what would be done, show new 'sfdisk -d'
    -v | --verbose    increase verbosity / debug
    -u | --update  R update the the kernel partition table info after growing
                      this requires kernel support and 'partx --update'
                      R is one of:
                       - 'auto'  : [default] update partition if possible
                       - 'force' : try despite sanity checks (fail on failure)
                       - 'off'   : do not attempt
                       - 'on'    : fail if sanity checks indicate no support

   Example:
    - growpart /dev/sda 1
      Resize partition 1 on /dev/sd

Now use growpart to extend your partition.

$ sudo growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=20969472 end=20971520 new: size=62912479,end=62914527

This will resize partition 1 on /dev/vda.

Validate the change.

$ lsblk 
 NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 sr0     11:0    1 1024M  0 rom  
 vda    253:0    0   30G  0 disk 
 └─vda1 253:1    0   30G  0 part /

Step 4: Resize ‘/’ partition to fill all space

The last step is to resize the file system to grow all the way to fill added space

For ext4 file system, use resize2fs

$ sudo resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
 Filesystem at /dev/vda1 is mounted on /; on-line resizing required
 old_desc_blocks = 2, new_desc_blocks = 4
 The filesystem on /dev/vda1 is now 7864059 blocks long.

If your filesystem is XFS, it can be grown while mounted using the xfs_growfs command:

sudo xfs_growfs /

Confirm new size using df -h

$ df -hT | grep /dev/vda
/dev/vda1      ext4       30G  1.2G   27G   5% /

Congratulations!, you have successfully resized an ext2/3/4 or XFS root partition on Linux without LVM.

Go to system/startup.php and find following lines of code:

if (!ini_get('date.timezone')) {
	date_default_timezone_set('UTC');
}

Replace with following lines of code by changing to your timezone

date_default_timezone_set('Australia/Sydney');

Synchronize PHP and Database Timezone

The query we use to set database timezone if you are super admin is below:

SET time_zone='offset';

But everyone has no super admin access so need to change in the code level. For that go to system/library/db/mysqli.php if you are using MySQLi and add code below after $this->connection->query(“SET SQL_MODE = ””);

$dt = new \DateTime();
$this->connection->query("SET time_zone='" . $dt->format('P') . "';");

With these changes your timezone in Opencart are changed.

Let us know if you find any issues, thanks a lot.

OpenCart is one of the simplest e-commerce platforms to build an online store. OpenCart offers you an ‘easy-to-work-with’ code-base with which you can get an e-Commerce site online, quickly. If you are looking for a safe way to move OpenCart website from one domain to another, follow the process below.

Here are the steps to migrate / move OpenCart website to a new server.

1. Download ALL the files from old server.
2. Create a backup of Database through PhpMyAdmin
3. Upload files to NEW SERVER
4. Install Database on NEW SERVER through PhpMyAdmin
5. Update the configuration files config.php and admin/config.php to reflect your new domain path.

The file should now open up for editing. Here, you will need to edit a few lines of code. Find the lines:

// HTTP

define('HTTP_SERVER', 'http://yourdomain.com/');

// HTTPS

define('HTTPS_SERVER', 'http://yourdomain.com/');

// DIR

define('DIR_APPLICATION','/
home/sites/YOUR-DOMAIN/public_html/catalog/');
define('DIR_SYSTEM','/home/sites/YOUR-DOMAIN/public_html/system/');
define('DIR_DATABASE','/home/sites/YOUR-DOMAIN/public_html/system/database/');
define('DIR_LANGUAGE','/home/sites/YOUR-DOMAIN/public_html/catalog/language/');
define('DIR_TEMPLATE','/home/sites/YOUR-DOMAIN/public_html/catalog/view/theme/');
define('DIR_CONFIG','/home/sites/YOUR-DOMAIN/public_html/system/config/');
define('DIR_IMAGE','/home/sites/YOUR-DOMAIN/public_html/image/');
define('DIR_CACHE','/home/sites/YOUR-DOMAIN/public_html/system/cache/');
define('DIR_DOWNLOAD','/home/sites/YOUR-DOMAIN/public_html/download/');
define('DIR_LOGS','/home/sites/YOUR-DOMAIN/public_html/system/logs/');

You will need to update these to your correct path. Contact your hosting company for the full path to your public folder.

Next, you need to update the database connection settings. Find the code below:

// DB

define('DB_DRIVER','mysql');
define('DB_HOSTNAME','localhost');
define('DB_USERNAME','your-old-opencart-databse-username');
define('DB_PASSWORD','your-old-opencart-databse-password');
define('DB_DATABASE','your-old-opencart-databse-database');
define('DB_PREFIX','oc_');

You will need to replace these with the new details made in step 3;

DB_HOSTNAME = Your database host (usually localhost).
DB_USERNAME = Your Database username.
DB_PASSWORD = Your Database password
DB_DATABASE = Your database name

Once you have updated these, save the changes & you are done.

Method-1: First Check the Timezone in Settings > Store. Make sure you set to UTC.

If you need to change it back you can in the SQL table “oc_setting” column “key” value “config_timezone” in the “value” column change it back to “UTC”

UPDATE oc_setting SET value='UTC' WHERE key = 'config_timezone';

If still issue, follow below method.

Method-2: You need to set your php time and mysql time the same. its deleting cookies to soon. You can fix this.

Open:

system/config/default.php
system/config/catralog.php
system/config/admin.php

Find:

$_[‘session_engine’] = ‘db’;

Replace:

$_[‘session_engine’] = ‘file’;

 

 

Step-1: Add 2 hidden fields to the contact form

[hidden your-first-name id:first-name-p]
[hidden your-last-name id:last-name-p]

Step-2: Write below jquery script in the footer

$("#name_field_id").focusout(function(){
     str = $(this).val();
     if(str){
      s = str.split(/(?<=^\S+)\s/); //split string in name field after first space found. 
      $("#last-name-p").val(s[1]); //s[1] value after the first space set to hidden field.
     }
  });

Output will be list this:-

ERROR:-
The response from the remote server was:
550 Please turn on SMTP Authentication in your mail client. mail-qk1-f172.google.com [209.85.222.172]:36503 is not permitted to relay through this server without authentication.

SOLUTION:-

Manage SMTP restrictions

Click Enable to deny users the ability to bypass your mail server to send mail. To allow users the ability to bypass your mail server, click Disable.

(WHM >> Home >> Security Center >> SMTP Restrictions)