Tuesday, February 11, 2014

Configure HHVM with Apache + FastCGI on Centos 6.5

On centos you can run regular fastcgi processes with mod_fcgid package. In order to communicate with HHVM over TCP/IP you need to install mod_fastcgi which is available elsewhere on the internet.

 Follow these instructions to use apache + fastcgi with hhvm.

0. Pre-requisites

Make sure you add the following to /etc/hosts on your server where you are going to use curl/browser

127.0.0.1 test.example.com

1. Install httpd-devel packages

[root@localhost yum.repos.d]# yum install httpd-devel -y

2. Download mod_fastcgi

 [root@localhost ~]# wget http://www.fastcgi.com/dist/mod_fastcgi-SNAP-0910052141.tar.gz

3. Compile and install mod_fastcgi

Make sure to change the top_dir variable in the Makefile to centos specific like below or else package wont compile

top_dir      = /usr/lib64/httpd

[root@localhost ~]# tar zxf mod_fastcgi-SNAP-0910052141.tar.gz 
[root@localhost ~]# cd mod_fastcgi-SNAP-0910052141
[root@localhost mod_fastcgi-SNAP-0910052141]# cp Makefile.AP2 Makefile
[root@localhost mod_fastcgi-SNAP-0910052141]# make
[root@localhost mod_fastcgi-SNAP-0910052141]# make install

4. Start the hhvm server in fastcgi mode

[root@localhost ~]# /usr/bin/hhvm --mode server -vServer.Port=9000 -vServer.Type=fastcgi 
mapping self...
mapping self took 0'00" (34658 us) wall time
loading static content...
loading static content took 0'00" (3 us) wall time
page server started
all servers started

5. Create a dummy apache configuration file

[root@localhost ~]# cat /etc/httpd/conf.d/1.conf 

    ServerName test.example.com
    DocumentRoot /var/www/localhost
    LoadModule fastcgi_module modules/mod_fastcgi.so
    FastCgiExternalServer /var/www/localhost -host 127.0.0.1:9000

[root@localhost ~]# 

6. Create document root and simple php file

mkdir -p /var/www/localhost && echo '<?php echo "hello world"; ?>' > /var/www/localhost/index.php

7. Start httpd from another terminal

[root@localhost ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]
8. Fire a request and see that you get response from HHVM
 nareshv @ localhost $ curl http://test.example.com/index.php ; echo
hello world!
 nareshv @ localhost $
 nareshv @ localhost $ curl http://test.example.com/404.php ; echo
Not Found
 nareshv @ localhost $

9. Final configurations

Once you have proper working setup like above, create a configuration file for hhvm and run it in daemon mode.

Have Fun!

Monday, February 10, 2014

Installing docker 0.8 version on Centos 6.5

1. Configure EPEL Repository
[root@localhost ~]# sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: centos.aol.in
 * extras: centos.aol.in
 * updates: centos.aol.in
Setting up Install Process
epel-release-6-8.noarch.rpm                                                                    |  14 kB     00:00     
Examining /var/tmp/yum-root-7UK58w/epel-release-6-8.noarch.rpm: epel-release-6-8.noarch
Marking /var/tmp/yum-root-7UK58w/epel-release-6-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:6-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                     Arch                  Version              Repository                               Size
======================================================================================================================
Installing:
 epel-release                noarch                6-8                  /epel-release-6-8.noarch                 22 k

Transaction Summary
======================================================================================================================
Install       1 Package(s)

Total size: 22 k
Installed size: 22 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : epel-release-6-8.noarch                                                                            1/1 
  Verifying  : epel-release-6-8.noarch                                                                            1/1 

Installed:
  epel-release.noarch 0:6-8                                                                                           

Complete!

2. Install the docker-io package from EPEL Repository
[root@localhost ~]# yum install docker-io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/metalink                                                                                  | 4.6 kB     00:00     
 * base: centos.aol.in
 * epel: epel.mirror.net.in
 * extras: centos.aol.in
 * updates: centos.aol.in
epel                                                                                           | 4.2 kB     00:00     
epel/primary_db                                                                                | 5.9 MB     00:06     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:0.7.6-2.el6 will be installed
--> Processing Dependency: xz for package: docker-io-0.7.6-2.el6.x86_64
--> Processing Dependency: lxc for package: docker-io-0.7.6-2.el6.x86_64
--> Processing Dependency: libcgroup for package: docker-io-0.7.6-2.el6.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 0:0.40.rc1-5.el6_5.1 will be installed
---> Package lxc.x86_64 0:0.9.0-2.el6 will be installed
--> Processing Dependency: liblxc.so.0()(64bit) for package: lxc-0.9.0-2.el6.x86_64
---> Package xz.x86_64 0:4.999.9-0.3.beta.20091007git.el6 will be installed
--> Running transaction check
---> Package lxc-libs.x86_64 0:0.9.0-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                Arch                Version                                        Repository            Size
======================================================================================================================
Installing:
 docker-io              x86_64              0.7.6-2.el6                                    epel                 3.4 M
Installing for dependencies:
 libcgroup              x86_64              0.40.rc1-5.el6_5.1                             updates              125 k
 lxc                    x86_64              0.9.0-2.el6                                    epel                  78 k
 lxc-libs               x86_64              0.9.0-2.el6                                    epel                 116 k
 xz                     x86_64              4.999.9-0.3.beta.20091007git.el6               base                 137 k

Transaction Summary
======================================================================================================================
Install       5 Package(s)

Total download size: 3.9 M
Installed size: 19 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): docker-io-0.7.6-2.el6.x86_64.rpm                                                        | 3.4 MB     00:03     
(2/5): libcgroup-0.40.rc1-5.el6_5.1.x86_64.rpm                                                 | 125 kB     00:00     
(3/5): lxc-0.9.0-2.el6.x86_64.rpm                                                              |  78 kB     00:00     
(4/5): lxc-libs-0.9.0-2.el6.x86_64.rpm                                                         | 116 kB     00:00     
(5/5): xz-4.999.9-0.3.beta.20091007git.el6.x86_64.rpm                                          | 137 kB     00:00     
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 858 kB/s | 3.9 MB     00:04     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
 Userid : EPEL (6) 
 Package: epel-release-6-8.noarch (@/epel-release-6-8.noarch)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) 
 Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libcgroup-0.40.rc1-5.el6_5.1.x86_64                                                                1/5 
  Installing : xz-4.999.9-0.3.beta.20091007git.el6.x86_64                                                         2/5 
  Installing : lxc-libs-0.9.0-2.el6.x86_64                                                                        3/5 
  Installing : lxc-0.9.0-2.el6.x86_64                                                                             4/5 
  Installing : docker-io-0.7.6-2.el6.x86_64                                                                       5/5 
  Verifying  : lxc-libs-0.9.0-2.el6.x86_64                                                                        1/5 
  Verifying  : xz-4.999.9-0.3.beta.20091007git.el6.x86_64                                                         2/5 
  Verifying  : docker-io-0.7.6-2.el6.x86_64                                                                       3/5 
  Verifying  : libcgroup-0.40.rc1-5.el6_5.1.x86_64                                                                4/5 
  Verifying  : lxc-0.9.0-2.el6.x86_64                                                                             5/5 

Installed:
  docker-io.x86_64 0:0.7.6-2.el6                                                                                      

Dependency Installed:
  libcgroup.x86_64 0:0.40.rc1-5.el6_5.1             lxc.x86_64 0:0.9.0-2.el6      lxc-libs.x86_64 0:0.9.0-2.el6     
  xz.x86_64 0:4.999.9-0.3.beta.20091007git.el6     

Complete!
[root@localhost ~]# 

3. For the brave, start the docker and see these warnings
[root@localhost ~]# docker -d &
[1] 1145
[root@localhost ~]# 2014/02/10 03:23:29 WARNING: You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.8.0.
[/var/lib/docker|c3648251] +job initapi()
[/var/lib/docker|c3648251.initapi()] Creating server

Docker will continue to run. But, better upgrade to kernel 3.8 or higher. 4. Configure the elrepo repository so that we can upgrade kernel to 3.8 or higher
[root@localhost ~]# yum install http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.aol.in
 * epel: epel.mirror.net.in
 * extras: centos.aol.in
 * updates: centos.aol.in
Setting up Install Process
elrepo-release-6-5.el6.elrepo.noarch.rpm                                                       | 7.2 kB     00:00     
Examining /var/tmp/yum-root-7UK58w/elrepo-release-6-5.el6.elrepo.noarch.rpm: elrepo-release-6-5.el6.elrepo.noarch
Marking /var/tmp/yum-root-7UK58w/elrepo-release-6-5.el6.elrepo.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package elrepo-release.noarch 0:6-5.el6.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                 Arch            Version                 Repository                                      Size
======================================================================================================================
Installing:
 elrepo-release          noarch          6-5.el6.elrepo          /elrepo-release-6-5.el6.elrepo.noarch          2.8 k

Transaction Summary
======================================================================================================================
Install       1 Package(s)

Total size: 2.8 k
Installed size: 2.8 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : elrepo-release-6-5.el6.elrepo.noarch                                                               1/1 
  Verifying  : elrepo-release-6-5.el6.elrepo.noarch                                                               1/1 

Installed:
  elrepo-release.noarch 0:6-5.el6.elrepo                                                                              

Complete!
5. Install the kernel-ml from elrepo
[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.aol.in
 * elrepo: mirror.smartmedia.net.id
 * elrepo-kernel: mirror.smartmedia.net.id
 * epel: epel.mirror.net.in
 * extras: centos.aol.in
 * updates: centos.aol.in
elrepo                                                                                         | 2.9 kB     00:00     
elrepo/primary_db                                                                              | 593 kB     00:02     
elrepo-kernel                                                                                  | 2.9 kB     00:00     
elrepo-kernel/primary_db                                                                       |  19 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:3.13.2-1.el6.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                  Arch                  Version                            Repository                    Size
======================================================================================================================
Installing:
 kernel-ml                x86_64                3.13.2-1.el6.elrepo                elrepo-kernel                 35 M

Transaction Summary
======================================================================================================================
Install       1 Package(s)

Total download size: 35 M
Installed size: 159 M
Is this ok [y/N]: y
Downloading Packages:
kernel-ml-3.13.2-1.el6.elrepo.x86_64.rpm                                                       |  35 MB     02:21     
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Importing GPG key 0xBAADAE52:
 Userid : elrepo.org (RPM Signing Key for elrepo.org) 
 Package: elrepo-release-6-5.el6.elrepo.noarch (@/elrepo-release-6-5.el6.elrepo.noarch)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-ml-3.13.2-1.el6.elrepo.x86_64                                                               1/1 
  Verifying  : kernel-ml-3.13.2-1.el6.elrepo.x86_64                                                               1/1 

Installed:
  kernel-ml.x86_64 0:3.13.2-1.el6.elrepo                                                                              

Complete!
[root@localhost ~]# 
6. Reboot the server into the 3.13 kernel (MAKE SURE TO SELECT KERNEL IN GRUB MENU)
[root@localhost ~]# reboot

Broadcast message from root@localhost.localdomain
        (/dev/pts/0) at 3:33 ...

The system is going down for reboot NOW!

7. Login and verify the server kernel version
[root@localhost ~]# uname -r
3.13.2-1.el6.elrepo.x86_64
[root@localhost ~]# 

8. See that a new docker0 interface is created
[root@localhost ~]# ifconfig
docker0   Link encap:Ethernet  HWaddr A2:FA:1E:55:53:77  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::a0fa:1eff:fe55:5377/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:1422 (1.3 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:D5:BC:A0  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed5:bca0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:118 errors:0 dropped:0 overruns:0 frame:0
          TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13818 (13.4 KiB)  TX bytes:7215 (7.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@localhost ~]# 

9. Start the docker in daemon mode
[root@localhost ~]# docker -d
10. Verify the docker version
[root@localhost ~]# docker version
Client version: 0.7.6
Go version (client): go1.2
Git commit (client): bc3b2ec/0.7.6
Server version: 0.7.6
Git commit (server): bc3b2ec/0.7.6
Go version (server): go1.2
Last stable version: 0.8.0, please update docker
[root@localhost ~]# 

11. Update to 0.8 version (Optional Step)
[root@localhost ~]# ps auxww | grep docker
root      1008  0.0  1.3 338992  6788 ?        Sl   03:35   0:00 /usr/bin/docker -d
root      1357  0.0  0.1 103296   820 pts/0    S+   03:55   0:00 grep docker
[root@localhost ~]# kill -9 1008

[root@localhost ~]# yum install http://kojipkgs.fedoraproject.org//packages/docker-io/0.8.0/2.el6/x86_64/docker-io-0.8.0-2.el6.x86_64.rpm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.aol.in
 * elrepo: mirror.smartmedia.net.id
 * epel: epel.mirror.net.in
 * extras: centos.aol.in
 * updates: centos.aol.in
Setting up Install Process
docker-io-0.8.0-2.el6.x86_64.rpm                                                               | 3.6 MB     00:05     
Examining /var/tmp/yum-root-7UK58w/docker-io-0.8.0-2.el6.x86_64.rpm: docker-io-0.8.0-2.el6.x86_64
Marking /var/tmp/yum-root-7UK58w/docker-io-0.8.0-2.el6.x86_64.rpm as an update to docker-io-0.7.6-2.el6.x86_64
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:0.7.6-2.el6 will be updated
---> Package docker-io.x86_64 0:0.8.0-2.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                Arch                Version                  Repository                                  Size
======================================================================================================================
Updating:
 docker-io              x86_64              0.8.0-2.el6              /docker-io-0.8.0-2.el6.x86_64               19 M

Transaction Summary
======================================================================================================================
Upgrade       1 Package(s)

Total size: 19 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : docker-io-0.8.0-2.el6.x86_64                                                                       1/2 
  Cleanup    : docker-io-0.7.6-2.el6.x86_64                                                                       2/2 
  Verifying  : docker-io-0.8.0-2.el6.x86_64                                                                       1/2 
  Verifying  : docker-io-0.7.6-2.el6.x86_64                                                                       2/2 

Updated:
  docker-io.x86_64 0:0.8.0-2.el6                                                                                      

Complete!

[root@localhost ~]# docker info
Containers: 0
Images: 0
Driver: devicemapper
 Pool Name: docker-253:0-110-pool
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 291.5 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 0.7 Mb
 Metadata Space Total: 2048.0 Mb
WARNING: No swap limit support
[root@localhost ~]# 

Go to http://docs.docker.io/en/latest/ and get started with docker.

Have Fun !

NOTE: If you were use http://www.hop5.in repository. Dont worry as the package upgrades are seamless due to the package name being same.