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.
To get started quickly:
htdocs/index.phpThis 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.
After unpacking the archive, you’ll see something like this:
/htdocs/
index.php
/nanomvc/
/myapp/
/myfiles/
/sysfiles/
index.php into your web server document root/nanomvc/ directory outside the web root (recommended)/var/www.foo.bar/htdocs/
index.php
/var/www.foo.bar/nanomvc/
/myapp/
/myfiles/
/sysfiles/
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);
error_reporting(E_ALL); to error_reporting(0); and ini_set('display_errors', '1'); to ini_set('display_errors', '0'); to hide all errors (typically for a production environment).NMVC_BASEDIR path if necessaryDS)
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.
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;
default is the name of the default DB connectionNanoMVC_PDO unless you have your own DB pluginThis setup allows multiple websites to share the NanoMVC core libraries.
# 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:
index.php under its document root/myapp/ to the corresponding site folderindex.php and define the paths:/* NanoMVC base library path */
define('NMVC_BASEDIR', '/usr/local/lib/nanomvc/');
/* application library path */
define('NMVC_MYAPPDIR', '../myapp/');
/sysfiles/ should never be modified directly — it’s updated on NanoMVC upgrades/myfiles/ to store shared plugins or helpers across projectsIf you use Git to get updates — which is a good idea compared to updating manually — keep the following in mind:
nanomvc/myapp folder can be modified. It contains demo materials to showcase how NanoMVC works.
Any changes you make there may lead to conflicts during updates. The best practice is to copy this folder elsewhere.
Instructions for where to copy it are provided earlier in this chapter.
nanomvc/myfiles. This folder is not affected by updates.
The only file that may be updated occasionally is nanomvc/myfiles/plugins/README.