Getting Started
Let's get everything setup correctly so you can start using PHP-RBAC.
Requirements
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.
Installation
Installing PHP-RBAC is a three step process:
- Get the code
- Load the code
- 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" }
Setup the database
Using the GUI Installer
- Navigate to '/path/to/PhpRbac/install.php'
- Enter proper database credentials
- 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
- Create a Database and Database User with the proper permissions
-
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'
-
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';
Continue...
You are now ready for the next step: Tutorial