Restoring Drupal from a backup using CPanel

Recently I had to move one of our Drupal site from one server to another. I was given the tar file containing the backup including the mysql script files. I strongly recommend you to go through expert blogs and sites for the complete information about this topic. I am writing my own experience

  1. The core Drupal installation is within the public_html folder. You can see this file folder within your backup files  directories.  In my case my public_html file was within a tar file named homedir.tar within my main backup file. public_html folder should contain folders like modules, profiles, INSTALL.txt etc. This is the base folder for your drupal installation. You have to copy this folder within public_html folder of your server. If your domain is www.abc.com the contents of public_html(modules, profiles etc) will be right within public_html/www folder. If you have a sub-blog then you have to copy the contents withing the subfolder. Following steps will assume that you are copying directly under public_html
  2. Using Cpanels, MySql Databases application, create a new database, create a new user and add this user with all the privileges to that database.
  3. Open public_html/sites/default/settings.php and set db_url value as per the database and user you have created in previous step
  4. Core data of your drupal website resides in mysql. Now you will have to import mysql database from the backup file to the newly created database. There are several ways of doing it. If you have ssh access you can go to the database and simply import the .sql file. I found phpadmin easy. For that, first you have to open your backup mysql script file(in my case it was a file under mysql folder in the backup. If there are more than one files then size of the files should give you fair idea which is the right file. Normally, file name should begin with the database name in your previous server) As a first statement in that sql file write this
    use mydb

    Where mydb is the name of the data. Usually when you select database in phpmyadmin before import then this step is not required. But it never hurts(less surprises this way)

  5. Open phpmyadmin, select your database from left lift, go to import tab and import this sql file
  6. Upto this step your website should be restored. If not, then probably you missed something. If you have not implemented clean url in your blog, then you don’t have to do anything else. Clean url converts the url in this format http://www.abc.com/?q=node/view/1/ to http://www.abc.com/node/view/1/.
  7. If you have implemented clean url, on clicking any link you might be getting 404 error. To correct this you have to have .htaccess file properly configured. This is just an example

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<Files ~ "(.(inc|module|pl|sh|sql|theme|engine|xtmpl)|Entries|Repositories|Root|scripts|updates)$">
 Order deny,allow
 Deny from all
</Files>

# Set some options.
Options -Indexes
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More exist in sites/default/settings.php, but
# the following cannot be changed at runtime. The first IfModule is
# for Apache 1.3, the second for Apache 2.
<IfModule mod_php4.c>
 php_value magic_quotes_gpc                0
 php_value register_globals                0
 php_value session.auto_start              0
</IfModule>

<IfModule sapi_apache2.c>
 php_value magic_quotes_gpc                0
 php_value register_globals                0
 php_value session.auto_start              0
</IfModule>

# Reduce the time dynamically generated pages are cache-able.
<IfModule mod_expires.c>
 ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
 RewriteEngine on

 # Modify the RewriteBase if you are using Drupal in a subdirectory and
 # the rewrite rules are not working properly.
 #RewriteBase /drupal

 # Rewrite old-style URLs of the form 'node.php?id=x'.
 #RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteCond %{REQUEST_FILENAME} !-d
 #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
 #RewriteRule node.php index.php?q=node/view/%1 [L]

 # Rewrite old-style URLs of the form 'module.php?mod=x'.
 #RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteCond %{REQUEST_FILENAME} !-d
 #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
 #RewriteRule module.php index.php?q=%1 [L]

 # Rewrite current-style URLs of the form 'index.php?q=x'.
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.66 2005/03/20 19:15:00 dries Exp $

This should complete your backup restoration. If you have any issues you can post comments here.

Getting all pages in WordPress

      No Comments on Getting all pages in WordPress

WordPress provides elegant wp_query class to query and manipulate post. You can use query_posts to query the posts in your blog.  If used with The_Loop and other global variables, it is very powerful function.

Sometimes, instead of posts, you need to query all the pages of your website. WordPress use same table to store posts and pages. It distinguishes posts from page using pagetype attribute. Therefore, if you pass pagetype=page in the query_posts, what you will get is all the pages

query_posts('post_type=page&orderby=ID&order=ASC');

In the above query, I am getting all the pages, ordered ascending by their IDs

Creating Acegi Users in a script

      No Comments on Creating Acegi Users in a script

We are using Acegi plugin for Authentication and Authorization in Grails. We had to create users in bulk using MySql script. We have to know the encrypted password for each user, corresponding to the clear text password to insert in the database. (Acegi encrypts the password before storing it in the database).

I came across this nice post http://stackoverflow.com/questions/1472431/acegi-password-encryption

I was also thinking that Acegi must be using MD5, but after reading this post realized that it is SHA1 encryption.

You can get the sha1 encrypted password by issuing this command

echo -n password | openssl sha1

For eg. if your password is admin you can find encrypted password by issuing this command

echo -n admin | openssl sha1

Grails – Plugin file not found for plugin project

If you have just renamed your Grails plugin project and getting this error “Plugin file not found for plugin project” and wondering – “What’s going on?”

Consider this. Grails is based on DRY principle. Convention over configuration. By convention, the plugin descripor file should end in the word “GrailsPlugin”

Most likely it would have happened that you wanted to rename AbcDef grails plugin to say Abc plugin

In the process, instead of renaming AbcDefGrailsPlugin.groovy file in your plugin root directoy to AbcGrailsPlugin.grooy, you might have mistakenly renamed it to just AbcPlugin.groovy. Since the word GrailsPlugin was not in the name, it was considered as the normal project instead of Plugin project.

If you look inside $GRAILS_HOME/scripts/_GrailsPluginDev.groovy file, you can see the following code snippet


metadataFile.name,
 "*GrailsPlugin.groovy",

In short, the solution is to rename the file and the class defined inside it to AbcGrailsPlugin.groovy

Grails Maven Integration

      No Comments on Grails Maven Integration

Note: Information provided in this post may get outdated soon, because Grails, it’s plugin and dependencies gets updated very frequently.

Today I was trying to integrate my existing grails application with Maven. I had hard time with it. I referred to the following information

  • http://grails.org/Maven+Integration
  • http://forge.octo.com/maven/sites/mtg/grails-maven-plugin/examples/mavenize-a-grails-app.html

The pom generated by the plugin was of Grails 1.1 and I was using grails 1.1.1 therefore I had to make the following changes in my pom.xml


<dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-crud</artifactId>
 <version>1.1.1</version>
 </dependency>
 <dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-gorm</artifactId>
 <version>1.1.1</version>
 </dependency>

Since I was using MySql I had to add this too


<dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>3.1.14</version>
 </dependency>

Also you need to add this


<dependency>
 <groupId>org.tmatesoft.svnkit</groupId>
 <artifactId>svnkit</artifactId>
 <version>1.2.3.5521</version>
 <scope>runtime</scope>
 </dependency>

If you are not using Acegi then this is all you need to do for Maven integration. If you are using Acegi then you might have to make some more changes. In my case, I was getting ClassNotFoundException  for net.sf.ehcache.CacheException. I had to manually copy ehcache-1.3.0.jar from $MAVEN_REPOSITORY_HOME/repository/net/sf/ehcache/1.3.0 to $GRAILS_PROJECT_HOME/plugins/acegi/lib. It solved my issue and I was successfully able to run my grails app using mvn grails:run-app

As I said before, information in this post may get outdated very soon. But it solved my problem and it might solve your too.

Grails – No such property: save for class

      1 Comment on Grails – No such property: save for class

I suddenly started getting this message in my grails app. I don’t know the root cause of the problem. But for me the cause of the problem was removal of some fields and renaming of certain fields in domain class. If you have rename and/or removed some fields then make sure you follow these steps

  1. Stopped the running grails application. Changes made in the domains, controllers and other grails-app artifacts sometimes doesn’t get updated while application is running
  2. Remove and update the reference of the removed or renamed fields from the gsp, constraints block of domain, any other static blocks in referenced domains, messages.properties and other property files.
  3. If you are not using in-memory db(HSQL) and using mysql or any other persistent database, then corresponding columns of the renamed/removed old fields are not deleted from database. If it does not affect the already existing data in DB then drop the corresponding table. When you restart application, grails will create the table for you again. If your table has foreign key reference, then drop the database altogether and create new DB and grant all privileges to the user used by Grails.
  4. If the above steps don’t work for you and you are using grails 1.1.1 then try doing MyDomainClass.get(-1) in your Bootstrap.groovy. See http://grails.1312388.n4.nabble.com/No-such-property-save-for-class-td1389894.html

This solved my No such property: save for class issue. YMMV. In your case, the cause may be different.

Null message in Grails

      No Comments on Null message in Grails

I had a domain object

class Project{
    String projectTitle
    Rso rso
}

Where Rso itself is another domain object.

Both projectTitle and rso could not be blank or null.
when I tried
project.projectTitle.blank message in messages.properties, it worked

but
project.rso.null was not working.
I was trying project.rso.null because the default message was mapped as default.null.message.

Then someone suggested me to use
project.rso.nullable and it worked.