Let's get everything setup correctly so you can start using PHP-RBAC.

PHP-RBAC requires PHP 5.3+ with a SQL database. Currently SQLite and MySQL are supported, but you can easily add any other DBMS you like.

Installing PHP-RBAC is a three step process:

  1. Get the code
  2. Load the code
  3. Setup the database

Get the code

Get the code

There are three ways to get PHP-RBAC:

  • The easiest way to install and autoload PHP-RBAC is to use Composer.
    • Add the following "require" element to your "composer.json" file:
    • "require": {
          "owasp/phprbac": "2.0.*@dev"
      }
      
  • The latest stable version can be found Here
  • Head over to Github

Setup the database

Using the GUI Installer

  1. Navigate to '/path/to/PhpRbac/install.php'
  2. Enter proper database credentials
  3. Click 'Install'

The installer will:

  • Create the proper 'database.config' file
  • Create the required Database Tables
  • Populate the Database Tables with the required initial data

Manual Installation

  1. Create a Database and Database User with the proper permissions
  2. Import the Database Tables and initial data using the provided *.sql file
    Warning: Make sure you change 'PREFIX_' in the SQL statements to the prefix you would like to use!
    • For MySQL: '/path/to/PhpRbac/database/mysql.sql'
    • For SQLite: '/path/to/PhpRbac/database/sqlite.sql'
  3. Edit the '/path/to/PhpRbac/database/database.config'
    • Enter the proper credentials
    • Choose the correct $adapter and $tablePrefix

Load the code

There are four methods provided to load the 'PhpRbac\Rbac' Class...

Using Composer

If you have installed PHP-RBAC using Composer simply include the Composer generated 'vendor/autoload.php' file:

Example: Using Composer's autoloader
require 'vendor/autoload.php';

Using a PSR-0 Autoloader

Point your Autoloader to 'PhpRbac/src' using the 'PhpRbac' namespace.

Example: Using AuraPHP's autoloader
$loader->add('PhpRbac\\', '/path/to/PhpRbac/src');

Using the provided Autoloader

Include the provided autoload.php:

Example:
require_once '/path/to/PhpRbac/autoload.php';

Manually including 'Rbac.php'

Manually include 'Rbac.php':

Example:
require_once '/path/to/PhpRbac/src/PhpRbac/Rbac.php';

You are now ready for the next step: Tutorial