Friday 21 December 2012

Set up x11vnc on ubuntu 12.10 as a startup item

I just installed a brand new instance of Ubuntu 12.10 and was trying to get my x11vnc to be a startup application.

In order to acheieve that, I first had to set up a password with the following command:

x11vnc -storepasswd

After that you enter a password.

Now click on the Windows icon and type 'startup'. From there enter a new command as a new task:

x11vnc -usepw

Voila!

Thursday 20 December 2012

Drupal 7: Not being able to see front page content

I'm new to Drupal and to be honest it's not my first choice of a CMS, but I have a low budget client so I have to use it. It sucks because in part I don't actually have to do too much coding and in part because there are so many configuration options.

For example, I was trying to enable the home page of the app so anyone can view it. However that didn't seem possible initially. Then I heard of the Access Control plugin, which I installed and had configured it correctly, but it still didn't work! What gives??

It turns out that there is a overriding flag that restricts the access of published content. To fix this, goto People -> Permission -> View Published Content, and check the Anonymous checkbox. Then the access control plugin will work.


Change your fonts in Intellij to make it look like Eclipse!

I've been working with Intellij for awhile now and I must say that for Groovy/Grails development it beats the default Eclipse or STS IDEs.

The one quirk (up until now) that I have is that the fonts look horrible. Well no more.

Thanks to http://722.kalaari.net/b/lang/fr/2012/09/30/improve-font-rendering-under-linux-for-your-favorite-java-ide/ we now can change the fonts to look like Eclipse.

Set GTK+ in appearance, and
export this: export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true"

Ubuntu 12.10 - Kernel driver not install (rc=-1908)

I keep getting this error when I try to run virtual box Please install the kernel module by executing 'etc/init.d/vboxdrv setup' the solution: sudo apt-get install linux-headers-3.5.0-21-generic sudo apt-get remove virtualbox sudo apt-get install virtualbox sudo apt-get install virtualbox-ose-dkms

Wednesday 19 December 2012

Grails - Integration testing with the REST plugin using SSL (HTTPS)

I was writing a few integration tests in a Grails application which used the REST plugin to call out to an HTTPS (SSL) endpoint. In Config.groovy, we had this defined:

rest.https.truststore.path='truststore.jks'

rest.https.truststore.pass='asdf'

rest.https.keystore.path='keystore.jks'

rest.https.keystore.pass='asdf'

rest.https.cert.hostnameVerifier = 'ALLOW_ALL'

rest.https.sslSocketFactory.enforce = true



I knew for a fact that this works because when I run the test individual it is fine. However, when I run it via the command

grails test-app integration:



However, I keep getting errors while running the test.


Upon looking at the source of the plugin, I realized that the plugin is still using the ConfigurationHolder class for reading its configuration, which has been deprecated since version 2.0.0. It seems that the context inside the ConfigurationHolder object is not the same as what's in the grailApplication variable.

So to fix the issue, I had to declare the values declaratively (unfortunately).

   @Before
    public void setUp() {
        //need to override as the rest plugin isn't using the grailApplication variable.
        ConfigurationHolder.config.rest.https.truststore.path='truststore.jks'
        ConfigurationHolder.config.rest.https.truststore.pass='asdf'
        ConfigurationHolder.config.rest.https.keystore.path='keystore.jks'
        ConfigurationHolder.config.rest.https.keystore.pass='asdf'
        ConfigurationHolder.config.rest.https.cert.hostnameVerifier = 'ALLOW_ALL'
        ConfigurationHolder.config.rest.https.sslSocketFactory.enforce = true
        super.setUp()
    }





The ideal way to fix this is to monkey patch the rest plugin to use the grailsApplication. However I didn't want to deal with the headache of a custom patched plugin in our project.

Sunday 9 December 2012

Troubleshooting PHP XDebug

It's been awhile since I set up XDebug for PHP.

I wanted to do it so I can step through some code one of my clients have prepared.

I found that in general it was hard to set up debugging, but it sure saves you a ton of time while troubleshooting. Anyways it seems that the installation guide provides you with 80% of what you need, but leaves 20% out.

Note that the installation instructions are for Ubuntu 12.10

To get the first 80%: Follow install instruction located below
http://xdebug.org/docs/install

To get the last bit working: I came across a few issues.
First was that php cli didn't see xdebug. This isn't a problem if you're using the apache php, but to complete and not run into problems in the future, solve this problem paste the following a new file /etc/php5/conf.d/xdebug.ini

; xdebug debugger
zend_extension="/usr/lib/php5/20100525/xdebug.so"

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
PHP will automatically scan that conf.d directory and pick up the config. Restart apache, and check that phpinfo() has the correct info.
Do a Ctrl + A and paste it into checker wizard: http://xdebug.org/wizard.php
Make sure there aren't any problems with it.

The second issue was related to my IDE. I was using PHPStorm and you actually have to create a server first by going to File -> Settings -> PHP -> Servers, and adding a new Server. Put localhost and port 80. After those two additions it now works like a charm!

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/

12.10 Hanging at checking battery state

Solved! Took me a bit of time to find out why. I just install a new superfast Samsung SSD and apparently the checking order is incorrect, leading to issues with Ubuntu. Solution: sleep 1 && service lightdm restart /etc/rc.local http://ubuntuforums.org/showthread.php?t=2073483&page=3

Make Ccumber fail if step is missing

make cucumber fail if step is missing in your runner, just use --strict

Setting up a symlink on apache and Ubuntu

I'm starting a client project which uses LAMP stack. However, instead of putting the source file in /var/www, I wanted to create a symlink in that directory that brings me to the actual source directory. So first thing I did was:
ln -s ~/repo/socialworkportal /var/www
Pretty standard stuff. However when I tried to hit the path localhost/socialworkportal it gave me a forbidden error. Then I thought it was an issue with the permission -- after all the dir /var/www had root:root permissions. Okay, then I did this:
cd ~/repo && chgrp root socialworkportal
Still didn't work! Solution: So apparently Apache needs execute rights to the path of your directory, so something like this was needed: chmod o+rx /home/me /home/me/repo Hope that helps! Reference for chmod: http://www.washington.edu/doit/Newsletters/Jul97/15.html