NanoMVC

Installation

Welcome to the NanoMVC installation guide. This section walks you through setting up the framework, configuring paths, and preparing your environment to start building applications.

Quick "I just want to see it" Install

To get started quickly:

Single Installation (Typical)

This setup is intended for a single website. If you’re planning to host multiple websites that share the NanoMVC core, see the "Shared Installation" section below.

Directory Structure

After unpacking the archive, you’ll see something like this:

/htdocs/
  index.php

/nanomvc/
  /myapp/
  /myfiles/
  /sysfiles/

Setup

  1. Move index.php into your web server document root
  2. Move the entire /nanomvc/ directory outside the web root (recommended)
  3. If keeping it inside the web root, configure your web server to deny access to it

Example Layout

/var/www.foo.bar/htdocs/
  index.php

/var/www.foo.bar/nanomvc/
  /myapp/
  /myfiles/
  /sysfiles/

Configuration

Edit index.php and set paths as needed:

// Enable full error reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');

// Directory separator constant
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
// Uncomment and set if the /nanomvc/ dir is not one level above this file
// define('NMVC_BASEDIR', dirname(__FILE__) . DS . '..' . DS . 'nanomvc' . DS);

If you define NMVC_ERROR_HANDLING and set it to 1, NanoMVC will use its internal error and exception handlers. If you omit this or set it to 0, PHP's default handlers will be used instead. This is useful for debugging during development.

After saving, open http://localhost/index.php in your browser. If you don’t see the welcome screen, recheck your paths and error messages.

Database Settings

If your application uses a database, edit:

/nanomvc/myapp/configs/​config_database.php

Example configuration:

$config['default']['plugin']     = 'NanoMVC_PDO';
$config['default']['type']       = 'mysql';
$config['default']['host']       = 'localhost';
$config['default']['name']       = 'dbname';
$config['default']['user']       = 'dbuser';
$config['default']['pass']       = 'dbpass';
$config['default']['persistent'] = false;

Shared Installation

This setup allows multiple websites to share the NanoMVC core libraries.

Structure

# Shared code
/usr/local/lib/nanomvc/
  /myfiles/
  /sysfiles/

# Website 1
/var/www.foo1.bar/htdocs/index.php
/var/www.foo1.bar/myapp/

# Website 2
/var/www.foo2.bar/htdocs/index.php
/var/www.foo2.bar/myapp/

# Website 3
/var/www.foo3.bar/htdocs/index.php
/var/www.foo3.bar/myapp/

For each website:

  1. Install a unique index.php under its document root
  2. Copy /myapp/ to the corresponding site folder
  3. Edit index.php and define the paths:
/* NanoMVC base library path */
define('NMVC_BASEDIR', '/usr/local/lib/nanomvc/');

/* application library path */
define('NMVC_MYAPPDIR', '../myapp/');

Using Git for Updates

If you use Git to get updates — which is a good idea compared to updating manually — keep the following in mind:

← to Overview to Controllers →

← Back to Documentation