Drush
more_horiz
close

on 20th July 2017 / by sarika.k
Drush is a command-line shell for Drupal which enables you to perform many website maintenance tasks and administrative tasks from the terminal instead of using the Drupal administrative interface. Drush aliases allow you to run drush commands on your local server but actually the command executes on a remote server. This is a real time saver while working locally and you want to do something on the remote server. Steps for downloading Drush aliases Sign in to the Acquia Cloud, using your email id and password. Click your name in the upper left corner, then click View profile. Click Credentials from the Profile page. Under Drush integration, click Download Drush aliases. Extract the downloaded archive file into $HOME:$ tar -C $HOME -xf $HOME/Downloads/sitename.tar.gz Setting up your local environment Your local computer needs a little configuration settings to use an alias. Alias configuration files go into a .drush folder in your home directory or in the sites/all/drush directory of the site. Putting them in the .drush in your home directory means they will be accessible from anywhere. You can add multiple alias files here with the naming convention: sitename.aliases.drushrc.phpEach file can contain any number of alias descriptions. Descriptions are added as multiple entries in a multi dimensional array, the key of which is the subitem for that alias. An example for an alias file called sitename.aliases.drushrc.php with one dev entry is like this, $aliases['dev'] = array( 'parent' => '@parent', 'site' => 'sitename', 'env' => 'dev', 'root' => '/var/www/html/sitename.dev/docroot', 'remote-host' => 'example.myserver.com', 'remote-user' => 'sitename', );gives one alias which is accessed via the @sitename.dev drush argument. For example, drush @sitename.dev status Some tips for Drush Aliases usage The powerful tasks that you can automate with drush aliases includes, Sync the database from the staging environment to local environment:drush sql-sync @sitename.stage @sitename.dev Sync the files directory from production environment to development:drush sql-sync @sitename.prod @sitename.dev Backup your entire production install (files & database):drush archive-dump @sitename.prod --destination=example.tgz Restore the backup to your development environment:drush archive-restore example.tgz Sync the sites/default directory on production environment to development environment using the created path-alias:drush rsync @sitename.prod:%default @sitename.dev:%files Clear cache on the remote staging environment from development:drush @sitename.stage cc all Drush Drush Aliases Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 05th December 2016 / by deepak.r
Everyone knows Drush is a very important tool in Drupal development, to execute things faster and to manage Drupal websites remotely. Drupal specifically built its shell function to update its configurations, managing modules, running drupal updates, etc. For Drupal 8 older versions of Drush will not work as part of changes that Drupal 8 put forward. If you want to setup the latest version of Drush, you can follow these steps to ensure that latest version of Drush has been installed and which is compatible for Drupal 8. Else, you can update Drush using composer. Open a terminal window and type: cd ~/ Download the latest version of Drush: php -r "readfile('http://files.drush.org/drush.phar');" > drush Make the newly downloaded version executable: sudo chmod +x ~/drush Depending on the setup, You may need to find current install path of Drush by typing: which drush It will return something like '/usr/bin/local', which can be different depending on the package manager in the system Create a backup for current Drush installation: sudo cp /yourpath/to/install/drush /yourpath/to/install/drush_older Delete the older version from your install path ('/usr/bin/local'): sudo rm /yourpath/to/install/drush Move the newly downloaded version to the install path: sudo mv ~/drush /yourpath/to/install/drush Initialize the newest version of Drush: /yourpath/to/install/drush init Navigate to the Drupal 8 root in terminal and simply type 'drush'. If everything is fine, a list of commands will be available for you. By following this, you can ensure that Drush has been updated to the latest version, preserving the older copy of installation, which can be used to switch between Drush versions later. Hope this helps! Drupal Drupal 8 Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 25th January 2016 / by abhai.sasidharan
This article is about a few drush commands as well as Linux commands that helped ease my work at times while working on remote servers. Mostly while updating or upgrading. The need for bulk operations in drush is often never met except using complex Linux commands often involving 'sed'. Operations like disable all non-core modules, enable the disabled modules from a list, create a list of all core and non-core modules in use and so on. Before updating or upgrading any site, you must always document all the extensions in the site. The pml command is quite useful to list extensions as shown below. //Lists all non core enabled modules drush pml --no-core --type=module --status=enabled //Lists all enabled core modules drush pml --core --type=module --status=enabled //Lists all disabled non core modules drush pml --no-core --type=module --status=disabled //List all disabled core modules drush pml --core --type=module --status=disabled // List all themes drush pml --type=theme // List modules with available updates. --core --no-core can be specified here as well. drush pm-updatestatusThese same commands can be combined with some useful Linux commands to document the outputs into text files. This will write the module's machine name into the txt file. For more details run "man cat" on your terminal. drush pml --no-core --type=module --status=enabled --pipe | cat > enabled_noncore_modules.txt drush pml --core --type=module --status=enabled --pipe | cat > enabled_core_modules.txt drush pml --no-core --type=module --status=disabled --pipe | cat > disabled_noncore_modules.txt drush pml --core --type=module --status=disabled --pipe | cat > disabled_core_modules.txt drush pml --type=theme --pipe | cat > themes.txt drush pm-updatestatus --pipe | cat > modules_to_update.txtRun "cat <filename>" to output it on terminal. Example "cat list.txt". The --pipe argument is quite useful in providing a piped output to use in the following command. Disable all non-core modules is quite easy. Disabling from a list of modules on the other hand may seem a bit more complex. /* Disable all non-core modules */ drush pml --no-core --type=module --status=enabled --pipe | xargs drush dis -y /* Disable all modules from a text file */ drush dis -y $(cat modules_list.txt) //OR cat > modules_list.txt | drush dis -y // The same can be applied for enabling /* Update all modules from a text file */ drush pm-updatecode $(cat modules.txt) //OR drush dl -y $(cat modules.txt)The command "drush pm-updatestatus" works only in versions above 6. It is recommended to update to a version above this. You can find a simple global installation for latest version of drush here. Drush provides the capability to write nested commands as seen earlier and so does Linux commands. You can mix and match with various commands. drush en -y $(drush pml --no-core --type=module --status=enabled --pipe) drush en -y $(drush pml --no-core --type=module --status=enabled --pipe | xargs cat > module_list.txt) /* The above commands are just for testing, they will work but will not affect the database.*/ Drush Drupal Modules Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 14th September 2015 / by antony.glen
Can you imagine how it will be to manage Drupal sites without Drush. We may face one issue when Drupal 8 release coming up. Drupal 8 needs the all new version of Drush, and it won't be compatible with older Drupal version 6 and so. Drush version 5 is used to Drupal 6, drupal 8 requires drush of version 8, or else if you have scripts for Drush developed for version 6 or 7 will not work with the latest version of Drush. In this article lets see how we could experiment switching between the Drush versions. First we need to install composer. Composer is the most perfered way of installing Drush, mostly the latest version. Now lets install drush globally, version 7 is till now the default version. \> composer global require drush/drush:7.* Next we need to pick one location to install drush versions. We need drush versions 5 and prior create directories for each of these drush version and these should be inside the user directory. Let's begin by installing drush versions needed, create directories for the drush versions, To install drush 8, create directory named drush8 inside the directory, run composer command: \> composer require drush/drush:dev-master Following the guidlines install other versions of drush also. Now its the key part, creating alias. In the bash profile add the following: alias drush5='~/drush5/drush' alias drush6='~/drush6/vendor/bin/drush' alias drush7='~/drush7/vendor/bin/drush' alias drush8='~/drush8/vendor/bin/drush' In the begining since I have installed drush 7 globally, this will act as the default version. We could call other drush versions using the alias name we added. For example, to check current status using drush 6 execute as follows: \> drush6 status. Other functions drush5 cc css-js Using the method we will be able to implement multiple Drush versions in our site. Please comment us for further clarifications. Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 17th August 2015 / by sarika.k
Here I am listing some methods to clear Drupal caches. Drupal caching is done to improve and enhance overall performances of the site. Its always recommended to enable the page caching and block caching in Drupal. The simplest way to clear the Drupal cache is to go to Administration > Configuration > Development > Performance Click Clear caches. Using drush through terminal. Run the command drush cc all in terminal. Flush cache tables from the database. Log into your PHPMyAdmin select your cache_ tables and flush/empty them. Using drupal_flush_all_caches(), to clear all caches. Add the code to index.php. If you can access your Drupal files but are unable to access your admin page, Then you can't clear caches directly. Even after doing necessary modifications, you may not see any improvement to your site since your pages are still cached in such situation an easy way to clear the cache is to use the PHP function in your index file and clear caches:require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_flush_all_caches(); //menu_execute_active_handler(); Hope this is helpful for you. Do you have any doubts, please share with us. For drush related articles, please use your time using this link. Drupal Drupal 7 Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 05th August 2015 / by fazeela.ma
While migrating our site to a new server or even updating the Drupal version, all come across backing up the database and files. Many might have done database backup through bash command. We can simply take a copy of the database by, mysql -u root -p drupal_database > drupal_database_backup.sql This would simply do it. If you want to make its copy in a path of your own, do specify the path in right portion. There is no choice left other than to backup the site files manually. However, we need to run many errands to take the backup of the database and files of Drupal installation. No worries, if you good at Drush. May be Drush developers have developed this considering the burden of back up's. In Drush we can backup the database as well as the files using a single command, ie., drush archive-dump, drush archive-dump default --tar-options="-z --exclude=sites/default/files" --destination=/_`date +%F`.tar.gz This command would give as a copy of both the database and the files folder of your Drupal installation at the destination specified. If you don't specify the destination folder, the backups would be available at drush-backup in home folder under today's date. This command supports 10 options. Few are, Description --description option for archive-dump will let you give a description for the contents you have backed up. No core --no-core which lets you not to include Drupal core files while backing up. Zipping the content --tar-options is the folder that've been asked to be zipped. Overwrite --overwrite, Suppose if the backup file specified is already been created once, on running the command with this option will overwrite the existing backup file. Destination --destination, is the path along with the file name for the copy. Tags --tags, As such as description the command also let as tag the contents to the most relevant tags. We can include more than one tag by comma separation. As of current developments in this command, it is not taking the back up of the database, but only the files. I assume people to try sql-dump command to create the backup of the database. Find more drush tips, please have look over here. Please get in touch with us to know more. Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 04th August 2015 / by fazeela.ma
Being drush in your portfolio has something to count on you. Drush has its own way of doing things. We all might be knowing on how to make a copy of the database of a project profile using MySQL in bash. In drush, we have drush sql-dump command, drush sql-dump --result-file=<backup-dir>/<project-code>_`date +%F`.sql.gz Using drush command we can take the back up of the database quick and smooth. This command supports around 14 options, few of them are, Result file --result-file : This is the path along with the file-name to which the copy has to be taken, if no value id specify find the backup under date folder in drush-backups in home folder. Skip tables --skip-tables-list : This is optional. If someone don't want a copy of a particular table, just specify it this array. Skip Data --structure-tables-list, which specifies a set of tables whose data are no more needed but its structure is. Tables list --tables-list. Set of tables to be listed. GZip the backup --gzip : compressing the values passed as the argument using gzip program. While running this command, make sure you are inside a Drupal installation. The above options can come handy when we want only one table, or even only data, or else the structure as the result. To update drush on you Drupal site, please have look over here. Please get in touch with us to know more. Drush MySQL Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 29th July 2015 / by emily.mathew
As part of Drupal development project, we always use drush commands. Drush or Drupal shell refers to a command-line shell and scripting interface for Drupal. Drush enables developers to effectively manage and maintain their Drupal websites from the server command line. A few frequently used commands are listed below. Download a module. drush dl module-name It will download the latest recommended module release from drupal site. drush dl --select module-name It will show all available versions. Then we can select the option that we want. Enable a module. drush en module-name It will ask to download the module, if it's not found. Disable a module. drush dis module-name Uninstall and Reinstall a module drush dre module-name Update a module. drush up module-name Run update.php drush updb Run tests. drush test-run This will run tests, if you use automated testing. Note that you must use the --uri option. URI of the drupal site to be used (only needed in multisite environments or when running on an alternate port). Clear the cache. drush cc all To clear all cached data from site drush cc css-js To clear all css and js cache from site Clear all the cache data, even if Drupal is broken. drush sql-query "DELETE FROM cache" sql-query command executes sql queries in the database where Drupal is installed. Set a password for a user. drush upwd --password="asdf" admin To revert a custom feature, update the database to match the code. drush fr feature_name Run cron. drush cron Flush image styles. drush image-flush all Set a variable. drush vset variable_name 'value'. Get the value of a variable. drush vget variable_name Open a MySQL console logged in. drush sql-cli Export a backup of the database. drush sql-dump | gzip --stdout > filename.sql.gz Remove all database tables (empty the database). drush sql-drop This command is useful before importing a database backup of the site. If you want to see all the main information and status of the site. drush status Create a user account. drush user-create <user-name> --mail="user@domain.com" If you regularly use drush commands in drupal applications development, this will definitely help you a lot. Drush Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 20th July 2015 / by varokky.jose
Drush alias are much handy when it comes to running commands in your local and executing them in server. Setting up alias needs little configuration. Read on to know the configurations. You would need to create alias file and put them in .drush folder of your home directory to make it available from anywhere. Drush alias file could be named as per the following naming convention. sitename.aliases.drushrc.php Each file can contain any number of aliases in a multi dimensional array, the key of each is the sub item for that alias. Have a look at the example as listed below. $aliases['dev'] = array( 'root' => '/home/user/public_html/mysite', 'ac-site' => 'sitename', 'ac-env' => 'dev', 'uri' => 'dev.example.com', 'remote-host' => 'example.com', 'remote-user' => 'user-1', ); You can use the following command for synchronizing the files to your local site. drush rsync @sitename.dev:sites/default/files/ sites/default/files/. Hope this helps. Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 24th April 2015 / by rohith.pv
Imagine if your Drupal site has more than 30-50 modules and you wanted to update them all or you want clear all Drupal cache. If you do it manually just by unzipping and run update.php or just click the clear cache it may takes more time. Hence if you can do this all process in one single command it will be easier for a developer. Here we can use drush commands to do all work with a single command and in few seconds. drupal.org says a "Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt". You can also view thing s like downloading a new module, installation location, site activity. When it comes to module you can enable, disable, install and uninstall. You can update the Drupal core and run update.php as well as you can upgrade to a newer version very easily. Drush can also be used to run cron, clear cache and creating a search index. Here are some useful drush commands drush cron : Run cron drush cc all : Clear all caches drush cc : cache clear drush dis : disable module eg: drush dis profile2 drush dl : download project or module eg: drush dl profile2 drush vset maintenance_mode 1 --yes Put a site into maintenance mode (D7 only) drush vset preprocess_js 0 --yes : Turn off JavaScript caching drush vset maintenance_mode 0 --yes Take a site out of maintenance mode (D7 only) drush vset site_offline 1 --yes : Put a site into maintenance mode (D6 only) drush vset preprocess_css 0 --yes : Turn off CSS caching. This is useful when developing themes. drush en : enable module eg: drush en profile2 drush vset site_offline 0 --yes Take a site out of maintenance mode (D6 only) drush status or drush st: Provides a bird's eye view of current Drupal install. drush up : Check for available updates, download updated modules, and run update.php drush sql-dump--result-file=db-backup.sql : Dump the entire Drupal database into a file called db-backup.sql. drush sql-cli < db-backup.sql : Connect to the database server and run the commands in db-backup.sql. To download and install. In your Linux machine type the following command. sudo apt-get install drush Some other useful tips regarding drush are, to download a Drupal you can use "drush dl drupal" or " drush dl drupal-7.x" to download a particular version. To install a site you can use. drush dl drupal --drupal-project-rename=example cd example drush site-install standard --db-url=mysql://[db_user]:[db_pass]@localhost/[db_name] --site-name=Example It will create the database for you if the db_user above has the privileges to. For more information you can go to drush.org.Thank you for reading!. Drupal Drupal 7 Drush Leave a reply Your email address will not be published. Required fields are marker *