Installation Guide
This guide covers the complete installation and configuration of the SUNAT Electronic Invoicing API on your server.System Requirements
Minimum Requirements
PHP
Version 8.2 or higher with required extensions
Database
MySQL 8.0+ or PostgreSQL 12+
Composer
Latest stable version for dependency management
Web Server
Apache 2.4+ or Nginx 1.18+ (optional for production)
Required PHP Extensions
Verify these extensions are installed and enabled:openssl- For certificate handlingpdo_mysqlorpdo_pgsql- Database connectivitymbstring- Multibyte string handlingtokenizer- Laravel requirementxml- XML processingctype- Character type checkingjson- JSON handlingbcmath- Arbitrary precision mathematicscurl- HTTP requests to SUNATfileinfo- File type detectionzip- Handling CDR zip files
Step 1: Clone the Repository
Clone the project from GitHub:Alternatively, download the ZIP file and extract it to your preferred location.
Step 2: Install Dependencies
Install all required PHP packages using Composer:| Package | Version | Purpose |
|---|---|---|
| laravel/framework | ^12.0 | Core framework |
| greenter/lite | ^5.1 | SUNAT integration |
| greenter/consulta-cpe | * | CPE query service |
| dompdf/dompdf | ^3.1 | PDF generation |
| endroid/qr-code | * | QR code creation |
| laravel/sanctum | ^4.0 | API authentication |
Installation time: Composer installation typically takes 2-5 minutes depending on your internet connection.
Step 3: Environment Configuration
Create your environment configuration file:Generate Application Key
Configure Environment Variables
Edit the.env file with your settings:
Step 4: Database Setup
Create Database
- MySQL
- PostgreSQL
Run Migrations
Execute database migrations to create all required tables:Core Tables
Core Tables
users- System users and authenticationroles- User roles (super_admin, admin, user)permissions- Granular permissionsrole_permission- Role-permission mappingpersonal_access_tokens- API tokens (Sanctum)
Company Tables
Company Tables
companies- Issuing companiescompany_configurations- Per-company settingsbranches- Branch officesclients- Customers and supplierscorrelatives- Document series and numbering
Document Tables
Document Tables
invoices- Electronic invoices (Facturas)boletas- Sales receiptscredit_notes- Credit notes (future)debit_notes- Debit notes (future)
Ubigeo Tables
Ubigeo Tables
ubi_regiones- Peru regionsubi_provincias- Provincesubi_distritos- Districts
System Tables
System Tables
jobs- Queue jobscache- Application cachesessions- User sessions
Expected output: All migrations should run successfully with no errors
Step 5: Certificate Setup
Understanding SUNAT Certificates
SUNAT requires a digital certificate to sign electronic documents. You’ll receive a.pfx file from your certificate provider.
Convert Certificate to PEM Format
The API uses.pem format certificates. Convert your .pfx file:
-in certificado.pfx- Input file-out certificado.pem- Output file-nodes- Don’t encrypt the private key
Place Certificate in Correct Location
For testing: SUNAT provides test certificates for the beta environment. Contact SUNAT or use the credentials from their documentation.
Verify Certificate
Validate your certificate is correctly formatted:.pem file:
Step 6: Storage Permissions
Set correct permissions for Laravel storage and cache:Step 7: Test the Installation
Start Development Server
http://localhost:8000
Verify API is Running
Test the system info endpoint:If
database_connected: true, your installation is successful!Step 8: Optional - Seed Sample Data
Load sample ubigeo (geographic) data:Production Deployment
Optimization Commands
Before deploying to production:Production Environment
Update.env for production:
Web Server Configuration
- Nginx
- Apache
SSL/HTTPS Setup
For production, always use HTTPS:Queue Configuration (Optional)
For better performance, configure queues:Troubleshooting
500 Internal Server Error
500 Internal Server Error
Symptoms: White page or 500 errorSolutions:
- Check storage permissions:
chmod -R 775 storage - Clear cached config:
php artisan config:clear - Check Laravel logs:
tail -f storage/logs/laravel.log - Verify .env file exists and APP_KEY is set
Database Connection Failed
Database Connection Failed
Symptoms:
SQLSTATE[HY000] [2002] Connection refusedSolutions:- Verify database is running:
systemctl status mysql - Check credentials in
.env - Test connection:
php artisan migrate:status - Verify database exists:
SHOW DATABASES;
Certificate Not Found
Certificate Not Found
Symptoms:
Archivo de certificado no encontradoSolutions:- Verify path:
ls -l storage/app/public/certificado/ - Check file exists:
certificado.pem - Verify permissions:
chmod 644 certificado.pem - Check certificate format with openssl
Composer Memory Exhausted
Composer Memory Exhausted
Symptoms:
Fatal error: Allowed memory size exhaustedSolutions:- Increase PHP memory:
php -d memory_limit=-1 /usr/bin/composer install - Or update php.ini:
memory_limit = 512M
Permission Denied Errors
Permission Denied Errors
Symptoms: Cannot write to storage/logsSolutions:
Verification Checklist
Before proceeding to create invoices:Next Steps
Now that installation is complete:Quickstart Guide
Create your first invoice in 10 minutes
API Reference
Explore all available endpoints
Authentication
Learn about API authentication
Configuration
Advanced configuration options
Getting Help
If you encounter issues during installation:
- Check the GitHub Issues
- Review Laravel logs in
storage/logs/laravel.log - Watch the YouTube tutorial series
- Contact via WhatsApp
