Installing Sphinx

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Tuesday, 27 January 2009

On Ubuntu Intrepid, this will get you Sphinx for rapid super-fast full-text searching.

sudo apt-get install libmysqlclient15-dev
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar -xzvf sphinx*.gz
cd sphinx*
./configure
sudo make
sudo make install

sudo gem install ultrasphinx

Tested and works ok

More here

Note about Ubuntu Installs

Had a bit of a problem with installing this on Ubuntu, RAKE just couldn't find the inspector and searchd binaries.

Found a way to fix this by configuring it like....

./configure --prefix=/usr/local/sphinx

Then doing the usual make and make install, but creating a symlink afterwards with

ln -s /usr/bin /usr/local/sphinx/bin

And then added a path to my .bashrc file, probably overkill after the first bit but got it working.

nano ~/.bashrc

Then adding...

PATH="$PATH:/usr/local/bin"
PATH="$PATH:/usr/local/sphinx/bin"
Missing Programs?

Note, if you're logged in as a normal user some system commands like smartctl will return command not found even though you know you installed them.

Just use sudo at the start and they should be found and run.

GeoCoding - Find Closest Neighbour

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Sunday, 18 January 2009

World Map

Today, after importing the geodata for all the postcodes in the UK I had to be able to determine which postcodes were in the closest vicinity to a fixed point.

This was a little work, the CSV wasn't in the best of condition; which had me banging my head against the wall with FasterCSV with it's stringent type ruling but eventually fixed that.

What I did was grab the first record that closely matches what I'm after and then build up the query to find it's closest neighbours.

zipcode = 'SW1'
distance = '100'

point = Geodata.find(:all, :conditions => ["postalcode = ?", zipcode], :limit => 1).first
puts point.postalcode

lng = point.longitude.to_f / 180 * Math::PI
lat = point.latitude.to_f / 180 * Math::PI

sql = "SELECT DISTINCT postalcode, place, 
  (6367.41*SQRT(2*(1-cos(RADIANS(latitude))*cos('#{lat}')*(sin(RADIANS(longitude))*sin('#{lng}')+cos(RADIANS(longitude))*cos('#{lng}'))-sin(RADIANS(latitude))* sin('#{lat}')))) 
  AS distance 
  FROM geodatas 
  WHERE (6367.41*SQRT(2*(1-cos(RADIANS(latitude))*cos('#{lat}')*(sin(RADIANS(longitude))*sin('#{lng}')+cos(RADIANS(longitude))*cos('#{lng}'))-sin(RADIANS(latitude))*sin('#{lat}'))) <= '#{distance}')
  ORDER BY distance"

results = Geodata.find_by_sql(sql)

results.each {|row| puts "postcode:#{row.postalcode} place:#{row.place} distance:#{row.distance.to_f.round}km"}

Probably still got some bugs but a stab in the right direction.

MySQL Add User + Grant Privelidges

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Wednesday, 07 January 2009

Create user

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

Grant rights specifically

GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost';

Or All at once

GRANT ALL ON *.* TO 'user1'@'localhost';

Or Create and Give rights all in one hit

INSERT INTO user (Host,User,Password,Select_priv,Insert_priv)

VALUES('localhost','user4',PASSWORD('pass3'),'Y','Y');

MAMP + Symfony

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Sunday, 21 December 2008

IronMan

Playing around with the Symfony framework for an interesting idea I have, sort of a Google Maps mashup.

Anyway, on OSX Leopard I'm using MAMP to handle the lamp environment and so need to supplement it's support with Symfony; which isn't too big a challenge to add.

Install MAMP on Leopard

First off download MAMP free here it's a 130mb download so you'll have to wait a while on a slow connection (we've got fibre so it's super quick). Once downloaded open & drag the MAMP folder into your Applications directory.

Next run up the MAMP application from within your /Applications/MAMP dir, this should give you MySQL running with these settings,

...location
Host: localhost
[Port: 8889]
User: root
Password: root

...via php
$link = mysql_connect('localhost', 'root', 'root');

...via sockets
Socket: /Applications/MAMP/tmp/mysql/mysql.sock
User: root
Password: root

...via php + sockets
$link = mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');
Add to PATH

Next using Terminal, add your PHP directory to your path by adding it to your .bash_profile file (need to reopen Terminal to read the new variable)

mate .bash_profile

Add this to the end of the file & save it,

export PATH=$PATH:/Applications/MAMP/bin/php5/bin

Check you've got PHP5 up and running by typing this at the Terminal, you should see PHP 5.2,

php -v
Install Symfony

Run these commands thru Terminal to install the Symfony framework into your PHP install,

/Applications/MAMP/bin/php5/bin/peardev channel-discover pear.symfony-project.com
/Applications/MAMP/bin/php5/bin/peardev install symfony/symfony

Now check you've got Symfony installed by typing this into the Terminal,

symfony -V

Next grab the Sandbox application to start with via here and extract it into the default root dir of your PHP install; being MAMP this will be:

/Applications/MAMP/htdocs

Afterwhich via your web browser you should be able to test the sandbox app at:

http://localhost:8888/sf_sandbox/web/frontend_dev.php/
Create your First Project

The Symfony framework provides an excellent starter for your application, with the data, app code, cache and logs all stored within a design much like Rails and it's MVC pattern so you can get up & running fast.

So to create your application do,

mkdir ~/myproject
cd ~/myproject
symfony init-project myproject

Note the symfony command must be run within the directory you want your app put together so create a directory for it first, move into it then run the line above.

And within MAMP,

mkdir /Applications/MAMP/htdocs/myproject
cd /Applications/MAMP/htdocs/myproject
symfony init-project myproject
Add your Application

Now you won't able to see anything until you've created your first app within myproject via,

symfony init-app myapp

This will create some files to get you up & started along with a simple index.php file within the /web dir to show things went ok,

http://localhost:8888/myproject/web/index.php

You'll probably get a message saying it can't find your application's web/sf directory for the images, as you've already got the sandbox app installed, copy it from there.

cp -R /Applications/MAMP/htdocs/sf_sandbox/web/sf /Applications/MAMP/htdocs/myproject/web/sf

Or from your original PEAR install,

cp -R /Applications/MAMP/bin/php5/lib/php/data/symfony/web/sf /Applications/MAMP/htdocs/myproject/web/sf

Your project should be much happier now.

Obviously you shouldn't be sticking your projects entire framework inside your /htdocs directory for production as it'll make the whole thing visible to the outside world but for this simple example it'll do for now.

But if you really want to you can edit your Apache's document root directory via the Apache config file:

mate /Applications/MAMP/conf/apache/httpd.conf

And change,

DocumentRoot "/Applications/MAMP/htdocs"
...to
DocumentRoot "/Applications/MAMP/htdocs/myproject/web"

Simple for now but you can expand on it later with virtual server configs and the like later.

More on this via Symfony's official documentation here

MATE ?

...please note i've got TextMate installed along with the path integration so I can access it via Terminal with mate so if you don't have TextMate, substitute mate for nano or vi if you're old-school ;-)

Installing Memcached on Debian Etch

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Tuesday, 02 December 2008

Unfortunately this takes a bit of work, the one in the etch repositiories is too old so you're going to have to build you're own sources and install manually.

Add Repository / Increase Cache Limit

So first off add the testing repository to your list of sources

cd /etc/apt
sudo nano sources.list

Then add the testing repository (here for the UK) and save the file

deb-src http://ftp.uk.debian.org/debian/ testing main

Now before you update your sources list increase the size of the package cache by,

nano /etc/apt/apt.conf

And add,

APT::Cache-Limit "16777216";

...now when you update your packages cache you shouldn't get an out-of-space error, finally update

sudo apt-get update
Build Packages

First create & move to your sources dir

mkdir /sources
cd /sources

Next grab the tools needed to compile the sources

sudo aptitude install devscripts

Next we'll check if we need anything extra for libevent

sudo apt-get build-dep libevent

And grab & build the libevent source

sudo apt-get source libevent
cd libevent-1.3e
sudo debuild -us -uc
cd ..

Then install libevent and it's development package

sudo dpkg -i libevent1_1.3e-3_amd64.deb
sudo dpkg -i libevent-dev_1.3e-3_amd64.deb

Next we'll test if there are any build dependencies for memcached

sudo apt-get build-dep memcached

Then grab & build the memcached source

sudo apt-get source memcached
cd memcached-1.2.2
sudo debuild -us -uc
cd ..

Finally install memcached

sudo dpkg -i memcached_1.2.2-1_amd64.deb

You should now have a working install of Memcached 1.2.2 on Debian Etch.

MySQL 5 on Leopard with MacPorts

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Monday, 24 November 2008

Setup Notes

Install MySQL5 via MacPorts

sudo port clean mysql5
sudo port install mysql5 +server

If you've already got an existing installation via macports use this to remove it (it'll give you a list of specific versions installed, use that name)

sudo port uninstall mysql5

After it's installed and activated, run this to add MySQL to your Daemons list so it'll auto-start on bootup

sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.mysql5.plist

Now build the user tables

sudo mysql_install_db5 --user=mysql

Next move the MySQL config file so other services can find it easier,

sudo mv /opt/local/share/mysql5/mysql/my-medium.cnf /opt/local/etc/mysql5/my.cnf

Now open it in NANO so we can set specifically which port, etc, it runs with (so you're other programs can access it)

sudo nano /opt/local/etc/mysql5/my.cnf

Add this to the start of your MySQL config,

This'll be the start of your initial config file...

#password       = your_password
port            = 3306
socket          = /opt/local/var/run/mysql5/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /opt/local/var/run/mysql5/mysqld.sock

Edit it to be similar to this...

[mysqld_safe]
socket          = /tmp/mysql.sock

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock

Save & Close the file (CTRL+X choose Y and Enter)

Now re-start MySQL

Setup MySQL 5

sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

sudo chown -R mysql /opt/local/var/db/mysql5

Set Password

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'password' /opt/local/lib/mysql5/bin/mysqladmin -u root -h john-griffithss-macbook.local password 'password'

Start MySQL5

cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

Test Daemon

cd mysql-test ; perl mysql-test-run.pl