Sunday, February 12, 2012

Installing Rails 3.1.1, ruby 1.9.3, apache2, Passenger and Mysql on Ubuntu 11.10

To install Rails 3.1 on  fresh Ubuntu 11.10 I followed the following steps.


Note:
Currently I am running Ubuntu on a Virtual Machine (VMware Player )


Step 1: Install  libYAML from source
cd /usr/src
sudo wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
sudo tar xvzf yaml-0.1.4.tar.gz
cd yaml-0.1.4
sudo ./configure --prefix=/usr/local
sudo make 
sudo make install


Step 2: Install  required libraries
 sudo apt-get install libxml2-dev libxslt-dev libzlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient16-dev


Step:3 Install ruby  from source file
cd /usr/src
sudo wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
sudo tar xvzf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
sudo ./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
sudo make
sudo make install


Step:4 Test proper ruby is installed
sudo ruby -v
The above command should display some thing as follows
ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]


Step 5: Install ruby gem
cd /usr/src 
sudo wget http://rubyforge.org/frs/download.php/75475/rubygems-1.8.11.tgz
sudo tar xvzf rubygems-1.8.11.tgz
cd rubygems-1.8.11
sudo ruby setup.rb


Step 6: Install Mysql server and Mysql client
sudo apt-get install mysql-server-5.1 mysql-client-5.1

Step 7: Install rails
sudo gem install rails


Step 8: Install apache2
sudo apt-get install apache2


Step 9: Install passenger
cd /usr/src 
sudo wget http://rubyforge.org/frs/download.php/75337/passenger-3.0.9.tar.gz
sudo tar xvzf  passenger-3.0.9.tar.gz
cd passenger-3.0.9
sudo ./bin/passenger-install-apache2-module  
Follow the instruction provided by the installer and restart the apache


Step 10: Install Node.js 
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs-dev


Step 11: Install readline library 
sudo apt-get install libreadline6-dev
cd /usr/src/ruby-1.9.3-p0/ext/readline
sudo ruby extconf.rb
sudo make
sudo make install


Step 12: Testing rails application
 a. create a new rails project. My project directory is /var/projects
     cd /var/projects
   sudo rails new demo --database=mysql
 b. create mysql database
     sudo mysql -u root -p 
     It prompts mysql password and provide the one which you provide at the time of
      installing Mysql server
     mysql> create database demo_developement;
  mysql> exit


c. Install  vim editor (optional) if  you are fond of vim
    sudo apt-get install vim vim-rails


 d. Update database.yml file
     cd /var/projects/demo
      Open database.yml and update 'password' attribute by using following command
      sudo vim config/database.yml


 e. Update apache configuration file and  update the virtual host entry shown below and restart
    sudo vim /etc/apache2/sites-enabled/000-default


  <VirtualHost *:80>
      ServerName localhost
      DocumentRoot /var/projects/demo/public
      RailsEnv development
      <Directory /var/projects/demo/public>
         AllowOverride all
         Options -MultiViews
      </Directory>
   </VirtualHost>
  sudo /etc/init.d/apache2 restart
f. Create log files
  sudo touch /var/projects/demo/log/development.log

Note:
1. You may get permission denied error something like
    "Permission denied - /var/projects/demo/tmp/cache/assets/CF0"
    To resolve this just give read and write permission for this folder. You can use the following command for   
     development environment
    sudo chmod 777 /var/projects/demo/tmp/cache/assets

2. To view apache log files you can use the following command
  sudo tail -f /var/log/apache2/error.log -n 100
     where "-n 100" denotes last 100 lines of error.log file

3. For installing Rails using RVM follow this blog


Reference:

Sunday, February 5, 2012

Some useful Git commands and resources



Git Cheat Sheets


Enable GIT colors commands

  • git config --global color.diff auto
  • git config --global color.status auto
  • git config --global color.branch auto
  • git config color.interactive auto
  • Or, you can set all of them on with the color.ui option:
  • git config color.ui true

Creating & pushing new branch

  • First, you must create your branch locally
  • git checkout -b your_branch
  • push the branch to the remote repository origin and tracks it
  • git push -u origin your_branch

listing all files in a commit:

$ git show --pretty="format:" --name-only bd61ad98

Restoring a deleted file in a Git repo:

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

Wireless enabling on Ubuntu

just install b43-fwcutter:
  • sudo apt-get install b43-fwcutter

working with DateTime instances in Doctrine 2

DateTime changes are detected by Reference

When calling EntityManager#flush() Doctrine computes the changesets of all the currently managed entities and saves the differences to the database. In case of object properties (@Column(type=”datetime”) or @Column(type=”object”)) these comparisons are always made BY REFERENCE. That means the following change will NOT be saved into the database:
<?php
/** @Entity */
class Article
{
    /** @Column(type="datetime") */
    private $updated;

    public function setUpdated()
    {
        // will NOT be saved in the database
        $this->updated->modify("now");
    }
}
The way to go would be:
<?php
class Article
{
    public function setUpdated()
    {
        // WILL be saved in the database
        $this->updated = new \DateTime("now");
    }
}​

Refere​nce:
http://www.doctrine-project.org/docs/orm/2.0/en/cookbook/working-with-datetime.html

Multiple virtual hosts with Apache (on windows)

Creating multiple virtual hosts using apache is so common, you may find making it so easy and straight forward on Linux or even Mac, but believe me it is not the case with Windows !​


   Here is the deal, the idea behind how to make this is to give another IP for your new host, and make apache listen on that IP, let's do it:

Step 1: add your new host in the hosts file under "C:\Windows\System32\drivers\etc​" and assign new IP to it:
  1. 127.0.0.1       localhost  
  2. 127.0.0.2       mysite.com  
Step 2: make your apache server listens on the new IP by modifying httpd.conf file in the "apache\conf" folder, put the following in the Listen section:
  1. Listen 80  
  2. Listen 127.0.0.2:80  
Step 3: and finally, open "apache\conf\extra\httpd-vhosts.conf" and add your new virtual hosts like this:
  1. <virtualhost mysite.com:80>
  2. DocumentRoot "absolute_location_to_mysite_public_folder"
  3. ServerName Boston.com
  4. ServerAlias boston.com
  5. <directory "absolute_location_to_mysite_public_folder">
  6. AllowOverride All
  7. Options Indexes FollowSymLinks
  8. Order allow,deny
  9. Allow from all
  10. </directory>
  11. </virtualhost>

  12. <virtualhost localhost:80>
  13. DocumentRoot "apache_htdocs_folder"
  14. ServerName localhost
  15. ServerAlias localhost
  16. <directory "apache_htdocs_folder">
  17. AllowOverride All
  18. Options Indexes FollowSymLinks
  19. Order allow,deny
  20. Allow from all
  21. </directory>
  22. </virtualhost>








Finally, you can use the two hosts in your browser:
  • localhost
  • mysite.com

Problem running Zend commands inside NetBeans (solved)

When trying to run zf commands inside Netbeans
it didn't work until I did the following:
    1. ​Using cmd I created the .zf.ini file using the script​ "zf --setup fonfig-file"
      1. .zf.ini is in your user directory like in windows: "C:\Users\abdelhady_mohammed"
    1. Then I opened netbeans and from tools>Options>php>Zend, then choosed "Register Provider"
    2. Right click the project Zend>run command and choose "Refresh Commands"
And here we go, every thing is Ok inside Netbeans

Then I tried to run zf commands again on windows command line:
And here comes the bug, zf commands is no longer runnable on windows command line and here is the full bug report on Netbeans site:

Solution:
get the "NetBeansCommandsProvider.php" located in "D:\Boston_Dev_Env\NetBeans\php\zend"
and copy it to the Zend Library folder "D:\Boston_Dev_Env\server\ZendFramework-1.11.7\library"

and every thing will be fine then

Additional reference:
http://www.kilinjal.com/blog/how-configure-zend-tool-netbeans?page=show

Installing PhpUnit manually for PEARLESS people ( on windows)

PHPUnit

The first thing is to download and extract PHPUnit, download the file, unzip it and place the resulting folder in
1 C:\wamp\bin\php\php5.2.9-2\
(I renamed the folder from PHPUnit-3.5.4 to phpunit but its up to you. You can also put the folder anywhere you want, so long as you amend the include path instruction below).

PHP.ini

With the PHPUnit files extracted, we need to alter our php.ini file to have an include path of our PHPUnit directory, add the following line to the appropriate section of the php.ini file.
1 include_path = "C:\wamp\bin\php\php5.2.9-2\phpunit"

Dependancies

Because I didn't/couldn't/wouldn't install this through PEAR, there were quite alot of dependancies missing, which was frustrating considering the manual installation instructions didn't mention this. I also found, that these dependancies had to be extracted to the (root) phpunit folder, and not the PHPUnit folder within there (which is where I'd initially put them - to a further series of errors!). Download the following dependancies, and extract them to the root phpunit folder (i.e. C:\wamp\bin\php\php5.2.9-2\phpunit).
  • PHP/CodeCoverage (copy the PHP folder and its contents)
  • PHP/Timer (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancy))
  • PHP/TokenStream (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancies))
  • Text/Template (copy the Text folder and its contents)
  • File/Iterator (copy the File folder and its contents)

The bat (cave) file

Since we are running on Windows, to run PHPUnit, we can't simply rename phpunit.php to phpunit and run it (as per the instructions), we instead run the phpunit.bat file. The bat file in turn runs the PHP executable, and opens the phpunit.php file with it.
Open the phpunit.bat file, and replace its contents with the following (replacing paths to php.exe and phpunit.php with your own systems paths).
1 C:\wamp\bin\php\php5.2.9-2\php.exe -d safe_mode=Off "C:\wamp\bin\php\php5.2.9-2\phpunit\phpunit.php" %*

phpunit.php

Within the phpunit.php file you need to replace @php_bim@ with the path to your php directory (as per the documentation)
1 C:\wamp\bin\php\php5.2.9-2

Running PHPUnit

Now simply open the command prompt, browse to your phpunit folder, and run phpunit followed by the file path of your tests.

Reference:
http://www.michaelpeacock.co.uk/blog/entry/phpunit-on-wamp​

Portable Netbeans

 Simply do this:
  • Make sure you have the same JDK installed (in the same paths) on the machines where you use the USB drive - or copy the JDK on the drive too. The same applies to web servers / version control systems / runtimes, whatever is applicable.
  • Download the OS-independent.zip distribution of NetBeans. Unpack it on your usb stick.
  • The directories you need to copy are the netbeans userdir (.netbeans directory), and of course your project directories.
  • Check whether you have a global netbeans.conf file: If yes, make certain it is identical to the one in your userdir to prevent unexpected behaviour in either environment.
  • In your netbeans installation directory, open /etc/netbeans.conf in a text editor.
  • Change netbeans_default_userdir="${HOME}/.netbeans/6.5rc2" to something like
    netbeans_default_userdir="X:/.netbeans/6.5" 
    assuming X is your USB sticks drive name.
  • Change the path to the JDK from #netbeans_jdkhome="/path/to/jdk" to e.g.
    netbeans_jdkhome="X:/jdk"
    Make sure to remove the hashsign (comment).
Reference: