Sunday 16 November 2014

How to Install php gearman on ubuntu 14.04 and 14.10


Steps


1. Install the gearman job server and libgearman :

sudo apt-get install gearman-job-server libgearman-dev
2. Install the pecl extension

sudo apt-get install php-pear php5-dev
sudo pecl install gearman

The output will show something like this at the end :
Build process completed successfully
Installing '/usr/lib/php5/20100525/gearman.so'
install ok: channel://pecl.php.net/gearman-1.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=gearman.so" to php.ini

3. Edit php.ini file :
$ locate php.ini
/etc/php5/apache2/php.ini
/etc/php5/cgi/php.ini
Open the correct php.ini file and add extension=gearman.so at the end.

4. Restart apache

How to install Mongodb in Lampp Ubuntu 14.10


Install MongoDB


Configure Package Management System (APT)

The Ubuntu package management tool (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Create a /etc/apt/sources.list.d/mongodb.list file using the following command

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Now issue the following command to reload your repository:

sudo apt-get update

Install Packages

Issue the following command to install the latest stable version of MongoDB:

sudo apt-get install mongodb-10gen


Install MongoDB PHP Driver to Lampp

Note that if you install XAMPP using the new .run installer file (versions newer than 1.8.3) then you will get the option during setup to install the development files as well as the core files. Remember to select both.

1 Please download lattest xampp for ubuntu and install with following command:

cd Download ( where xampp download location)
sudo chmod +x xampp-linux-1.8.3-4-installer.run
sudo ./xampp-linux-1.8.3-4-installer.run


 2. Run the pecl installer
1
sudo /opt/lampp/bin/pecl install mongo

Note : If You getting below error : “ ERROR: `phpize' failed”

sudo apt-get install php5-dev

Now again run this command :

sudo /opt/lampp/bin/pecl install mongo

Note : again any error same like

the error message you got:
configure: error: sasl.h not found!
should be solveable by:
sudo apt-get install libsasl2-dev
3. Finally add the following to the php.ini file (located in /opt/lampp/etc folder)
1
extension=mongo.so
4. restart xampp server

1
sudo /opt/lampp/lampp start
That’s it!












 

Friday 17 October 2014

How to install mongodb in windows

Sections in this post:

1) Download MongoDB
2) Install MongoDB
3) Create mongo.config Configuration File
4) Start/Shutdown the MongoDB Server
5) MongoDB Windows Service
6) Download/Use MongoDB Java Driver
7) Verify MongoDB Installation

1) Download MongoDB

There are three builds of MongoDB for Windows:
1) MongoDB for Windows Server 2008 R2 edition [Download link]
2) MongoDB for Windows 64-bit [Download link]
3) MongoDB for Windows 32-bit [Download link]

2) Install MongoDB

The given links above will download zip files which you extract directly onto any place in your system of your choice. I have extracted them in “d:/mongodb“. So, all code samples will in this post as well as future posts will refer to this location.
Also, please create following directories inside d:/mongodb
  • D:\mongodb\data
  • D:\mongodb\log

3) Create mongo.config Configuration File

his is important step before marching ahead. Create a normal text file in location d:/mongodb and save it with namemongo.config.
Now place the below configuration options in file. You can change the option’s values at your will.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
##Which IP address(es) mongod should bind to.
bind_ip = 127.0.0.1
 
##Which port mongod should bind to.
port = 27017
 
##I set this to true, so that only critical events and errors are logged.
quiet = true
 
##store data here
dbpath=D:\mongodb\data
  
##The path to the log file to which mongod should write its log messages.
logpath=D:\mongodb\log\mongo.log
 
##I set this to true so that the log is not overwritten upon restart of mongod.
logappend = true
  
##log read and write operations
diaglog=3
 
##It ensures write durability and data consistency much as any journaling scheme would be expected to do.
##Only set this to false if you don’t really care about your data (or more so, the loss of it).
journal = true


4) Start/Shutdown the MongoDB Server

To start the MongoDB server, use below command in command prompt:
mongod.exe --config d:\mongodb\mongo.config
1
2
3
4
D:\mongodb\bin>mongod --config D:\mongodb\mongo.config --journal
2014-05-25T16:51:18.433+0530 warning: --diaglog is deprecated and will be removed in a future release
2014-05-25T16:51:18.434+0530 diagLogging level=3
2014-05-25T16:51:18.435+0530 diagLogging using file D:\mongodb\data/diaglog.5381d22e
To connect to MongoDB from command prompt, use below command:
d:\mongodb\bin>mongo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
D:\mongodb\bin>mongo
MongoDB shell version: 2.6.1
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see   http://docs.mongodb.org/
Questions? Try the support group   http://groups.google.com/group/mongodb-user
Server has startup warnings:
2014-05-25T16:52:09.158+0530 [initandlisten]
2014-05-25T16:52:09.158+0530 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
2014-05-25T16:52:09.158+0530 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --jour
nal).
2014-05-25T16:52:09.158+0530 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
2014-05-25T16:52:09.158+0530 [initandlisten]

To shutdown the MongoDB server, you must be authorized user. So after getting auth complete, use below command in command prompt:
db.shutdownServer()
1
2
3
4
5
6
7
8
9
10
11
12
13
> use admin
switched to db admin
> db.shutdownServer()
2014-05-25T19:55:25.221+0530 DBClientCursor::init call() failed
server should be down...
2014-05-25T19:55:25.224+0530 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2014-05-25T19:55:26.225+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made b
ecause the target machine actively refused it.
2014-05-25T19:55:26.225+0530 reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (
127.0.0.1), connection attempt failed
> quit()
 
D:\mongodb\bin>

5) MongoDB Windows Service

To install the window service, use below command:
mongod --config D:\mongodb\mongo.config --install
Start the windows service from command prompt:
net start MongoDB
Stop the windows service from command prompt:
net stop MongoDB
Remove the windows service
mongod --remove
Sample run of all above four commands is below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
D:\mongodb\bin>mongod --config D:\mongodb\mongo.config --install
2014-05-25T20:07:41.191+0530 warning: --diaglog is deprecated and will be removed in a future release
2014-05-25T20:07:41.192+0530 diagLogging level=3
2014-05-25T20:07:41.193+0530 diagLogging using file D:\mongodb\data/diaglog.53820035
 
D:\mongodb\bin>net start MongoDB
 
The MongoDB service was started successfully.
 
 
D:\mongodb\bin>net stop MongoDB
System error 109 has occurred.
 
The pipe has been ended.
 
 
D:\mongodb\bin>mongod --remove
2014-05-25T20:09:32.514+0530
2014-05-25T20:09:32.515+0530 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you wa
nt durability.
2014-05-25T20:09:32.515+0530
2014-05-25T20:09:32.518+0530 Trying to remove Windows service 'MongoDB'
2014-05-25T20:09:32.520+0530 Service 'MongoDB' removed
 
D:\mongodb\bin>

6) Download/Use MongoDB Java Driver

Download the MongoDB java driver (mongo-java-driver-2.9.3.jar) from this download link. It’s a jar file you need to include in your classpath/ copy in lib folder in project where you want to use MongoDB.


7) Verify MongoDB Installation

To verify that MongoDB has been installed and working properly, execute below program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package examples.mongodb.install;
 
import java.net.UnknownHostException;
import java.util.List;
 
import com.mongodb.MongoClient;
 
public class VerifyMongoDBInstallation {
    public static void main(String[] args) throws UnknownHostException {
        MongoClient mongo = new MongoClient("localhost", 27017);
 
        List<String> dbs = mongo.getDatabaseNames();
        for (String db : dbs) {
            System.out.println(db);
        }
    }
}
 
Output:
 
local
admin