Monday, August 2, 2010

Existing PHP / Ruby not working with MySQL installed with 'sudo port install'

By Default OSX 10.x contains PHP & Ruby installed already. I wanted to make work few applications which used MySQL, PHP & Ruby. So to do this, I installed Xcode & MacPorts too. Then installed mysql using 'sudo port install' and installed successfully. But when I executed the applications, I found that neither PHP nor Ruby could know which mysql.sock can be used to make the existing application work. After a deep search found that port install uses different location and stores the mysql socket. I tried to edit the php.ini file to make sure that it gets connected to the existing socket, but still it didn't worked.

When executed the PHP code I got this warning "Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /Users" but without this solved I can't connect to DB and get the code working.

When I tried with Ruby also it gave me some weird error "ruby `initialize`: wrong number of arguments (4 for 0) (ArgumentError)" and I got frustrated little bit.

So instead of debugging more I thought I can remove the existing PHP & Ruby and install them using the port install command. So I followed the few steps like mentioned below:

sudo mv /System/Library/Frameworks/Ruby.framework/Versions/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8.dead

sudo port install ruby
sudo port install rb-rubygems

sudo mv /usr/bin/ruby /usr/bin/old_ruby
sudo mv /usr/bin/gem /usr/bin/old_gem
sudo ln -s /opt/local/bin/ruby /usr/bin/ruby
sudo ln -s /opt/local/bin/gem /usr/bin/gem

sudo gem update --system

sudo gem install xml-simple
sudo gem install mysql

sudo port install php5
sudo port install php5-mysql
sudo port install php5-mbstring

sudo cp /opt/local/etc/php5/php.ini-production /opt/local/etc/php5/php.ini

locate mysqld.sock
==> /opt/local/var/run/mysql5/mysqld.sock (mostly this will be)

sudo vim /opt/local/etc/php5/php.ini

and change all mysql & mysqli default_socket = /opt/local/var/run/mysql5/mysqld.sock

sudo mv /usr/bin/php /usr/bin/old_php

The above commands will rename the existing PHP & Ruby and uses the new Ruby & PHP installed using the port install commands. After updating the php.ini my existing code worked perfectly as though there were no issues. Even the Ruby also didn't gave me any error, even that too worked fantastically.

I hope this will help you to resolve your problem easily rather than debugging the issue which might eat up your time.

Friday, July 30, 2010

Uninstall Ruby / PHP in existing Mac OS

Hi Guys, posting this after a long period as was little busy ;-). Anyways lets get into the subject.

Whenever OSX 10.x version installed, by default PHP / Ruby will also be installed. This is good but sometimes we don't want the particular version installed so to remove this we need to do the following steps.

For Ruby
sudo mv /System/Library/Frameworks/Ruby.framework/Versions/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8.dead
sudo mv /usr/bin/ruby /usr/bin/old_ruby
sudo mv /usr/bin/gem /usr/bin/old_gem

For PHP
sudo mv /usr/bin/php /usr/bin/old_php

Wednesday, April 21, 2010

Drupal: Drush + CCK Import Module Code

I was trying to figure out if there are any modules which I can download for the Drupal 6 and try to use Drush command to do an CCK Import of a file which has been exported thru CCK Export. After a hard dig around, I couldn't find any one, so I started writing my own. Don't worry I have shared the code below. Anyway talks apart, below is the code which you put in a file called drush/commands/cck_import/cck_import.drush.inc




// $Id: cck_import.drush.inc,v 1.1 2010/04/21 03:03:39 kishore Exp $

/**
* @file
* Drush support for cck_import.
*/

/**
* Implementation of hook_drush_command().
*/
function cck_import_drush_command() {
$items = array();

$items['cck_import-import'] = array(
'callback' => 'cck_import_drush_callback_import',
'description' => "Import node code from a previous export.",
'options' => array(
'--uid' => "Uid of user to save nodes as. If not given will use 1. You may specify 0 for the Anonymous user.",
),
'examples' => array(
'drush cck_import import < filename' =>
'Import nodes from given filename.',
),
);

return $items;
}

/**
* Implementation of hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help '
*
* @param
* A string with the help section (prepend with 'drush:')
*
* @return
* A string with the help text for your command.
*/
function cck_import_drush_help($section) {
switch ($section) {
case 'drush:cck_import-import':
return dt("Imports nodes that have been exported. Usage: 'drush cck_import import < filename'.");
}
}

/**
* Drush command callback.
*
*/
function cck_import_drush_callback_export() {
$commands = func_get_args();

$nids = array_filter($commands, 'is_numeric');

$data = cck_import_node_bulk($nids, TRUE);

$filename = drush_get_option('file');

if ($filename) {
// Output data to file. Note this only takes a flat filename for the current directory.
// If file exists, ask for whether to overwrite
if (file_exists($filename)) {
if (!drush_confirm(dt('File ' . $filename . ' exists. Do you really want to overwrite?'))) {
return;
}
}
// Write the file.
file_put_contents($filename, $data);
}
else {
// Print to terminal.
drush_print_r($data);
}
}

/**
* Drush command callback.
*
* Import nodes from data.
*/
function cck_import_drush_callback_import() {
$commands = func_get_args();

// Switch to admin or the specified user so imported nodes are not anonymous.
$uid = drush_get_option('uid');
// Test on NULL so uid may be given as 0.
if (is_null($uid)) {
$uid = 1;
}
// uid 0 is already loaded.
if ($uid != 0) {
global $user;
$user = user_load($uid);
}

$values = array();
$values['type_name'] = '';
$values['macro'] = file_get_contents("php://stdin", "r");
$form_state = array();
$form_state['values'] = $values;
if (!empty($form_state)) {
$result = drupal_execute("content_copy_import_form", $form_state);
if ($result === FALSE) {
// There was a problem with types?
drush_set_error('DRUSH_NOT_COMPLETED', 'Problem found with the import file. Check the node types exist.');
}
}

}




After saving this file, try to execute the below command



$ drush cck_import-import < filename.content



note filename.content should contain something which has been exported from the CCK Export.

Hope this would have solved your issues, I am in the process of developing the CCK Import / Export thru Drush commands and might update you soon with other version of the code. Not sure where to publish but thought of publishing in my own blog and in future might publish in a proper particular location where everybody gets benefited.

Feel free to ask me any queries.

Thursday, April 1, 2010

Gmail - April Fool


Hope everybody trying to find out what is the April Fool prank Google is going to play this time. Here G-King played the prank April Fool. GMail application misses all the vowels and wants people to think that there is some virus / some flaw in user's computer.. ;-) might be bad guess..

Anyway here is the screenshot of GMAIL Disemvowelling

Wednesday, November 11, 2009

Remove Extended attributes present in file permission in Mac OS

Hi Guys,

For the past two days I was struggling to get rid of the '@' character which is appended in the permission for a file whenever used using the TextMate Editor in the Mac OS. I opened TextMate Editor and created a file called "test.txt" which is created successfully but unfortunately the permissions saved are


-rw-r--r--@ 1 kishorekumar admin 5 Nov 11 13:56 test.txt


Now I felt strange regarding this why this @ came and what is that exactly. Later after two days of digging I found the answer and now I am relaxed. Oops sorry to continue my story.. continuing back..

What I understood regarding the '@' is that it is file extended attributes for the Mac files. You can see them with the -@ flag to ls, or with the new xattr command:


ls -al test.txt
-rw-r--r--@ 1 kishorekumar admin 5 Nov 11 13:56 test.txt



ls -al@ test.txt
-rwxr-xr-x@ 1 kishorekumar admin 11614 Nov 11 12:27 test.txt
com.macromates.caret 35



xattr -l test.txt
com.apple.FinderInfo:
0000 00 00 00 00 54 78 4D 74 00 00 00 00 00 00 00 00 ....TxMt........
0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

com.macromates.caret: {
column = 7;
line = 295;
}


So now, how to get rid of the '@' and the com.apple.FinderInfo & com.macromates.caret so here is the simple and fastest solution which works faster.

To Disable the Extra Attributes which gets attached to the file is just run this below command in the Terminal.

defaults write com.macromates.textmate OakDocumentDisableFSMetaData 1


To Enable the Extra Attributes which gets attached to the file is just run this below command in the Terminal.

defaults write com.macromates.textmate OakDocumentDisableFSMetaData 0


Note: Make sure that you restart the TextMate Application else it might not work perfectly.

Hope this might help you easily. If not please let me know I will try to help you :-)