Pages

Saturday, April 5, 2014

Drush - Drupal Command Line interface

Drush is a command line interface that allows to manage your Drupal web sites fast and easy. This scripting shell should be additionally installed on your hosting server in order to benefit from its features. 
First, you need to have a Drupal installation under your hosting account. It can be completed in several mouse clicks through cPanel -> Softaculous.
Second, you need SSH access to your account in order to run Drush commands.
In this part of the Drupal tutorial we will show how to use Drush in order to backup and update your script, install and activate Drupal extensions, remove them and clear the script’s cache.
In order to create a backup of your Drupal web site with Drush follow the steps listed below:
  1. Log in your account via SSH. 
  2. Navigate to the Drupal installation’s home folder.
  3. Run the following command:
drush archive-backup –destination=/home/cPuser/backup/site.tar.gz
Replace the cPuser variable with your actual cPanel user. You can pick a different location for the backup and different backup file name.
Executing the command listed above will create an archive with all the web site files and a dump of your Drupal database.
The output will be similar to the following one:
Drupal version                  :  7.22
Site URI                        :  http://default
Database driver                 :  mysql
Database username               :  cPuser_drup709
Database name                   :  cPuser_drup709
Database                        :  Connected
Drupal bootstrap                :  Successful
Drupal user                     :  Anonymous
Default theme                   :  bartik
Administration theme            :  seven
PHP configuration               :  /usr/local/php54/lib/php.ini
Drush version                   :  6.0-dev
Drush configuration             :
Drush alias files               :
Drupal root                     :  /home/cPuser/public_html/drupal
Site path                       :  sites/default
File directory path             :  sites/default/files
Temporary file directory path:/tmp
Archive saved to /home/cPuser/backupD/site.tar.gz
If you need to restore a backup of your web site use the following command:
drush archive-restore /home/cPuser/backup/site.tgz
The output will be similar to:
Archive restored to /home/cPuser/public_html/drupal                         [ok]
To update the Drupal application execute the following command:
drush pm-update
Checking available update data …                                          [ok]
Checked available update data for Block.                                    [ok]
Checked available update data for one project.                          [status]
Name    Installed Version  Proposed version  Message
Drupal  7.20               7.22              Update available
Update information last refreshed: Thu, 06/06/2013 – 11:18
Update status information on all installed and enabled Drupal projects:
Code updates will be made to drupal core.
WARNING:  Updating core will discard any modifications made to Drupal core files, most noteworthy among these are .htaccess and robots.txt.  If you have made any modifications to these files, please back them up before updating so that you can re-create your modifications in the updated version of the file.
Note: Updating core can potentially break your site. It is NOT recommended to update production sites without prior testing.
Do you really want to continue? (y/n): y
Project drupal was updated successfully. Installed version is now 7.22.
Backups were saved into the directory                                       [ok]
/home/cPuser/drush-backups/cPuser_drup709/20130606113109/drupal.
‘all’ cache was cleared in self                                        [success]
No database updates required                                           [success]
‘all’ cache was cleared in self                                        [success]
Finished performing updates.                                                [ok]
The above command will also update the plugins.
To install a chosen plugin you should download and enable it. Check the example listed below:
drush dl addtoany
Project addtoany (7.x-4.0) downloaded to sites/all/modules/addtoany.   [success]
drush en addtoany
The following extensions will be enabled: addtoany
Do you really want to continue? (y/n): y
addtoany was enabled successfully.                                          [ok]
addtoany defines the following permissions: administer addtoany
Your AddToAny settings are available under Configuration > System    [status] > AddToAny
Instead of AddToAny you can pick a different Drupal plugin or module. The skip the Do you really want to continue? prompt modify the command in the following way:
drush en -y addtoany
A chosen extension can be disabled and removed with two simple commands. Check the example:
drush dis -y addtoany
The following extensions will be disabled: addtoany
Do you really want to continue? (y/n): y
addtoany was disabled successfully.    
drush pm-uninstall -y addtoany
The following modules will be uninstalled: addtoany
Do you really want to continue? (y/n): y
addtoany was successfully uninstalled.
Often the Drupal web site administrators need to clear the script’s cache. It can be easily completed with the following command:
drush cache-clear all
‘all’ cache was cleared in self                                        [success]
If the webmaster prefers to clear different types of cache the options can be listed:
drush cache-clear
Enter a number to choose which cache to clear.
[0]  :  Cancel
[1]  :  all
[2]  :  drush
[3]  :  theme-registry
[4]  :  menu
[5]  :  css-js
[6]  :  block
[7]  :  module-list
[8]  :  theme-list
[9]  :  registry
To get help on the Drush commands run the following command:
drush help
If you want to learn how to use a specific command enter the following line in the shell:
drush help command
Replace the “command” string with the chosen one. For example:
drush help archive-backup
More about Drush can be found in the official documentation of the project: http://drush.ws/

Access Control in Drupal CMS

The access control list in the Drupal's admin panel -> People -> Permissions is quite self-explanatory.
There you can modify the predefined permissions for the different user types (anonymous, authenticated and administrator).
A typical use of the access control is when you want to make some parts of your site available only for registered users. The default access control rules are quite safe, but you might want to change them to satisfy better your needs. Spend some time playing with the permissions options to better understand what you can do.

Using Drupal Taxonomy to Post Content

Now that we have created the vocabulary and we have added terms to it, we can use it when posting content on the web site.
Note that the tags option auto completes the vocabulary field with one of the terms we have created before.If you choose terms from the vocabulary they will be displayed as tags on the page you have posted them as shown below:
Note that the terms presented do not indicate their underlying structure to the reader. The vocabulary just displays all terms for this content item.The Drupal taxonomy provides a great way to manage the content sorting of your web site. Those are just basic examples and you can achieve amazing results extending the taxonomy vocabularies and terms for your web site.

Managing an Existing Vocabulary

There are 3 actions you can take with an existing vocabulary.
  • Edit Vocabulary -  This refers to changing the settings you have chosen upon creating the vocabulary.
  • List Terms - It will display a list of all terms currently added to this vocabulary.
  • Add Terms -  This will allow you to add a new term to an already created vocabulary.
By default the terms list for a newly created vocabulary will be empty. You will need to create terms for the vocabulary via the Add terms functionality:
We have added several terms in our vocabulary and here is how the list looks now:
You can now edit each of the terms you have added by clicking the corresponding button. Drupal allows you to adjust the terms order. You can do so by holding down the left mouse button on the cross icon at the left and dragging the term to the desired position in the list.Note that when creating or editing a term you have relations you can set for it.
Those settings will provide you with four different options.
1. You will be able to define an already existing term as parent term for the new one. Note that if you hold down Ctrl you will be able to set more than one term as parent for the new one. Note that setting multiple parents for a single item will disable the drag and drop list functionality. It will be re-enabled if you reduce the parents for each term to one.
2. You can set the weight for each term. The same as with vocabularies this resembles the order in which the terms will be listed in the vocabulary.
Once you have made the desired changes click the save button.

Creating a New Vocabulary for Drupal Taxonomy

It is important to note that content can belong to several vocabularies at once. Also vocabulary relations can be modified dynamically as new content or new vocabularies are added. This saves the trouble to manually update the relationships each time.
The taxonomy module in Drupal allows multiple lists of categories for classification. It offers the possibility of creating thesauri (terms with horizontal relationships) and taxonomies (terms with hierarchical relationships). Basically, the taxonomy deals with a hierarchy of information and the thesaurus deals with relationships between terms. Taxonomy is what affects how exactly the content is organized.
Settings for the taxonomy module can be found in the Drupal admin area -> Structure -> Taxonomy.
You can add a new vocabulary using the "Add vocabulary" link.
The Name field is mandatory and if you want you can add a description.

Drupal Upgrade

Here we will explain in simple steps how to upgrade your Drupal application to the latest stable version.
STEP 1The first step is to visit the official Drupal site and download the latest stable release of Drupal.
Once the download is complete, you need to upload the new version of Drupal on your website. The safest way to do that is to create a new folder in the public_html directory of your website, e.g. drupal_new, and upload the new version package there. Then you need to extract the archive file through cPanel -> File Manager.
If you don't have cPanel, you can extract the archive on your computer and upload its contents to your account using your favorite FTP client.
STEP 2Once you have the new version uploaded in the drupal_new folder, you should copy the necessary files and folders from the old version of Drupal to the new one.
Here we assume that you already have a full backup of your live Drupal site. Navigate to the backup folder of your Drupal site and copy the .htaccess file, the sites and the files directories and upload them into the drupal_new folder by overwriting any existing files.
Now, go to your cPanel -> File manager -> public_html -> drupal_new/sites/default folder and open the settings.php file for editing.
Edit the following line:
$update_free_access = FALSE;
and change it to:
$update_free_access = TRUE;
The changes above will allow you to run the update.php script from your browser.
STEP 3The next step is to update the database of your Drupal.
Go to
http://yourdomainname.com/drupal_new/update.php
where yourdomainname.com is replaced with your actual domain name. The screen should look similar to the one below.
Click on the Continue button and follow the instructions.
A list with the pending updates will be published. You can check them. Click on the Apply pending updates button to perform the update.
If there are no errors reported, your Drupal application is successfully upgraded.
Due to security reasons you should turn the $update_free_access variable back to false in the settings.php file:
$update_free_access = FALSE;
Open a new window in your browser and point it to the site you have just upgraded. As we performed the upgrade in a test folder drupal_new you should point your browser to: http://yourdomainname.com/drupal_new/
Once you are sure that the upgraded version of the site works properly you can delete or rename the old folder to drupal_old and rename drupal_new to drupal in order to put the new version live.

MySQL Backup/Restore Tutorial

Learn how to backup and restore MySQL databases in your hosting account. Here you will find detailed instructions on how to archive your information and restore it when needed.

MySQL Export: How to backup your MySQL database?

You can easily create a dump file(export/backup) of a database used by your account. In order to do so you should access the phpMyAdmin tool available in your cPanel:
The phpMyAdmin tool will be loaded shortly.
You can select the database that you would like to backup from the Database menu (located in the upper left corner of the page).
A new page will be loaded in phpMyAdmin showing the selected database. In order to proceed with the backup click on the Export tab:
The options that you should select apart from the default ones are Save as file (which will save the file locally to your computer in an .sql format) and Add DROP TABLE (which will add the drop table functionality if the table already exists in the database backup) as shown below:
Click on the Go button to start the export/backup procedure for your database:
A download window will pop up prompting for the exact place where you would like to save the file on your local computer. It is possible that the download starts automatically. This depends on your browser's settings.

MySQL Import: How to restore your MySQL database from a backup

To restore (import) a database via phpMyAdmin, first choose the database you'll be importing data into. This can be done from the corresponding menu on the left. Then click the Import tab:
You have the option of importing an .sql file. Choose the file from your local computer. Note that you are given the option to pick the character set of the file from the drop down-menu just below the upload box. If you are not certain about the character set your database is using just leave the default one.
In order to start the restore click on the Go button at the bottom-right. A notification will be displayed upon a successful database import. 

Search Engine Friendly URLs

Here we will try to explain how you can enable the clean URLs in Drupal in three simple steps. Most servers fully support the Apache mod_rewrite module and all Drupal users hosted on our servers will be able to use the clean URLs option.
There are only 3 steps you need to follow to enable the Search Engine Friendly URLs.Here we assume that you already have Drupal installation for your account into the /drupal subfolder (www.yourdomainname.com/drupal) and you want to activate the clean URLs.
STEP 1Edit the .htaccess file in your Drupal directory.
Delete the entire content of the .htaccess file and insert the following lines into it:
RewriteEngine on
RewriteBase /drupal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
You should replace the path in the following line:
RewriteBase /drupal
with the relative path to the directory where Drupal is installed. For example if your Drupal is installed in your web site root folder and you access it via www.yourdomainname.com, the line should look like this:
RewriteBase /
STEP 2The next step is to log in the administrative back end of your Drupal site and make sure that the "Path" module is enabled. This module is essential for the clean URLs in Drupal.
Once you are logged click on the "Modules" link:
Scroll down the page, find the Path module, tick the little check box on the left of the module and save the settings:
STEP 3The next and final step is to test the clean URLs and confirm their functionality. In the administrative back end click on the Configuration link from the top menu and open the Clean URLs section.
The page will be loaded. Make sure that the clean URLs checkbox is enabled and the configuration is saved.
Now load the front end of your site and point the mouse over a link. In the status bar and in the address bar you will notice that all links will be in clean (human readable) format.

How to Create a Backup of Drupal?

In order to backup your Drupal application you have to:
STEP 1Backup all your web site files.
Backup all the files and folders inside your Drupal directory. You can do that by downloading them via your favourite FTP client. 
STEP 2Backup/Export your database
Then, you have to export your Drupal database. You can do that by using PHPMyAdmin. Please, check our tutorial on how to backup/restore MySQL database in order to create a backup of your Drupal database.
Please, make sure that you choose the correct database, which your Drupal application uses.
If you are unsure about the Drupal database name, you will be able to find it in the drupal_folder/sites/default/settings.php file. You can view this file through cPanel -> File manager. 

How to optimize Drupal?

There are several steps that you should follow in order to improve the performance of your Drupal-based website:
First, you should enable the caching system of your Drupal application. In order to do this, login as administrator and go to the Administer -> Site Configuration -> Performance menu. In it, set the values of Caching Mode to "Normal" and Block Cache to "Enabled". Then, click on the "Save configuration" button at the bottom of the page.


Next, you can disable all the modules/blocks that you are not actually using. To do this, go to the Administer -> Site Building -> Modules menu. Note that the enabled modules have a check in the "Enabled" column. Remove this check for all the modules you want to disable and then click on the "Save configuration" button at the bottom of the screen.


Finally, you should optimize your Drupal database. 
In addition, you can try reducing the content you are displaying on your front page. Too much links/images/scripts on your main page can signifficantly increase the time your website needs to load.

How to Manage Users in Drupal

You can manage users' rights from the Drupal Admin Section -> People.
People
Here you can filter the list with the users registered in your system based on the role, defined permissions and status (active, blocked or both).
The Update Options drop-down menu allows the chosen accounts to be blocked, canceled, promoted as administrators or downgraded back to regular users.
Also, you can add a new user or edit a selected one using the corresponding links.
users

How to change the default Drupal theme?

The default Drupal installation comes with several themes which can be changed from your administration area. Log in as an administrator,click on Administer -> Appearance and choose which theme you want to use for your website.
Appearance

How to install new Drupal themes?

Drupal keeps its skins in the themes subfolder. To install additional themes, you can get from the Drupal official theme resource. Extract the files under the themessubfolder. This can be done through cPane l -> FileManager.
If you don't have cPanel or you prefer using an FTPclient, you can extract the archived theme to your computer and then upload the theme's files to the themes folder in your Drupal installation directory.
You should now be able to see the theme at your Drupal Administration Area -> Appearance. Enable it and set it as default.
enable theme
The Update t ab allows to view the outdated themes and get the new versions.
Appearance Update
In the Settings section you can manage the global visualization settings for your web site. You can also overwrite them per each theme.
Drupal Appearance

How to install/enable Drupal modules

You can enable/disable Drupal Modules from the Drupal Administration area -> Modules section.
The default installation of Drupal has many useful modules, and there is a brief description of what each one of the modules does. If you need more modules, you can freely download them from the Drupal Modules official website.
On your site, Drupal modules are stored in the modules subfolder within the Drupal installation directory. You can install additional modules by simply unzipping them in that folder. Alternatively, you can use the Install new module functionality.

How to install/enable the Nice Menus module?

We will demonstrate the module installation process in Drupal by installing the Nice Menus module.
Visit Drupal Modules website and find the Nice Menus module. Download the corresponding version to your local hard-drive. Then upload the archive in the modules folder of your Drupal installation and extract it.
Make sure its dependencies are enabled. Then enable the Nice Menus module and save the new configuration.
You can also check for the modules that need update in the Update tab.
The Uninstall section lists the disabled external modules that can be uninstalled from your system.

How to use Drupal?

In this tutorial we will show you the basic actions you need to take in order to start a new Drupal-powered website.

How to start a Drupal site?

All you need to do is sign up for a hosting account where you can have the Drupal application installed.  If you already have a hosting account and would like to change your host, we offer free website transfer of your Drupal site.

How to create new content?

In order to add content for your Drupal web site, you need to click on the Add content link under your administrator area.
  • The Article option is suitable for a blog, news or other time-sensitive content.
  • The Basic Page option allows you to create a static page;

Content Management

In order to manage the content structure elements of your Drupal web site, you need to navigate to the Structure section under your administrator area.
In the following lines we will give a brief description of the options under this section:
Blocks - This functionality allows to manage the content that will be visualized through blocks on the sidebars and other regions of the web site. The blocks can be situated on the themes regions through a drag-and-drop interface. They are configured separately per each theme due to the different visualization setup.
Content types - Manage content types, including default status, front page promotions, comment settings and more. You can include new content types besides Basic Page and Article.
Menus - Allows to add new menu, edit existing ones, manage them, list, add and reorganize the menu links. You can also define the menu sources.
Taxonomy - You can manage the tagging, the categorization and classification of your content.

How to Install Drupal On Your Hosting Account

In order to install the Drupal CMS application, please follow the step-by-step instructions below:
STEP 1Download the installation file from Drupal.org by choosing the latest stable version and clicking on the download link next to the package.
STEP 2Upload it in the public_html folder of your account. You can do that through an FTP client like FileZilla or via cPanel -> File Manager -> Upload file(s). This way, after the installation is completed, the script will appear once your write something like http://yourdomainname.com in your web browser. Or you can create a subfolder there and upload the file in it. The Drupal installation will be available at: http://yourdomainname.com/subfolder.
STEP 3Once you are in the File Manager, please navigate to the uploaded file and extract it by clicking on the Extract link. It will create a subfolder: drupal-x.x.x., where instead of x.x.x. is the current version. So you can move the files one level up in the desired directory. The other option is to extract the file in your computer and then to upload the content in the desired folder via FTP.
STEP 4Once the files are extracted in the desired folder, you should create a MySQL database for Drupal. You can do that from cPanel -> MySQL Databases. There you should create a database and add a user to it - click here to learn how to create a MySQL database and user.
STEP 5Navigate to the URL of your Drupal site and run the install.php file (for example http://yourdomainname.com/install.php). Pick the default profile option for your Drupal application.
STEP 6Pick the default language for the Drupal web site.
STEP 7Enter the database details for the database which you have created in Step 4. Click on the Save and continue button to continue.
STEP 8The installation procedure is finished. You will see the following screen:
Enter the site information and the administrative login details. Click on the Save and Continue button.
STEP 9Well done! The installation is completed and you can proceed to your web site.