Blogs

How to quickly enable or disable and control your Drupal theme using DRUSH

Drush can do so many things specially during development of a Drupal Website and this includes working with theme of your website. Here are some drush command for manipulating theme that I find very useful and handy to memorize while you are working within your drupal site. Screen shot will show you, the code is written below:

Drush command written below.

Code

1.) Enable theme
drush pm-enable themename

2.) Disable theme
drush pm-disable themename

3.) Show information about the theme
drush pm-info themename

4.) List all theme
drush pm-list --type=theme

5.) List enabled theme
drush pm-list --type=theme --status=enabled

6.) Set default theme
drush vset theme_default themename

7.) Set admin theme
drush vset admin_theme themename

8.) show theme status
drush status theme

How to install Drupal 7 through shell using Drush

First you need to login to your server then type the following command seen on this screenshot, the code is shown below.

Code

Step 1 - Go into your public_html folder
  cd ~/public_html

Step 2 - Download Drupal using drush command
  drush dl drupal

Note: If successful, drupal will be downloaded inside public_html/drupal-7.12 directory

Step 3 - Go inside drupal-7.12 folder
   cd drupal-7.12

Step 4 - Move all files into public_html
    mv * .* ..

Step 5 - Go to public_html directory, up one level
    cd ..

Step 6 - Clean up, delete the empty folder
    rm -rf drupal-7.12

Step 7 - Install drupal using drush
     drush site-install --db-url=mysql://dbusername:password@localhost/dbname

Follow the instructions and answer yes if you ask to continue. After installation, take note of username/password given to you. Visit the browser and enjoy your new Drupal 7 website

How to quickly enable or disable Drupal CSS/JS optimization using DRUSH

I find this command very handy during development. Drush can easily disable or enable CSS and JS aggregation using the vset command in Drush. Here's how:

Code

// To turn on JS Aggregation
    drush vset preprocess_js 1 --yes

// To clear all Cache
    drush cc all

// To disable JS Aggregation
   drush vset preprocess_js 0 --yes

// To clear cache of JS and CSS only
   drush cc css+js

// To enable CSS Aggregation
   drush vset preprocess_css 1 --yes

// To disable CSS Aggregation
   drush vset preprocess_css 0 --yes

PHP scripts for converting InnoDB to MyISAM database engine

This PHP CODE snippets will change your database engine from  InnoDB to MyISAM, this is useful when you need to save time manually changing all the tables from InnoDB to MyISAM, for example when a CMS populates a database with tables that use InnoDB but you cannot run on your web host because InnoDB is disabled and MyISAM is your remaining options.

Commonly on a shared hosting environments, web host disabled InnoDB because it requires more disk space and eats more Server resources and Memory than MyISAM. To use this scripts you need to change the variables:

dbServerName // Database server, commonly use value is localhost

dbUserName // Database User, the one with priveleges to your database

dbPassword // Password of the Database User

DatabaseName // The database you want to convert from InnoDB to MyISAM

Code

<?php
// display error is On for us to be notified if there's something wrong
ini_set('display_errors', 'On');
error_reporting(E_ALL);

// Set a connection for our database
$link = mysql_connect("dbServerName","dbUserName","dbPassword")
or die(
"unable to connect to msql server: " . msql_error());

// Select our database
mysql_select_db("DatabaseName", $link)
or die(
"unable to select database 'db': " . msql_error());

$result = mysql_query("show tables");
if (!
$result) {
  die(
'query failed: ');
}

// Use while loop to convert all tables to MyISAM
while ($row = mysql_fetch_array($result)){
// Command Reference: ALTER TABLE tableName ENGINE=MyISAM
mysql_query("ALTER TABLE ".$row[0]." ENGINE=MyISAM; ");
}

?>

How to install node.js in CentOS server

Here how to install node.js into you CentOS server. Login to your centOS server using SSH client such as putty and type the following commands in shell.

Code

yum install openssl-devel
cd /usr/local/src
wget http://nodejs.org/dist/v0.6.8/node-v0.6.8.tar.gz
tar zxvf node-v0.6.8.tar.gz
cd node-v0.6.8
./configure
make
make install