Networking

How to install the Program O chatbot on a LEMP server

If you want to add a chatbot to your company site, check out Program O. Here's how to get Program O up and running on a Ubuntu 16.04 server.

programohero.jpg
Image: Jack Wallen

Program O is an AIML chatbot written in PHP with MySQL that you can add onto your Linux server. It's a challenge to install, but once Program O is up and running, you can integrate it into your website and even include it with a WordPress plugin.

I'll walk you through the process of installing Program O on a LEMP (Linux NginX MySQL PHP) server. I'll use a fresh install of Ubuntu 16.04 server, so everything will be handled via the command line.

SEE: Linux's 'big' 4.9 release adds support for Raspberry Pi Zero, LG Nexus 5 (ZDNet)

Update Ubuntu

The first thing you want to do is make sure your platform is updated. Open a terminal window (or in the case of a GUI-less server, log in) and issue the commands:

sudo apt-get update
​sudo apt-get upgrade

Issue the command ifconfig so you know what the IP address is for your server.

Prepare your user

Since you'll be running this as your standard user (with the help of sudo), you'll need to add your user to the www-data group. To do this, issue the command (USERNAME is the name of your user):

sudo usermod -a -G www-data USERNAME

Install dependencies

Once that's complete, it's time to start installing the dependencies. You need to install git, as this is what will be used to pull the Program O application to the server. To install git, issue the following command, and then allow that installation to complete.

sudo apt-get install git

Install and configure MySQL

Next install the database component, which in this case is MySQL. To install MySQL, issue the command:

sudo apt-get install mysql-server

During the database server installation, you will be prompted to enter a password to be used by the MySQL admin user (Figure A).

Figure A

Figure A

Creating a password for the MySQL admin user.

Once the database is installed, it's time to create the user and database that will be used for Program O. The first step is to log into the MySQL prompt with the command:

mysql -u root -p

You will be prompted to enter the MySQL admin password.

Once in the MySQL prompt, create the database for Program O. Issue the command:

CREATE DATABASE bots;

Next, create the user that Program O will use. Issue the command:

CREATE USER 'botmaster'@'localhost' IDENTIFIED by 'bot123'

Note: bot123 is the password used by the botmaster user; you can change that to whatever you need.

Change to the bots database with the command:

USE DATABASE bots;

Grant the new user privilege to use the new database with the command:

GRANT ALL PRIVILEGES ON *.* TO 'botmaster'@'localhost';

Exit out of the MySQL prompt with the command exit.

Install Nginx

The next step is installing the web server to be used by Program O. To install Nginx, issue the command:

sudo apt-get install nginx

Install and configure PHP

PHP must now be installed, with a number of added components. To do this, issue the command:

sudo apt-get install -y php-fpm php-mysql php7.0-mbstring php7.0-zip php7.0-xml

Let's configure PHP. Open the /etc/php/7.0/fpm/php.ini file in your favorite text editor and search for the line:

;cgi.fix_pathinfo=1

Change that line to:

cgi.fix_pathinfo=0

Save and close the php.ini file. Restart the PHP preprocessor with the command:

sudo systemctl restart php7.0-fpm

Finally, restart Nginx with the command:

sudo service nginx restart

Configure Nginx for PHP

You must make Nginx aware of PHP. To do this, open the /etc/nginx/sites-available/default file. The first thing you need to do is search for the line:

server_name _;

Change that line to reflect the IP address of your server, like so:

server_name 192.168.1.100;

In the above example I entered a random IP address, but you will add the IP address the ifconfig reported earlier.

Now search for the section that begins with the line root /var/www/html; and locate the line index index.html index.htm index.nginx-debian.html;. You need to modify that line to include index.php, so that it looks like:

index index.php index.html index.htm index.nginx-debian.html;

Finally, locate this section:

#location ~ \.php$ {
​#include snippets/fastcgi-php.conf;
​#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
​#}
​#location ~ /\.ht {
​#deny all;
​#}
​#}

Uncomment the above by removing all the leading # characters.

Save the default file and test Nginx with the command:

nginx -t

You shouldn't see any errors listed. Restart Nginx with the command:

sudo service nginx restart

Download and install Program O

It's time to download and configure Program O for installation. Change into the /var/www/html directory and issue the command:

sudo git clone https://github.com/Program-O/Program-O.git

This will download a new folder called Program-O. Before you run the installation of the program, you must change the permission and ownership of two folders. To do that, issue the following commands:

sudo chown -R www-data:www-data /var/www/html/Program-O
​sudo chown -R www-data:www-data /var/log/nginx

You can now run the installation script by pointing a web browser to http://IP_ADDRESS/Program-O/install/install_programo.php (IP_ADDRESS is the server's IP address). When the installation page is presented (Figure B), enter the necessary information and click Save.

Figure B

Figure B

The Program O installation page.

That's it! Your server and bot are configured. All you have to do is upload your AIML files. Point your browser to http://IP_OF_SERVER/Program-O/admin and log in with the administrator credentials you created on the installation page. Once authenticated, you are ready to upload your AIML files and administer your bot!

Tailor the chatbot to meet your needs

You've accomplished the hardest part of getting your Program O chatbot up and running. You still have much work to do in order to tailor the bot to meet your needs (creating your bot personality, teaching your bot, and much more); but that work is all done through the Program O web interface. After you complete the process, the bot will be ready to serve.

Also see

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox