Sunday, 9 December 2012

Tutorial: Migrate Drupal app from GoDaddy to localhost on Ubuntu

I wanted to set up an exact copy of a hosted Drupal instance (on GoDaddy) without actually changing any code on production, which meant I had to set up my local environment on a fresh Ubuntu install. I've documented the process so hopefully whoever is doing the same thing won't run into the same issues I did. 
The versions I used for this tutorial:
Drupal 7.17
Apache2 2.2.22
Ubuntu 12.10
PHP 5.4.6-1ubuntu1.1
MySQL 5.5.28-0ubuntu0.12.10.1

The following procedures were done:

1.) Copy over the existing database. This can be done using the phpMyAdmin tool. It's pretty self-explanatory and I didn't encounter any problems with it.
2.) Get apache, mysql, php5. Just follow the instructions on the following page. Create the database user/password with the same as your hosted instance. https://help.ubuntu.com/community/ApacheMySQLPHP 
3.) Restore the database. Pretty self-explanatory
4.) FTP the files to your local.
5.) Create GIT repo (optional) I want to track my changes against the baseline, so I just created a local git repo
git init && git add . && git commit -m "init commit"
6.) Edit the drupal settings file Because the settings point to the hosted database, you need to change it.

 * @code
 * array(
 *   'driver' => 'mysql',
 *   'database' => 'databasename',
 *   'username' => 'username',
 *   'password' => 'password',
 *   'host' => 'localhost',
 *   'port' => 3306,
 *   'prefix' => 'myprefix_',
 *   'collation' => 'utf8_general_ci',
 * );
 * @endcode
7.) Change your apache configs My site was hosted on the root context, so to mimick the same behavior, edit your apache config file:
tchan@tchan-PC:/etc/apache2/sites-available$ cat default


        ServerAdmin webmaster@localhost

        DocumentRoot /home/tchan/repo/socialworkportal/
        
                Options FollowSymLinks Indexes
                AllowOverride All
        
        
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined


Note the DocumentRoot, the Directory, and the AllowOverride (set to All)
8.) Set the correct permission to your directory For ubuntu the group it uses it root, so do something like this:
cd ~/repo && chgrp root socialworkportal
9.) Enable mod_rewrite This is so that Drupal can enable the .htaccess files for cleaner urls
sudo a2enmod rewrite && sudo service apache2 restart
10.) Check for any problems in status report. Login using your admin account, then click Reports -> Status Reports. Fix any issues that come up. For me cTools and File System had permission issues. Just change it to the correct permission. For me the following fixed it:

tchan@tchan-PC:~/repo/socialworkportal/sites/default$ chmod 777 files/
tchan@tchan-PC:~/repo/socialworkportal/sites/default/files$ chmod 777 ctools/

2 comments: