Skip to main content

Prerequisites

Before setting up your development environment, ensure your system meets these requirements:

System Requirements

PHP

Version: 8.1 or higherCheck version: php -v

Database

MySQL 5.7+ or PostgreSQL 9.6+Choose one based on your preference

Web Server

Apache 2.4+ or Nginx 1.18+With PHP-FPM support

Composer

Latest stable versionFor dependency management

Required PHP Extensions

Verify these extensions are installed:
php -m | grep -E "curl|gd|intl|mbstring|pdo_mysql|xml|zip"
  • curl: HTTP client for API requests
  • gd: Image processing
  • intl: Internationalization
  • mbstring: Multibyte string handling
  • pdo_mysql or pdo_pgsql: Database connectivity
  • xml: XML parsing
  • zip: ZIP file handling for plugins
sudo apt-get update
sudo apt-get install php8.1-cli php8.1-curl php8.1-gd php8.1-intl \
                     php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip
brew install [email protected]
brew install composer

Installation

Step 1: Clone the Repository

Clone FacturaScripts from GitHub:
# Clone the repository
git clone https://github.com/NeoRazorX/facturascripts.git
cd facturascripts

# Checkout the stable branch (recommended for development)
git checkout stable
Use the stable branch for plugin development. The master branch contains the latest development code and may be unstable.

Step 2: Install Dependencies

Install PHP dependencies using Composer:
composer install
This will install:
  • Twig template engine
  • Symfony components
  • Testing frameworks
  • Other required libraries

Step 3: Configure the Web Server

Create a virtual host configuration:
<VirtualHost *:80>
    ServerName facturascripts.local
    DocumentRoot /path/to/facturascripts
    
    <Directory /path/to/facturascripts>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/facturascripts-error.log
    CustomLog ${APACHE_LOG_DIR}/facturascripts-access.log combined
</VirtualHost>
Enable required modules and restart:
sudo a2enmod rewrite
sudo systemctl restart apache2
Add to /etc/hosts:
127.0.0.1 facturascripts.local

Step 4: Set Directory Permissions

FacturaScripts needs write access to specific directories:
# Create necessary directories
mkdir -p MyFiles Dinamic Plugins

# Set permissions (adjust user/group for your system)
chmod -R 775 MyFiles Dinamic Plugins
chown -R www-data:www-data MyFiles Dinamic Plugins

# Or for development (less secure, but easier):
chmod -R 777 MyFiles Dinamic Plugins

Step 5: Create Database

Create a database for FacturaScripts:
CREATE DATABASE facturascripts CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'fs_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON facturascripts.* TO 'fs_user'@'localhost';
FLUSH PRIVILEGES;

Step 6: Initial Setup

Visit your FacturaScripts installation in a browser:
http://facturascripts.local
You’ll see the installation wizard. Complete these steps:
1

Database Configuration

  • Database Type: MySQL or PostgreSQL
  • Host: localhost (or 127.0.0.1)
  • Port: 3306 (MySQL) or 5432 (PostgreSQL)
  • Database Name: facturascripts
  • Username: fs_user
  • Password: Your database password
2

Admin Account

  • Username: Choose an admin username
  • Email: Your email address
  • Password: Secure password
3

Company Information

  • Company Name: Your development company name
  • Tax ID: Test tax ID (can be changed later)
  • Country: Select your country
4

Finish

Click “Install” and wait for the process to complete.

Development Tools Setup

Code Editor Configuration

Recommended extensions:
{
  "recommendations": [
    "bmewburn.vscode-intelephense-client",
    "xdebug.php-debug",
    "whatwedo.twig",
    "editorconfig.editorconfig",
    "recca0120.vscode-phpunit"
  ]
}
Create .vscode/settings.json:
{
  "php.suggest.basic": false,
  "intelephense.files.exclude": [
    "**/node_modules/**",
    "**/vendor/**",
    "**/Dinamic/**"
  ],
  "files.associations": {
    "*.twig": "twig"
  }
}
Install Xdebug for debugging:
# Install Xdebug
sudo apt-get install php8.1-xdebug

# Or with PECL
sudo pecl install xdebug
Configure Xdebug in php.ini or create /etc/php/8.1/mods-available/xdebug.ini:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host=localhost
Restart your web server:
sudo systemctl restart apache2
# or
sudo systemctl restart php8.1-fpm

Git Configuration

Set up Git for version control:
# Configure Git
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# Create .gitignore for your plugin
cat > .gitignore << EOF
/MyFiles/
/Dinamic/
/vendor/
/node_modules/
config.php
.env
*.log
EOF

Creating Your First Plugin

Step 1: Create Plugin Directory

# Create plugin structure
mkdir -p Plugins/MyFirstPlugin/{Controller,Model,View,Assets}
cd Plugins/MyFirstPlugin

Step 2: Create Plugin Metadata

Create facturascripts.ini:
name = "MyFirstPlugin"
version = 1.0
min_version = 2024.1
description = "My first FacturaScripts plugin"
author = "Your Name"

Step 3: Create Initialization File

Create Init.php:
<?php
namespace FacturaScripts\Plugins\MyFirstPlugin;

use FacturaScripts\Core\Base\InitClass;

class Init extends InitClass
{
    public function init(): void
    {
        // Plugin initialization code
    }
    
    public function update(): void
    {
        // Update logic when plugin version changes
    }
}

Step 4: Create a Simple Controller

Create Controller/HelloWorld.php:
<?php
namespace FacturaScripts\Plugins\MyFirstPlugin\Controller;

use FacturaScripts\Core\Base\Controller;

class HelloWorld extends Controller
{
    public function getPageData(): array
    {
        $data = parent::getPageData();
        $data['title'] = 'Hello World';
        $data['icon'] = 'fa-solid fa-hand-wave';
        $data['menu'] = 'admin';
        return $data;
    }
    
    public function privateCore(&$response, $user, $permissions): void
    {
        parent::privateCore($response, $user, $permissions);
        // Your controller logic here
    }
}

Step 5: Create a View Template

Create View/HelloWorld.html.twig:
{% extends "Master/MenuTemplate.html.twig" %}

{% block body %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h1>Hello World!</h1>
            <p>Welcome to your first FacturaScripts plugin.</p>
        </div>
    </div>
</div>
{% endblock %}

Step 6: Activate Your Plugin

1

Access Plugin Manager

Navigate to: Admin → Plugins (or /AdminPlugins)
2

Find Your Plugin

Your plugin “MyFirstPlugin” should appear in the list
3

Enable Plugin

Click the toggle or “Enable” button
4

Wait for Deployment

FacturaScripts will:
  • Merge your plugin code into Dinamic/
  • Rebuild routes
  • Update database schema
5

Access Your Controller

Visit: http://facturascripts.local/HelloWorld
After enabling your plugin, you’ll find the merged code in Dinamic/Controller/HelloWorld.php. This is the actual file that gets executed.

Development Workflow

Making Changes

When developing plugins:
1

Edit Source Files

Make changes in Plugins/YourPlugin/ directory
2

Redeploy

Go to Admin → Plugins and click “Deploy” or “Rebuild”
3

Test Changes

Changes are merged into Dinamic/ and immediately active
4

Debug Issues

Check logs in MyFiles/ directory

Using the Command Line

FacturaScripts provides CLI tools:
# Rebuild routes
php index.php rebuildRoutes

# Update database
php index.php updateDB

# Clear cache
php index.php clearCache

# Run cron tasks
php index.php cron

Debugging Tips

Edit config.php (create if it doesn’t exist):
<?php
define('FS_DEBUG', true);
This enables verbose error messages.
Logs are stored in:
  • Application logs: MyFiles/error.log
  • Web server logs: /var/log/apache2/ or /var/log/nginx/
  • PHP errors: Check php.ini for error_log location
Enable query logging in config.php:
define('FS_DB_LOG', true);
Queries are logged to MyFiles/database.log
For quick debugging:
var_dump($variable);
exit; // Stop execution
Or use FacturaScripts logger:
use FacturaScripts\Core\Tools;

Tools::log()->debug('Variable value: ' . print_r($variable, true));

Testing

PHPUnit Setup

FacturaScripts includes PHPUnit for testing:
# Run all tests
./vendor/bin/phpunit

# Run specific test
./vendor/bin/phpunit tests/Core/KernelTest.php

# Run plugin tests
./vendor/bin/phpunit -c phpunit-plugins.xml

Writing Tests

Create Test/ directory in your plugin:
<?php
namespace FacturaScripts\Test\Plugins\MyFirstPlugin;

use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
{
    public function testExample(): void
    {
        $this->assertTrue(true);
    }
}

Troubleshooting

  • Check PHP error logs
  • Verify file permissions (775 or 777 for development)
  • Ensure all required PHP extensions are installed
  • Check .htaccess file exists (copy from htaccess-sample)
  • Verify facturascripts.ini exists and is valid
  • Check plugin directory name matches name in INI file
  • Ensure Plugins/ directory has correct permissions
  • Try refreshing the plugin list
  • Click “Deploy” in Plugin Manager to rebuild Dinamic/
  • Clear browser cache (Ctrl+Shift+R)
  • Check if you’re editing the right file (not Dinamic/)
  • Verify plugin is enabled
  • Verify database credentials in installer or config.php
  • Check database server is running
  • Test connection with mysql -u fs_user -p or psql -U fs_user
  • Ensure user has correct privileges

Next Steps

Now that your development environment is ready:

Creating Plugins

Learn to build complete plugins with models, controllers, and views.

Controllers

Master controller development and request handling.

Models & Database

Work with the ORM and database layer.

Best Practices

Follow coding standards and best practices.
Join the FacturaScripts community on GitHub for help, discussions, and to share your plugins!

Build docs developers (and LLMs) love