Scripts

Install composer 1.10 using php composer

Copy and paste this in terminal and hit enter. Composer version 1.10.23 will be installed in local directory. you can use it as php composer.phar install

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --version=1.10.23
php -r "unlink('composer-setup.php');"

Install composer 1.10 using php composer Read More »

Magento 2 backup script for developer

Magento 2 developer usually require taking backup of live environment and setup on local or creating staging environment. We need to take backup of Database, App folder and composer.json minimal. We can add media and other assets for full fledged setup. I created a simple script to create backup of these two folder after reading env.php file. It will decrease time to take backup. We just need to put these script at root and run it. It is very flexible and you can make changes to your requirement as well. I will keep updating it and will add new features.

<?php 
//create backup file
$envData = include('app/etc/env.php');

//taking database backup
echo "Taking database backup \n";
if(isset($envData['db'])){
    $mysqlDump = 'mysqldump --user='.$envData['db']['connection']['default']['username'].' --password='.$envData['db']['connection']['default']['password'].' --host='.$envData['db']['connection']['default']['host'] .' '.$envData['db']['connection']['default']['dbname'] .' > db.sql;'; 
    exec($mysqlDump);
}

//zipping files
echo "Zipping required files to setup environment \n";
exec('zip -r files.zip db.sql composer.json app/');

die('finished');
?>

Magento 2 backup script for developer Read More »