Home PageArchiveContact UsAbout Us
If you are hopelessly addicted to drupal;
if bringing yourself to bed is allways a strugle;
if your main source of entertainement
is watching lullabot videos; then you belog
here.

Installing Drush

Video: 
See video

Introduction

Installing Drush is very easy, but installing it the right way on Linux can be a daunting task! Drush might work but you will always have a lot of permissions conflicts.

So, follow this tutorial and learn how to get Drush working on your Linux distro and behaving like a tamed cheetah!

Installing Drush with Pear

The first thing we need to do is to switch to the root user.

[User@localhost ~]$ su -
Password:

If you go to "https://github.com/drush-ops/drush", you will find instructions on how to install Drush.

The installation process might change considerably with time so the aforementioned URL is the best source of up to date installation instructions. In any case, I am going to show you how to install Drush as it is today:

[root@localhost ~]# pear channel-discover pear.drush.org
[root@localhost ~]# pear install drush/drush

I had a little problem with the pear channel, the first time around. My VM was disconnected from the Internet and, for that reason, the above command created a broken pear channel. As a result, I had to learn how to uninstall it from my VM so I could try to reinstall it once the Internet connection had been reestablished. You don't need to do the following commands unless your pear channel was not set up correctly.

[root@localhost ~]# pear uninstall drush/drush
[root@localhost ~]# pear channel-delete pear.drush.org

Download Drupal Site With Drush

Now, what I am going to do is to partially delete the website that we have created on the previous videos. Not that there is anything wrong with it. It is just so I can show you how to recreate it with Drush.

[root@localhost ~]# cd /var/www/html
[root@localhost html]# rm -Rf drupalfever

Now, with a single line of commands we will download the lattes version of Drupal, decompress it, and rename the decompressed folder to "drupalfever":

[root@localhost html]# drush dl drupal --drupal-project-rename=drupalfever

Let's breakdown the above command so you understand it a little better:

  1. drush The command that you will always have to type.
  2. dl Drush download subcommand that you can use to download Drupal core or a module.
  3. drupal Is the name of the module or, in this case, of the project you want.
  4. --drupal-project-rename Property that will rename the downloaded folder.
  5. drupalfever The name of the folder to rename it to.

Install Drupal Site With Drush

Now, let's go back inside this new folder and recreate the phpoMyAdmin symbolic link.

[root@localhost html]# cd drupalfever
[root@localhost drupalfever]# ln -s /var/www/html/phpmyadmin ./

Now, we are going to install Drupal with a single line of command:

[root@localhost drupalfever]# drush si -y --db-url=mysqli://root:5XsrZPtBWbGf@localhost/drupalfever

Let's breakdown the above command so you understand it a little better:

  1. drush The command that you will always have to type.
  2. si Drush "site installation" subcommand.
  3. -y Will answer yes to any prompt during the installation.
  4. --db-url Property with the database connection URL.
  5. mysqli In the beginning of the database URL, you will have to type the database protocol. Note that it is "mysqli" with an "i" at the end.
  6. root If you had a different User previously created for the database, you could use it here instead of the root user. This other user needed to have Grant privileges to the database at list while the installation is taking place.
  7. 5XsrZPtBWbGf Te database password for the root user in this case.
  8. localhost The location where your database server is.
  9. drupalfever The name for our new database.

Create Additional Folders In Drupal Site

Now, we are going to create a couple of folders on our website that I think should have been created by default during the installation.

[root@localhost drupalfever]# mkdir sites/all/libraries
[root@localhost drupalfever]# mkdir -p sites/all/modules/{contrib,custom,features}

Now we need to change the ownership of the files in our website. They are currently being owned by "root" but we want them to be owned by "apache".

[root@localhost drupalfever]# chown -R apache:apache ../drupalfever

Setting Up The Sticky Bits On The New Folders

You may already know how to change permissions on a file on Linux but most Linux people have a hard time understanding or using the "Sticky Bits". Just for our Development Environment, we are going to change some permissions so we can execute Drush without having problems accessing or editing some critical files or folders.

[root@localhost drupalfever]# chmod -R 6770 sites/all/modules/{contrib,custom,features}
[root@localhost drupalfever]# chmod -R 6775 sites/all/themes
[root@localhost drupalfever]# chmod -R 6770 sites/default/files

Setting Up ACL Permissions On The New Folders

Now we need to add ACL permissions to these new folders:

[root@localhost drupalfever]# setfacl -m d:user:apache:rwx,d:user:User:rwx,d:group:apache:rwx ./sites/all/modules/{contrib,custom,features}
[root@localhost drupalfever]# setfacl -m d:user:apache:rwx,d:user:User:rwx,d:group:apache:rwx ./sites/all/themes
[root@localhost drupalfever]# setfacl -m d:user:apache:rwx,d:user:User:rwx,d:group:apache:rwx ./sites/default/files

There is a curious caveat to ACL, it will only work if all the parent folders down the directory tree have a permission of at list "711". It can have more but never less. So let's check these folders one by one and change their permissions accordingly:

Add Sudo Access To User

Now, just so we can work outside of the root user in our Development Environment, we are making a "Sudo" entry for our user.

[root@localhost drupalfever]# visudo

Now you should add this line at the end of the file.

User ALL=(ALL) NOPASSWD: ALL

Now, you will need to type the following to save your changes:

   :     W     Q   Enter

Now, you need to alter the default group for your User.

[root@localhost drupalfever]# usermod --gid apache User

Change Umask For The User

Now, let's get out of the root account:

[root@localhost drupalfever]# exit

Now, we need to change the default umask for our user in shell mode.

[User@localhost ~]$ echo "umask 0002" >> ~/.bashrc

Now, we need to change the default umask for our user on system-wide.

[User@localhost ~]$ sudo nano /etc/profile

Add this at the end of the file. Just remember to change the user name on this shell script where it says "User". You should type your own user name, instead.

USRNAM="User"

if [ "$USRNAM" = `whoami` ];
   then umask 002
fi

Now, save and exit nano:

Ctrl +   O  

Enter

Ctrl +   X  

Make Drush Run From The Apache User

Now, we need to figure out the full path of Drush:

[User@localhost ~]$ which drush
/usr/bin/drush

Now we need to create a command alias in our shell that will sudo us to apache every time we use Drush.

[User@localhost ~]$ echo "alias drush='sudo -u apache /usr/bin/drush'" >> ~/.bashrc

So, now, lets do a test with Drush:

[User@localhost ~]$ cd /var/www/html/drupalfever
[User@localhost drupalfever]$ drush status

Use Drush To Install 12 Modules At Once

Drush really shines when it comes to downloading and installing modules. As an example, I will show you how to download and install some of the modules that I always install on my websites. To download the modules you do the following:

[User@localhost drupalfever]$ drush dl module_filter filter_perms taxonomy_manager admin_menu libraries hierarchical_select fieldset_helper devel devel_themer features

Now that we have downloaded the modules, we can enable all of the ones that we need with Drush as well:

[User@localhost drupalfever]$ drush en -y module_filter filter_perms taxonomy taxonomy_manager admin_menu libraries hierarchical_select fieldset_helper devel devel_generate features

Now, I will disable the "toolbar" module that comes enabled by default in Drupal 7. Since we installed "admin_menu", this module is no longer necessary.

[User@localhost drupalfever]$ drush dis -y toolbar

Now let's go to the folder where the modules were downloaded and see how our permissions worked out.

[User@localhost drupalfever]$ ll sites/all/modules/contrib/

We are done!

Average: 5 (3 votes)
Drupal
Linux