Hướng dẫn sử dụng Drush tool cho người mới bắt đầu

Hướng dẫn sử dụng Drush tool cho người mới bắt đầu

CMS Drupal, DrushDrush is a great tool for quickly managing routine tasks with a Drupal installation.

Drush allows you to search the drupal.org site, install Drupal, install modules, enable modules and much more.

This is going to be a tutorial aimed at Drush beginners. We'll explain how to install Drush, how to use it and how to perform some common tasks.

Some Notes Before We Start

  • In this tutorial, we're working with a Drupal site that is already installed. To follow this tutorial, have a Drupal site to practice on and please make sure it's one you don't mind breaking!
  • This tutorial explains only of several ways to use Drush. Using PEAR is another recommended method and explained on the Drush download page.
  • Even though Drush is listed as a module on drupal.org, it's not actually a module. It is something you will need to install on your server, not upload through Drupal's module management.
  • If you are familiar with using shell access and the command line for doing things like copying, moving, backing up, and installing, you'll get the hang of Drush right away. If you're not familiar with either, don't worry if the concepts in this tutorial are confusing at first. With our help and some persistence, you will get the hang of it quickly.
  • Yes, this tutorial is a simplification, perhaps even an over-simplification. This tutorial is called the Absolute Beginner's Guide to Drush for a reason. It's a simple introduction to a complex topic. Those expecting a great level of detail are advised to visit http://drupal.org/node/477684.

Step 1: Setting up SSH Access

To access the server directly from your computer you will need shell (SSH) access.

What is SSH? Technically, SSH allows you to control another computer (ie, your web server) over the Internet through a command line interface (CLI). SSH is actually included by default on many Mac and Linux computers.

 
You will probably need to get your hosting company to enable SSH for you. Most hosting companies won't have this turned on for you.

Step 2: Install PuTTy and Connect

There are many ways that you can connect to your site using SSH, but in this example we're going to use Putty.

tutuploadsmedia_1340717521170.png
 
  • As soon as you enter your host name and click Open, you'll be taken to the command line screen. This will be a black screen with white text as in the image below.
  • Putty will ask you for your login username and password. This will often be identical to your FTP login or hosting account login.
tutuploadsmedia_1340722166971.png
  • You'll know that you logged in successfully if you get a message like the one below. That means that you're connected and ready to start work. If you get an Access Denied message, you'll need to try your details again.

Step 3: Download Drush

  • Go to http://drupal.org/project/drush.
  • Right-click on the download link for Drush. You want to copy the URL link. It will look like this: http://ftp.drupal.org/files/projects/drush-7.x-5.4.zip
  • Paste this into Putty.
1.wget http://ftp.drupal.org/files/projects/drush-7.x-5.4.zip
  • That command will run and should tell you that it connected to Drupal.org and saved Drush:
tutuploadsmedia_1340723047979.png

Step 4: Unzip Drush

  • Enter the command below and that will extract the zipped Drush file that's on your server.
1.unzip drush-7.x-5.4.zip
tutuploadsmedia_1340723003471.png
 

Step 5: Change Drush's Permissions

  • For security reasons, by default you will not have permission to use Drush. The following command will allow your system to use Drush:
1.chmod u+x ~/drush/drush
  • You can also do this via FTP. Find the file called Drush and set it's permissions to 744.

Step 6: Tell your System Where Drush is

  • The following command will give your system the information it needs to access Drush.
  • Be careful with the path. You are looking for the path to drush.php. If you have the wrong path, you'll get an Access Denied error. Try again with a new path.
1.export PATH="$PATH:/home/example/drush/drush:/usr/local/bin"

Step 7: Flush the Cache

  • The following command will reset your system that it is ready to use Drush:
1.source .bashrc

Step 8: Check that Drush is Working

  • Run this command to check if Drush is working:
1.drush status
  • If Drush is working you will see a result like the one below. If Drush isn't working, go back and check the earlier steps.
1.PHP configuration : /usr/local/lib/php.ini
2.Drush version : 5.4
3.Drush configuration :

Step 9: Browse to Your Drupal Files

  • In the example below, our Drupal site is in the /shell/ folder. Adjust this command to navigate to the folder where you have Drupal installed:
1.cd /home/public_html/shell/
  • You will know you're not in the root any more because the next line will read:
1.[~/public_html/shell]#

Step 10: Download a Module

  • Now let's test out our Drush install by trying to install a module. This command will download the Token module:
1.drush dl token
tutuploadsmedia_1340724253007.png

Step 11: Enable a Module

  • Now let's try to enable that Token module:
1.drush en token
tutuploadsmedia_1340724233092.png

More Common Drush Commands

Congratulations. If the download and enable commands work for you, then you're ready to use Drush.

We have seen several common Drush commands above. There is an entire list of the Drush commands at http://drush.org. Here are some of the most popular:

  • drush dl     Download and install a drupal module. This defaults to the sites/all/modules directory.
  • drush en     Enable a module
  • drush dis     Disable a module
  • drush up    Check for available updates, download updated modules, and run update.php
  • drush up     Check to see if the specific module needs updating, and if so, download it and run update.php
  • drush sql-dump --result-file=db-backup.sql    Dump the entire Drupal database into a file called db-backup.sql. In other words, backup your database.
  • drush sql-cli < db-backup.sql    Connect to the database server and run the commands in db-backup.sql. In other words, restore the database from db-backup.sql
  • drush cc all    Clear all caches
  • drush vset preprocess_css 0 --yes    Turn off CSS caching. This is useful when developing themes.
  • drush vset preprocess_js 0 --yes    Turn off JavaScript caching
  • drush cron    Run cron
  • drush vset site_offline 1 --yes    Put a site into maintenance mode (D6 only)
  • drush vset maintenance_mode 1 --yes    Put a site into maintenance mode (D7 only)
  • drush vset site_offline 0 --yes    Take a site out of maintenance mode (D6 only)
  • drush vset maintenance_mode 0 --yes    Take a site out of maintenance mode (D7 only)

 

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Apple TV sẽ cho phép sử dụng bàn phím bluetooth

Apple TV sẽ cho phép sử dụng bàn phím bluetooth

Rất nhiều người dùng cảm thấy khó chịu khi sử dụng điều khiển từ xa quá đơn điệu trên Apple TV. Tuy nhiên trên bản cập nhật tiếp theo, Apple TV đã cho phép dùng bàn phím Bluetooth để việc trải nghiệm trở nên dễ dàng hơn.

Headless Websites: Những vấn đề lớn là gì?

Headless Websites: Những vấn đề lớn là gì?

Headless website architecture is gaining traction and popularity. Nearly every developer I’ve spoken to in the past six months is excited about the potential, and with good reason

Các cách để save a node in Drupal

Các cách để save a node in Drupal

Every day, millions of nodes are saved. It happens every time content is created, migrated, or updated. It's probably the most common content management task in Drupal.

Công ty diệt chuột T&C

 

Diet con trung