Monday, August 19, 2013

Installing Go Lang 1.1 on centos 6.4 *64-bit

UPDATE: 28/Apr/2014 - Golang package is now available on Fedora EPEL Repository. You can just configure EPEL repo and do a "yum install golang".

I have added go-lang package to the current repository. So you can try installing it using the following steps.

1. Install centos 6.x

2. Download and setup Fedora EPEL Repository

sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

(Step-3 not needed, if you are seeing this on Apr/2014)

3. Setup hop5.in repository


cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo

4. Install go package

sudo yum install golang

5. Write a simple "hello world" program to get started with go

[nareshv@fallenangel tmp]$ cat hello.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World.")
}
[nareshv@fallenangel tmp]$ go run hello.go
Hello, World. 

6. Continue exploring go-lang, from here

(Note is not applicable if you are using golang from EPEL Repository)

Note: Please note that, go-lang is compiled without emacs support (to avoid pulling tons of packages) and with gcc-4.6.3.

Monday, July 15, 2013

Installing HHVM (Hiphop PHP) 2.1.0 On Centos 6.x

HHVM 2.1.0 was released a day ago (as of writing this blog).  In order to install this stable version on your server / development environment. Follow these steps

1. Configure the Repository as mentioned in my previous post

2. Upgrade to the latest version

sudo yum update hiphop-php

3. Confirm that the package is installed correctly

/usr/bin/hhvm --help

NOTE: You need to re-build your we-application (if you are using repo-authoritative mode) with the current version and then only upgrade your production server, or else you might not have this application working correctly.

Have fun with this stable version.

Saturday, July 13, 2013

Wednesday, July 10, 2013

Install TokuDB Mysql Server along with Existing mysql-server on Centos/Ubuntu Server

Tokudb has fractal tree engine which is mentioned to perform bettern than innodb in certain instances. In some scenarios you might want to run mysql-server which is patched with tokudb engine along with your current mysql server (for performance testing, evaluation etc).

A straightforward installation will mess up /var/lib/mysql, so follow these instructions to make sure that the server installation doesn't mess up existing installation.

1. Download and unzip the tokudb to /usr/local/

nareshv@fallenangel:~/Downloads$ sudo mv mysql-5.5.30-tokudb-7.0.1-linux-x86_64 /usr/local/
nareshv@fallenangel:/usr/local$ sudo ln -s mysql-5.5.30-tokudb-7.0.1-linux-x86_64 mysql
nareshv@fallenangel:/usr/local$ cd mysql
nareshv@fallenangel:/usr/local/mysql$ ls -l
total 80
drwxrwxr-x  2 nareshv nareshv  4096 Apr 19 04:57 bin
-rw-r--r--  1 nareshv nareshv 17987 Apr 19 03:11 COPYING
drwxrwxr-x  4 nareshv nareshv  4096 Apr 19 04:57 data
drwxrwxr-x  2 nareshv nareshv  4096 Apr 19 04:57 docs
drwxrwxr-x  3 nareshv nareshv  4096 Apr 19 04:57 include
-rw-r--r--  1 nareshv nareshv  7469 Apr 19 03:11 INSTALL-BINARY
drwxrwxr-x  3 nareshv nareshv  4096 Apr 19 04:57 lib
drwxrwxr-x  4 nareshv nareshv  4096 Apr 19 04:57 man
drwxrwxr-x 10 nareshv nareshv  4096 Apr 19 04:57 mysql-test
-rw-r--r--  1 nareshv nareshv  2552 Apr 19 03:11 README
-rw-r--r--  1 nareshv nareshv  3659 Apr 19 04:52 README-TOKUDB
drwxrwxr-x  2 nareshv nareshv  4096 Apr 19 04:57 scripts
drwxrwxr-x 27 nareshv nareshv  4096 Apr 19 04:57 share
drwxrwxr-x  4 nareshv nareshv  4096 Apr 19 04:57 sql-bench
drwxrwxr-x  2 nareshv nareshv  4096 Apr 19 04:57 support-files

2. Install the mysqlserver to /usr/local/mysql (not /var/lib/mysql)

nareshv@fallenangel:/usr/local/mysql$ sudo -u mysql ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h fallenangel password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

3. Create a new startup script to launch mysqld on port 3307

nareshv@fallenangel:/usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64$ sudo vi run.sh
#!/bin/bash

/usr/bin/env MYSQL_HOME=/usr/local/mysql ./bin/mysqld --user=mysql \
    --pid-file=/usr/local/mysql/mysqld.pid \
    --socket=/usr/local/mysql/mysqld.sock \
    --port=3307 \
    --basedir=/usr/local/mysql \
    --datadir=/usr/local/mysql/data \
    --lc-messages-dir=/usr/local/mysql/share \
    --tmpdir=/tmp \
    --skip-external-locking \
    --bind-address=127.0.0.1 \

nareshv@fallenangel:/usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64$

4. Run the mysql server in another terminal as root user

nareshv@fallenangel:/usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64$ sudo ./run.sh

5. Connect and check if mysql is available on 3307 / 127.0.0.1

nareshv@fallenangel:/usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64$ mysql -u root -h 127.0.0.1 -P 3307
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30-tokudb-7.0.1 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye

Confirm that variables point to /usr/share/mysql only
mysql> show variables like '%dir%';
+-----------------------------------------+-------------------------------------------------------------------+
| Variable_name                           | Value                                                             |
+-----------------------------------------+-------------------------------------------------------------------+
| basedir                                 | /usr/local/mysql                                                  |
| binlog_direct_non_transactional_updates | OFF                                                               |
| character_sets_dir                      | /usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64/share/charsets/ |
| datadir                                 | /usr/local/mysql/data/                                            |
| innodb_data_home_dir                    | /usr/local/mysql/data                                             |
| innodb_log_group_home_dir               | /usr/local/mysql/data                                             |
| innodb_max_dirty_pages_pct              | 75                                                                |
| lc_messages_dir                         | /usr/local/mysql/share/                                           |
| plugin_dir                              | /usr/local/mysql-5.5.30-tokudb-7.0.1-linux-x86_64/lib/plugin/     |
| slave_load_tmpdir                       | /tmp                                                              |
| tmpdir                                  | /tmp                                                              |
| tokudb_data_dir                         |                                                                   |
| tokudb_directio                         | OFF                                                               |
| tokudb_log_dir                          |                                                                   |
| tokudb_tmp_dir                          |                                                                   |
+-----------------------------------------+-------------------------------------------------------------------+
15 rows in set (0.00 sec)

Friday, May 17, 2013

Install HHVM (Hiphop PHP) on Centos 6.4 (64-bit)

UPDATED: 10/July/2013 - Fixed the errors which are causing repo not available. Sorry for the trouble.

UPDATEd: 19/Oct/2013 - HHVM 2.2.0 Release is available now

UPDATED: 18/Dec/2013 - HHVM 2.3.0 Release is available now  

UPDATED: 14/Apr/2014 - HHVM 3.0.1 Release is available now

I have created a repository and compiled HHVM (v2 of HPHP) rpm packages. Follow these steps to get started.

1. Install Centos 6.x (minimal is preferred)

2. Install epel repository

sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

(or get the latest version from http://ftp.riken.jp/Linux/fedora/epel/6/i386/repoview/epel-release.html)

3. download the hop5 repository configuration file

cd /etc/yum.repos.d

sudo wget http://www.hop5.in/yum/el6/hop5.repo
 
If you are here after Mar-2014, use hhvm as package name instead of hiphop-php

4. Install hiphop-php
sudo yum install hiphop-php

5. Follow the instructions at https://github.com/facebook/hiphop-php to get started


Please note that, i have compiled the required rpms from fedora distribution. DO NOT FILE ANY BUGS WITH CENTOS/FEDORA regarding the rpms that you are about to install from this repoisitory.

Sunday, November 20, 2011

Fixing Redmine user page-load-error on Debian 6

For those who are using redmine on debian-6.0, and using redmine might see problem using it, when we try to visit the user page.

Error look something like this.


ActionView::TemplateError (undefined method `html_safe' for "user@mycompany.com":String) on line #10 of app/views/users/show.rhtml:
Solution to this problem is to apply this patch.



redmine-server:/usr/share/redmine# diff /usr/lib/ruby/1.8/action_view/helpers/url_helper.rb /usr/lib/ruby/1.8/action_view/helpers/url_helper.rb.orig 476,477c476<           #html = content_tag("a", name || email_address_obfuscated.html_safe, html_options.merge({ "href" => "mailto:"+html_escape(email_address)+extras }))<                 html = content_tag("a", name || html_escape(email_address_obfuscated), html_options.merge({ "href" => "mailto:"+html_escape(email_address)+extras }))--->           html = content_tag("a", name || email_address_obfuscated.html_safe, html_options.merge({ "href" => "mailto:"+html_escape(email_address)+extras }))mdserver1:/usr/share/redmine# 

Monday, October 31, 2011

Building Facebook's HipHop on Fedora 15

Facebook has opensourced their Hiphop code transformer. Simply put Hiphop transforms your code written in PHP Language into Machine Language. So this post is mainly for PHP Developers and Others who want to get their hands dirty with Hiphop on Fedora 15.

Before you get started. Please visit the main home page of the hiphop Project itself.

On github you see the list of all the pre-requisites. First lets get our development environment ready.


Prerequisites.

You need a Fedora 15 64-bit installation. You need not install anything. Just install the Live CD and follow these steps to get the things done.

1. Install the Fedora Packager packages


[root@nareshv-build64 ~]# yum groupinstall "Fedora Packager"


2. Make sure you have git and c++ compiler


[root@nareshv-build64 ~]# yum install gcc-c++ git wget 


3. Install all the pre-requisites as mentioned in the hiphop wiki

[root@nareshv-build64 ~]# yum install zlib-devel   \
xorg-x11-devel   \
libXau-devel   \
libxcb-devel   \
libX11-devel   \
libXpm-devel   \
freetype-devel   \
fontconfig-devel   \
libcom_err-devel   \
libjpeg-turbo   \
2:libpng-devel   \
libsepol-devel   \
libselinux-devel   \
keyutils-libs   \
krb5-devel   \
openssl-devel   \
mysql-devel   \
gd-devel   \
boost-devel   \
libcap-devel   \
oniguruma-devel   \
pcre-devel   \
libicu-devel   \
binutils-devel   \
libxml2-devel   \
libmcrypt-devel   \
expat-devel   \
libstdc++-devel   \
glibc-devel   \
tbb-devel   \
cyrus-sasl   \
libmemcached-devel   \
bzip2-devel   \
openldap-devel   \
ncurses-devel   \
readline-devel   \
pam-devel   \
uw-imap-devel   \
systemtap-sdt   \
libaio-devel   \
mysql-devel   \
jemalloc-devel


4. Now we have to build libevent-1.4 and curl packages on our own as facebook has made some patches to those packages.

5. Lets create the environment for building the packages

6. Create workspace for checking out the hiphop source code.


[root@nareshv-build64 ~]# cd $HOME/
[root@nareshv-build64 ~]# mkdir -p $HOME/dev/hiphop/ $HOME/dev/hiphop/usr
[root@nareshv-build64 ~]# cd $HOME/dev/hiphop


7. Checkout the hiphop source code


[root@nareshv-build64 ~]# cd $HOME/dev/hiphop/ && git clone git://github.com/facebook/hiphop-php.git



8. Download curl and libevent for building locally


[root@nareshv-build64 ~]# cd $HOME/dev/hiphop/
[root@nareshv-build64 hiphop]# wget http://curl.haxx.se/download/curl-7.20.0.tar.bz2
[root@nareshv-build64 hiphop]# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

[root@nareshv-build64 hiphop]# tar jxf curl-7.20.0.tar.bz2
[root@nareshv-build64 hiphop]# tar zxf libevent-1.4.13-stable.tar.gz

[root@nareshv-build64 hiphop]# cd libevent-1.4.13-stable
[root@nareshv-build64 libevent-1.4.13-stable]# cp ../hiphop-php/src/third_party/libevent-1.4.13.fb-changes.diff .
[root@nareshv-build64 libevent-1.4.13-stable]# patch < libevent-1.4.13.fb-changes.diff
[root@nareshv-build64 libevent-1.4.13-stable]# export CMAKE_PREFIX_PATH=$HOME/dev/hiphop/usr
[root@nareshv-build64 libevent-1.4.13-stable]# make
[root@nareshv-build64 libevent-1.4.13-stable]# make install
[root@nareshv-build64 libevent-1.4.13-stable]# cd $HOME/dev/hiphop/

[root@nareshv-build64 hiphop]# cd curl-7.20.0
[root@nareshv-build64 curl-7.20.0]# cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
[root@nareshv-build64 curl-7.20.0]# patch -p0 < libcurl.fb-changes.diff

# While applying patch, it will ask for which file to patch. Type in the names without the .new and .old paths. 
# Example: include/curl/multi.h and 
# Example: lib/multi.c
# After this, patch will be applied correctly.

[root@nareshv-build64 curl-7.20.0]# ./configure --prefix=$HOME/dev/hiphop/usr/
[root@nareshv-build64 curl-7.20.0]# make
[root@nareshv-build64 curl-7.20.0]# make install
[root@nareshv-build64 curl-7.20.0]# cd $HOME/dev/hiphop/


9. Now get ready to build hiphop itself


[root@nareshv-build64 curl-7.20.0]# cd $HOME/dev/hiphop/hiphop-php
[root@nareshv-build64 hiphop-php]# export CMAKE_PREFIX_PATH=$HOME/dev/hiphop/usr/
[root@nareshv-build64 hiphop-php]# git submodule init
[root@nareshv-build64 hiphop-php]# git submodule update
[root@nareshv-build64 hiphop-php]# export HPHP_HOME=`pwd`
[root@nareshv-build64 hiphop-php]# export HPHP_LIB=`pwd`/bin
[root@nareshv-build64 hiphop-php]# cmake .
[root@nareshv-build64 hiphop-php]# make


10. You will encounter some errors related to 'c-client version should be higher than 2007'.

On fedora the package is called libc-client and libc-client-devel and the includes are present in /usr/include/imap/ folders.

Lets adjust the CMakeCache.txt like this.

[root@nareshv-build64 hiphop-php]# cd $HOME/dev/hiphop/hiphop-php/
[root@nareshv-build64 hiphop-php]# vim CMakeCache.txt

 71 //Path to a file.CCLIENT_INCLUDE_PATH:PATH=CCLIENT_INCLUDE_PATH-NOTFOUND
 72 CCLIENT_INCLUDE_PATH:PATH=/usr/include/imap/
 73 
 74 //Path to a library.CCLIENT_LIBRARY:FILEPATH=CCLIENT_LIBRARY-NOTFOUND
 75 CCLIENT_LIBRARY:FILEPATH=/usr/lib64/libc-client.so.2007


11. Build again.

[root@nareshv-build64 hiphop-php]# cd $HOME/dev/hiphop/hiphop-php/
[root@nareshv-build64 hiphop-php]# cmake .
[root@nareshv-build64 hiphop-php]# make


12. Now it will fail at mysql related references like this


[ 88%] Building CXX object src/hphp/CMakeFiles/hphp.dir/externals.cpp.o
Linking CXX executable hphp
../../bin/libhphp_runtime.a(ext_mysql.cpp.o): In function `HPHP::php_mysql_do_query_general(HPHP::String const&, HPHP::Variant const&, bool)':
ext_mysql.cpp:(.text+0x8109): undefined reference to `cli_safe_read'
ext_mysql.cpp:(.text+0x822c): undefined reference to `net_field_length'
ext_mysql.cpp:(.text+0x83a0): undefined reference to `cli_safe_read'
ext_mysql.cpp:(.text+0x8675): undefined reference to `free_root'
collect2: ld returned 1 exit status
gmake[2]: *** [src/hphp/hphp] Error 1
gmake[1]: *** [src/hphp/CMakeFiles/hphp.dir/all] Error 2
gmake: *** [all] Error 2


After investigating for a couple of hours. found that this issue is related to the way mysql rpm is built in fedora distribution. Somehow i managed to overcome this problem by doing the following things.

12.1 Download the mysql .src.rpm from koji

I went to http://koji.fedoraproject.org/koji/buildinfo?buildID=268920

and downloaded the following .src.rpm

http://kojipkgs.fedoraproject.org/packages/mysql/5.5.16/3.fc17/src/mysql-5.5.16-3.fc17.src.rpm

12.2 Install the .src.rpm as 'fedora' user (It can be root also. I did it as fedora user. But you got the point)


[root@nareshv-build64 hiphop-php]# rpm -Uvh mysql-5.5.16-3.fc17.src.rpm


12.3 Update the libmysql.version file


[root@nareshv-build64 hiphop-php]# cd /home/fedora/rpmbuild/SOURCES/
[root@nareshv-build64 SOURCES]# ls
filter-requires-mysql.sh    mysql-disable-test.patch     mysql-errno.patch          mysql-strmov.patch
generate-tarball.sh         mysqld-nowatch.patch         mysql-expired-certs.patch  mysql.tmpfiles.d
libmysql.version            mysqld-prepare-db-dir        mysql-install-test.patch   mysql-va-list.patch
my.cnf                      mysqld.service               mysql-openssl-test.patch   mysql-versioning.patch
my_config.h                 mysql-dubious-exports.patch  mysql-plugin-bool.patch    README.mysql-docs
mysql-5.5.16-nodocs.tar.gz  mysqld-wait-ready            mysql-s390-tsc.patch       README.mysql-license
mysql-chain-certs.patch     mysql-embedded-check.c       mysql-stack-guard.patch    scriptstub.c
[root@nareshv-build64 SOURCES]# tail libmysql.version 
 mysql_get_charset_by_csname;
 mysql_net_realloc;
# PHP's mysqli.so requires this (via the ER() macro)
 mysql_client_errors;
# Hiphop needs it
 cli_safe_read;
 net_field_length;
 cli_safe_read;
 free_root;
};


12.4 Rebuild the RPM

[fedora@nareshv-build64 SOURCES]$ rpmbuild -bb ../SPECS/mysql.spec 
...
...
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-libs-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-server-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-devel-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-embedded-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-embedded-devel-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-bench-5.5.16-3.fc15.x86_64.rpm
Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-test-5.5.16-3.fc15.x86_64.rpm

Wrote: /home/fedora/rpmbuild/RPMS/x86_64/mysql-debuginfo-5.5.16-3.fc15.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.I5L4qW
+ umask 022
+ cd /home/fedora/rpmbuild/BUILD
+ cd mysql-5.5.16
+ rm -rf /home/fedora/rpmbuild/BUILDROOT/mysql-5.5.16-3.fc15.x86_64
+ exit 0


12.5 Install the RPM Files happily


[root@nareshv-build64 SOURCES]# yum install /home/fedora/rpmbuild/RPMS/x86_64/mysql-libs-5.5.16-3.fc15.x86_64.rpm \
/home/fedora/rpmbuild/RPMS/x86_64/mysql-5.5.16-3.fc15.x86_64.rpm \
/home/fedora/rpmbuild/RPMS/x86_64/mysql-devel-5.5.16-3.fc15.x86_64.rpm -y --nogpg


13. Now build hiphop again

[root@nareshv-build64 hiphop-php]# cd $HOME/dev/hiphop/hiphop-php/
[root@nareshv-build64 hiphop-php]# gmake clean
[root@nareshv-build64 hiphop-php]# cmake .
[root@nareshv-build64 hiphop-php]# make


14. You should have the binary created

[root@nareshv-build64 hiphop-php]# src/hphp/hphp -h | head
Error in command line: unknown option -h\n\n
HipHop Compiler for PHP Usage:

 hphp  

Options:
  --help                         display this message
  --version                      display version number
  -t [ --target ] arg (=run)     lint | analyze | php | cpp | sep-ext-cpp | 
                                 filecache | run (default)
  -f [ --format ] arg            lint: (none); 


15. Now continue with the rest of the tutorial on how to get your code compiled in the main hiphop project page itself.