Novice

Create a Node.js webserver

To create a node webserver, the core http module needs to be included. To include an existing module you can use the require function.


var http = require("http");

http.createServer(function(request, response) {
    response.writeHead(200,{"Content-Type":"text/plain"});
    response.write("Luke, I am your server");
    response.end();
}).listen(8888);

See the difference with a node server using express

Install SQLite on Ubuntu

SQLite can be installed by typing the following command in command line:

sudo apt-get install sqlite3 libsqlite3-dev

You can see if SQLite is installed properly by typing sqlite3 in command line.

sqlite3_is_installed.png

Quit SQLite by typing .exit.

Help is on the way when typing .help.

 

Drop MongoDB database in PHP


// Establish connection.
$connection = new Mongo();

// Select database.
$database = $connection->demo;

// Drop database.
$dropped = $database->drop();
var_dump($dropped);

// Close connection.
$connection->close();

First steps using MongoDB in PHP


// Establish connection.
$connection = new Mongo();
// Select database, create database if database not exists.
$database = $connection->demo;
// Select collection.
$collection = $database->users;
// Insert data.
$user = array(
  'name' => 'Dribbit',
  'email' => 'info@dribbit.eu',
);
$collection->insert($user);

// Get all records.
$records = $collection->find();
var_dump($records);
foreach($records as $record) {
  var_dump($record);
}

// Close connection.
$connection->close();

Where does mongodb stores data

Type following command in command line terminal:

sudo nano /etc/mongodb.conf

 

mongo_conf.png

This is based on an Ubuntu system.

Install MongoDB driver for PHP on Ubuntu

Type following line in command line:

sudo pecl install mongo

If Pecl throws this error: configure: error: sasl.h not found! add following command and retry installing mongodb

sudo apt-get install libsasl2-dev

After installing, add the mongo extension to php.ini

extension=mongo.so

Restart apache:

Get current Ubuntu version

Get Ubuntu version by typing

lsb_release -a

in command line.

ubuntu_release.png

My current version is 14.4

 

Install MongoDB on Ubuntu

32 bit systems are limited to DB of 2 gig. Therefor, use MongoDB only on 64 bit systems in production.

@see MongoDb documentation to install MongoDB.

See if MongoDB is running by typing

sudo service mongodb status

in command line.

 

Pages

Subscribe to RSS - Novice