These instructions are for installing TrainMyAI on your own server.
If you prefer an instant trial of the product, fill out this form for a free cloud-based demo.
Requirements
- Modern 64-bit Linux server. TrainMyAI has been tested on Ubuntu 18/20/22, Debian 10/11/12 and CentOS Stream 8/9. It is also expected to work on other distros which meet all the requirements.
- At least 4 GB of memory and a 40 GB SSD drive.
- Apache 2.x.
- MySQL/MariaDB 5.5 or later.
- PHP 7.2 or later.
- An OpenAI/ChatGPT API key (paid account recommended).
Installation time
If you're new to TrainMyAI, expect to spend around half an hour installing and configuring it. Once you're familiar with the process, this can be reduced to around 15 minutes.Getting help
If you encounter any problems with these instructions, please contact us with the following information:
- A description of the problem, including any error messages shown.
- Linux distribution, e.g. Ubuntu 22.
- MySQL/MariaDB version.
- PHP version.
- Any relevant lines of Apache's error_log file.
You can run the following set of commands to collect much of this information together:
grep PRETTY_NAME /etc/os-release ; mysql --version ; php -v
sudo grep -s PHP /var/log/httpd/error_log /var/log/apache2/error.log | tail -n 10
1. Install prerequisites
First, TrainMyAI needs a few common packages to be installed on your Linux server.- Ensure Apache, PHP and MySQL are installed and active. The process will depend on the version of Linux you are using – there are tons of guides available online.
-
To enable extracting text from PDF, DOC and DOCX files, install Poppler, catdoc and docx2txt:
Ubuntu/Debian sudo apt install poppler-utils catdoc docx2txt
CentOS sudo yum install poppler-utils
-
Install any other required packages that might be missing:
Ubuntu/Debian sudo apt install curl php-curl php-json wget tar nano
CentOS sudo yum install curl php-curl php-json wget tar nano
2. Install files and directories
Now's we're going to download and install TrainMyAI, and create a directory for it to store its files.-
Use
cd
to navigate to a directory in which to create the TrainMyAI directory. For security reasons, this should not be within the web content directory (we'll create the necessary link later on). You can install TrainMyAI in any location, so long its files are readable by the web server. -
Download and install TrainMyAI:
wget https://trainmy.ai/download/trainmyai-1.0.tar.gz
tar -xzf trainmyai-1.0.tar.gz
cd trainmyai -
Decide where TrainMyAI should store its data directory, e.g.
/home/trainmyai_data
(example used below) and create this directory:sudo mkdir /home/trainmyai_data
-
Ensure this data directory is owned by the same user which runs the Apache web server, as follows:
Ubuntu/Debian sudo chown www-data /home/trainmyai_data
CentOS sudo chown apache /home/trainmyai_data
3. Create the database
TrainMyAI stores some of its information in a MySQL or MariaDB database, which we'll now set up.-
Choose a database name (e.g.
trainmyai_db
), user name (e.g.trainmyai_user
) and password (denoted by<password>
below) for the TrainMyAI database and note them down. We will use these examples below and assume the database is running on the same server as the website. -
Log in to MySQL or MariaDB as the root user, entering the MySQL root password:
mysql -u root -p
-
Create the TrainMyAI database, user and grant all privileges:
CREATE USER 'trainmyai_user'@'localhost' IDENTIFIED BY '<password>';
CREATE DATABASE trainmyai_db;
GRANT ALL PRIVILEGES ON trainmyai_db.* TO 'trainmyai_user'@'localhost'; -
Type
exit
to leave the MySQL command line.
4. Configure TrainMyAI
Now it's time to set up TrainMyAI to use the chosen data directory, database and your OpenAI account.-
Make a copy of the TrainMyAI example configuration file:
cp config-example.ini config.ini
-
Use your favorite text editor to start editing
config.ini
, e.g.nano config.ini
. -
Decide whether TrainMyAI should be at the root of your web site or in a subdirectory. If it will be at the root, leave
url_base = /
as is. Otherwise, set it accordingly, e.g.url_base = /trainmyai/
-
Set
data_directory
to the full path of the directory created for TrainMyAI to store its files, e.g./home/trainmyai_data
-
Enter the MySQL or MariaDB database credentials chosen earlier in the
[database]
section. -
Enter your OpenAI API key in the
api_key
setting of the[openai]
section. We strongly recommend adding a payment method to your OpenAI account, rather than just using the free trial credits. This will increase the API rate limit and let you test TrainMyAI properly. Each TrainMyAI chat response costs well under $0.01 (excluding GPT-4). - Save the changes to disk and exit the text editor.
5. Set up the web site
We'll now set up your web server to work with TrainMyAI.-
Create a symbolic link in your web server's content directory to the
html
directory of TrainMyAI. For example to serve it in thetrainmyai
subdirectory of your web site, create a symbolic link as follows:sudo ln -s $(pwd)/html /var/www/html/trainmyai
If you prefer to serve TrainMyAI at the root of your website, do this instead:sudo mv /var/www/html /var/www/html-old
Note that servers running SELinux may prevent these symbolic links being followed. You can use the
sudo ln -s $(pwd)/html /var/www/htmlgetenforce
command to check (if the command is not found, SELinux is not installed). If SELinux is installed, you may need to configure it to allow Apache to access this directory. -
Ensure that Apache is configured to follow symbolic links and
.htaccess
files. To do this, use your favorite text editor to modify Apache's configuration file, e.g. using nano:Ubuntu/Debian sudo nano /etc/apache2/apache2.conf
CentOS sudo nano /etc/httpd/conf/httpd.conf
-
Add the following block at the end of the configuration file:
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
</Directory> - Save the changes to disk and exit the text editor.
-
Activate Apache's rewrite module (where required) and restart the web server:
Ubuntu/Debian sudo a2enmod rewrite
sudo systemctl restart apache2CentOS sudo systemctl restart httpd
6. Create cron job
Some of TrainMyAI's tasks are asynchronous, meaning that they aren't activated directly by a web request. To keep these moving, we need to set a cron job to make regular requests to a special web page.-
Start editing the crontab file for your user:
crontab -e
-
If the interface is unfamiliar, you're probably using Vi/Vim, so press
i
to enter insert mode. -
Add in the following line, substituting the appropriate URL for your TrainMyAI site. For example, if TrainMyAI is at
https://my-site.com/trainmyai/
you would add:* * * * * wget -O - https://my-site.com/trainmyai/trainmyai_async >>/dev/null 2>&1
-
Save changes to disk and exit the editor. (To do this in Vi/Vim, press
escape
then:wq
.)
7. Install loader and verify
We're nearly there. The last step is to install the SourceGuardian loader and verify the installation.-
Open the installation verification page
verify-install.php
in your web browser. For example,https://my-site.com/trainmyai/verify-install.php
-
If you see a 'Forbidden' error, this is because the web server does not have permission to look within the directory containing the
trainmyai
directory, but this can be fixed. -
Follow the instructions on the page to install the SourceGuardian loader. To download the loader directly on the server, copy the link for the loader given in the page and run the following:
wget --content-disposition -U agent '<url>'
-
Follow the SourceGuardian instructions to move the downloaded
ixed...
file to the correct directory and edit PHP's configuration file. -
Restart the web server:
Ubuntu/Debian sudo systemctl restart apache2
CentOS sudo systemctl restart httpd
-
Refresh the installation verification page. If the SourceGuardian message is still appearing, try running
sudo systemctl reload php-fpm
and refresh again. - You should be told the database was created and whether anything is missing. If you see a message about cron never being called, wait a minute then refresh the page again.
- Click the link to go to TrainMyAI, and sign up as the first user. This user will automatically be given full admin permissions.
That's everything! Now you can create the first knowledge base and start adding content.
When you're ready, you can also start learning about customization or API integration.