Author: Shiva Charan Devabhaktuni

  • Adding an SSL certificate to EC2

    Buy Certificates

    Buy your SSL certificate from a provider. I got mine from namecheap.
    Transfer your SSL certificate bundle files onto your server, for example into /ssl/ folder. (more…)

  • Optimize your website in 5 minutes

    Getting a good score in Google Pagespeed Insights is very important, as it is a main factor for good User Experience (UX).

    Minify Js, HTML & CSS

    Minifying the Javascript, HTML and CSS helps reduce the page load times drastically.

    Optimize Images

    Optimize your images before hosting them online and using them on your site. You can optimize images online for free here. (more…)

  • Monitor EC2 using crontab

    If you want to monitor your Amazon Web Services (AWS) Elastic Cloud Compute (EC2) instances using crontab and AWS SDK. Here in this example I have chosen php (7.1).

    Install AWS SDK

    Install composer

    composer require aws/aws-sdk-php

    (more…)

  • Monitor services (Apache, MySQL, HHVM) using crontab

    Want to ensure that your services (Apache, MySQL, HHVM) on your linux instance are running 24*7? Then you can use crontab for that. This job runs every minute to check the status of the service and if it is not running then, it starts the service. (more…)

  • Redirect users based on the HTTP Request Header – Node.js

    For this example it is recommended that you have the latest most stable release of Node.js + npm installed.
    Now you will need express to run a simple server. (more…)

  • Create an Observable the right way – Angular 5

    Using a subject to create an observable is the recommended method of inter-component communication by the official angular documentation.
    The following code was tested with Angular 5.2.2. (more…)

  • Add Google Analytics to WordPress in 2 minutes

    The following is the fastest way to integrate Google Analytics with your self hosted WordPress website without using any external applications or plugins. By injecting plain javascript into your tag, you won’t have to worry about incurring the overhead of adding a new plugin to your site for a small 2 line code addition. (more…)

  • Delete shell history

    You can login as the user you want to delete history from and then use the following command. For example if you want to delete from root

    sudo -i
    cat /dev/null > ~/.bash_history && history -c && exit
    
  • Automate total backups using crontab

    sudo crontab -e
    

    The following cronjobs will run every hour. Make sure you replace the database connection string values (make sure you have the right privileges on the database being used.) and backup folder paths with the appropriate ones.

    0 * * * * cd /cron/backup && tar -zcvf backup.tar.gz /var/www/html/
    0 * * * *  mysqldump -u user_name -p'password' db_name> /cron/backup/backup.sql
    

    Now save the changes and restart the cron service.

    Ctrl+O
    Enter
    Ctrl+X
    sudo service cron restart
    
  • Optimize all the tables in your database using cronjobs

    This php script repairs and optimizes all the tables in the selected database. Make sure you provide the right values in the connection string.

    Script

    optimize.php

     $tablename)
       {
           if(mysqli_query($link,"REPAIR TABLE `$tablename`")) 
               { 
               echo '\nRepair Success: '.$tablename;
                }
           else 
             die(mysqli_error($link));
           if(mysqli_query($link,"OPTIMIZE TABLE `$tablename`")) 
              { 
               echo '\nOptmize Success: '.$tablename;
              }
           else
              die(mysqli_error($link));
       }
    }
    
    mysqli_close($link);
    
    

    Cronjob

    crontab -e
    0 * * * * php /var/www/html/optimize.php
    Ctrl+O
    Enter
    Ctrl+X
    sudo service cron restart