Installation
Installation Guide (Backend & Legacy UI)
This guide explains how to install the AI Brain PHP backend and legacy UI on a web server. For the new React-based interface, please refer to the Next-Gen UI Installation Guide.
Prerequisites
PHP 8.3+ with the following extensions:
php-fpm,php-mysql,php-curl,php-xml,php-mbstring,php-zip,php-gd,php-sqlite3
MySQL (or MariaDB)
Composer (PHP dependency manager)
Web Server (Nginx recommended, or Apache)
SSL Certificate (Required for Google SSO and GitHub Webhooks)
Obtaining API Keys and Secrets
1. Google OAuth (SSO)
Go to the Google Cloud Console.
Create a new project.
Navigate to APIs & Services > OAuth consent screen.
Configure the consent screen, adding the
email,profile, andopenidscopes.Go to APIs & Services > Credentials.
Click Create Credentials > OAuth client ID.
Select Web application as the application type.
Add your
GOOGLE_REDIRECT_URI(e.g.,https://your-domain.com/google/callback.php) to the Authorized redirect URIs.Copy the Client ID and Client Secret.
2. GitHub OAuth App
Go to your GitHub Settings > Developer settings > OAuth Apps.
Click New OAuth App.
Set the Homepage URL to your domain.
Set the Authorization callback URL to your
GITHUB_REDIRECT_URI(e.g.,https://your-domain.com/github/callback.php).Click Register application.
Copy the Client ID and click Generate a new client secret to get your secret.
3. GitHub Webhook Configuration
To receive real-time updates for issue events, you must configure a webhook for each repository you link.
In the application, go to the Project Details page for your linked repository.
Copy the Payload URL and Secret from the “Webhook Configuration” section.
In GitHub, navigate to your repository’s Settings > Webhooks.
Click Add webhook.
Paste the Payload URL.
Set Content type to
application/json.Paste the Secret.
Select Let me select individual events and check Issues.
Ensure Active is checked and click Add webhook.
5. Telegram Bot
Message @BotFather on Telegram.
Use the
/newbotcommand and follow the instructions to get your Bot Token.
a) Installation with SSH
This is the recommended method if you have terminal access to your server.
Clone the repository:
cd /var/www git clone https://github.com/chatelao/ai-brain.git cd ai-brain
Install dependencies:
composer install --no-dev
Set up the database:
Create a MySQL database and user.
Import the schema:
mysql -u your_user -p your_db_name < src/sql/schema.sql
Configure your Web Server: Point your web server’s document root to the
src/frontenddirectory.Example Nginx Configuration:
server { listen 443 ssl; server_name your-domain.com; root /var/www/ai-brain/src/frontend; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # Environment variables fastcgi_param DB_HOST localhost; fastcgi_param DB_NAME your_db_name; fastcgi_param DB_USER your_user; fastcgi_param DB_PASS your_password; # Enable interactive upgrade page (set to 'true' when needed, then remove or set to 'false') # fastcgi_param ENABLE_UPGRADE_PAGE true; # ... add other env vars here ... } }
Set Permissions: Ensure the web server user (e.g.,
www-data) has write access if necessary (though the current architecture mostly uses DB).
b) Manual Deployment via SSH (rsync)
Use this method if you want to deploy from your local machine via SSH.
Build locally: On your local machine, clone the repository and run:
# Build backend composer install --no-dev --optimize-autoloader # Build frontend (Next-Gen UI) cd web npm install npm run build cd .. mkdir -p src/frontend/web cp -r web/out/* src/frontend/web/
Upload files: Use
rsyncto upload the production files to your server:rsync -avz --exclude='.git*' --exclude='.github/' --exclude='test/' \ --exclude='docs/' --exclude='specification/' --exclude='scripts/' \ --exclude='web/' --exclude='*.sqlite' \ ./ user@your-server:/var/www/ai-brain/
Note: Ensure the destination path matches your server configuration.
Set up the database:
Use a tool like phpMyAdmin provided by your hosting.
Create a new database.
Use the “Import” tab to upload and execute
src/sql/schema.sql.
Configure Environment Variables:
If your host allows setting environment variables in a control panel (like cPanel), add them there.
Alternatively, you might need to use an
.htaccessfile (for Apache) or contact your host to setfastcgi_param(for Nginx).
Example
.htaccess(Apache):# # Database Configuration # SetEnv DB_HOST localhost SetEnv DB_NAME your_db_name SetEnv DB_USER your_user SetEnv DB_PASS your_password # # Google OAuth: https://console.cloud.google.com/auth/clients # SetEnv GOOGLE_CLIENT_ID your_google_client_id SetEnv GOOGLE_CLIENT_SECRET your_google_client_secret SetEnv GOOGLE_REDIRECT_URI https://your-domain.com/google/callback.php # # GitHub OAuth: https://github.com/settings/developers # SetEnv GITHUB_CLIENT_ID your_github_client_id SetEnv GITHUB_CLIENT_SECRET your_github_client_secret SetEnv GITHUB_REDIRECT_URI https://your-domain.com/github/callback.php # # Telegram Bot: https://t.me/botfather # # # Administration # SetEnv UPGRADE_ALLOWED_EMAIL your_admin_email@example.com # SetEnv ENABLE_UPGRADE_PAGE true # SetEnv DB_UPGRADE_SECRET your_secure_upgrade_secret
Document Root: Ensure your hosting points the domain to the
src/frontendfolder of the uploaded files.
c) Automated Deployment with GitHub Actions (SSH)
If you have your own fork of this repository, you can use the included GitHub Action to automate the SSH deployment.
Configure Secrets: In your GitHub repository, go to Settings > Secrets and variables > Actions and add the following repository secrets:
SSH_SERVER: Your SSH server hostname or IP address.SSH_USERNAME: Your SSH username.SSH_PASSWORD: Your SSH password.SSH_PATH: The target folder on the remote server.
Trigger Deployment:
Go to the Actions tab in your GitHub repository.
Select the Manual SSH Deploy workflow in the sidebar.
Click the Run workflow dropdown and then Run workflow.
Note: For security, this workflow is configured to only be runnable by the repository owner.
Deployment Details: The workflow will:
Checkout your code.
Install production dependencies via Composer.
Upload the application to your server via SSH (rsync), excluding development and documentation files.
Environment Variables
The application requires several environment variables to be set in your web server configuration (e.g., via fastcgi_param in Nginx):
Variable |
Description |
|---|---|
|
Database host (e.g., |
|
Database name |
|
Database username |
|
Database password |
|
Google OAuth 2.0 Client ID |
|
Google OAuth 2.0 Client Secret |
|
|
|
GitHub OAuth App Client ID |
|
GitHub OAuth App Client Secret |
|
|
|
(Required for upgrades) Email address of the admin user authorized to trigger database migrations on the Admin Dashboard. |
|
(Optional) Set to |
|
(Optional) A secret token that allows automated database upgrades via the “Apply DB Patch” workflow. Should be set in |
Automated Database Upgrades
If you have configured DB_UPGRADE_SECRET in your .htaccess file, you can use the Apply DB Patch workflow to apply pending SQL patches automatically.
Trigger the Workflow:
Go to the Actions tab in your GitHub repository.
Select the Apply DB Patch workflow.
Click Run workflow.
Parameters:
Select patch to apply: Choose ‘all’ to run all pending migrations, or select a specific
.sqlfile.Base URL of the application: Enter the public URL of your application (e.g.,
https://your-domain.com).
Execution:
The workflow will SSH into your server, extract the
DB_UPGRADE_SECRETfrom your.htaccess, and then send an authorized POST request to/upgrade.phpto trigger the migration.