Setup Drush alias to run Drush on remote server.

Drush alias  help me to run the drush command on  the remote server from my local computer.

How to setup ?

Setting up the aliases is quite easy, It just required file named in this below format

[your-site.]aliases.drushrc.php

in your drush folder. Most of the time location of your  drush folder should be ~/.drush.

Putting it in home folder makes it accessible from anywhere.

Content for  [my-site.]aliases.drushrc.php

// You can create as many environments you want.
$aliases['dev'] = array(
'remote-host' => 'ssh-host',
'remote-user' => 'ssh-user',
'root' => 'my-drupal-root',
'uri' => 'my-site-name',
);

To add more environments, create one more alias array in the same file. Like this

$aliases['prod'] = array(
'remote-host' => 'ssh-host',
'remote-user' => 'ssh-user',
'root' => 'my-drupal-root',
'uri' => 'my-site-name',
);

Below is the command to access your remote site via drush

drush @my-site.dev status    // Dev env

drush @my-site.prod status  //Prod env

To list all Drush alias run the below command

drush sa

Now we are ready to run almost every drush command locally to control our remote drupal site.

Examples:

drush @my-site.dev sql-dump > dbdump.sql

drush rsync @my-site.dev:sites/default/files/ sites/default/files/
Advertisements

Reset password using drush

This commands will be help you to reset the admin password of your site.

# Provide you a login link
drush uli
# Set the password for any user
drush upwd admin –password=”new password”

One more way :

cd php scripts/password-hash.sh 'drupal'

This will generate a hash for you, copy and paste in below queries.

drush sql-cli
update users set name='admin', pass='Hash generated from above command' where uid=1;
quit

Install Drupal From Command Line

If you are using drupal, you must have heard of drush, if not check it now, its the one of the awesomest thing in drupal.More links

1. Project page on drupal.

2. Documentation : how to install

Now i suppose you have drush installed on your system. So you can install drupal in three easy steps.

1. Drush dl drupal

2. mv drupal-7.x your_site_name && cd your_site_name

3.drush si --db-url=mysql://mysql_username:password@127.0.0.1/db_name --account-name=you_choose --account-pass=you_choose --account-email=your_email --locale=pt_br --site-name="Drupal Test"