How to install Program-O with the LEMP stack

Program-O is an environment that allows you to host chatbots. As of this writing, it is AIML version 1.1 compliant. Its interface is easy to use and you can get started easily. However, installation can take some time and troubleshooting. Here is the guide I wish I had when I began installing Program-O.

My environment

  • Ubuntu 16.04 64bit
  • Nginx
  • MySQL
  • PHP
  • Vmware workstation and player version 12 running on Windows 10 professional 64bit.
  • Your machine obtains its IP address automatically via DHCP.

Prepareing Ubuntu

If you are starting from scratch, let the automatic installer handle the creation of the virtual machine. Follow the prompts and you will be fine. The only thing you should change is the network connection. I have set mine to bridged and to replicate the state of the physical network connection. This way, the virtual machine gets its own IP address and comes up with a working connection to your LAN. Once you have ubuntu installed, you will have to add a SSH server. You can install this using the gui but I will cover the commandline approach. Once you are at the ubuntu desktop, hit ctrl+alt+t to get into the terminal. Then type
sudo apt-get update
to ensure that the package repositories are updated and then type
sudo apt-get install openssh-server -y
this command will download and install the SSH server.
You can then run ifconfig to see the address that has been assigned to your virtual machine.
Exit the terminal and return to Windows. Use a terminal emulator to login into your virtual machine.

Configuring users and groups

You do not run as root in ubuntu. The user you created at the time of installation has sudo access. It is tempting to do everything as root but avoid that temptation because you may have to do a fair bit of ownership changes once you are ready to deploy your machine. You need to add your user to the www-data group. You will need this to work with nginx. To do this, run the following command.
usermod -a -G www-data bob

Note

I am working on the assummption that bob is your user name.
This completes the ubuntu configuration.

Installing git

You will need a git client to pull Program-O from its git repository. Git is not installed on ubuntu by default. You can install it by typing the following command into the terminal.
sudo apt-get install git -y

Installing the components required for Program-O

MySQL

The first thing you need is the MySQL database server. You can install it by issuing the following command and following the prompts.
sudo apt-get install mysql-server -y
You should secure your MySQL installation. Run the following command.
sudo mysql_secure_installation
You do not need the test database. Once this script has finished running, login into the MySQL database by typing the following command.
mysql -u root -p
Once you are in, you need to create a database. You can do this by issuing the command
create database bots;
You need a database user too as you do not want the root user doing any work with the database.
CREATE USER ‘botmaster’@’localhost’ IDENTIFIED BY ‘bot123’;
you then issue the command
use database bots;
At this point, you have a user and a blank database but the user cannot do anything. You need to make the user capable of administering the bots database.
GRANT ALL PRIVILEGES ON * . * TO ‘botmaster’@’localhost’;

Nginx

It is now time to setup the web server which is nginx. To install nginx, issue the followig command at the terminal.
sudo apt-get install nginx -y

Install php

It is time to install php. Nginx can serve static content but your chatbot is dynamic content because its input and output will change. Program-O also needs to write configuration values to the server.
sudo apt-get install -y php-fpm php-mysql php7.0-mbstring php7.0-zip php7.0-xml 
You need to change one setting in the php configuration to make things more secure. See the references section for details. Execute the following command.
sudo nano /etc/php/7.0/fpm/php.ini
You can use any editor of your choice.
Change thecgi.fix_pathinfo=1 to
cgi.fix_pathinfo=0
remembering to uncomment the above line.
Restart the php preprocessor by issuing the following command.
sudo systemctl restart php7.0-fpm
also restart the web server by using the below command.
 service nginx reload

Configuring nginx to use php

If you have followed this guide, everythingng that you need to run Program-O should be installed. You have to configure nginx to use php. This involves careful editing of the nginx configuration file. Do not be distracted by the comments in that file.
sudo nano /etc/nginx/sites-available/default
Again, you can use whatever editor you want.
The first thing we do is to set our server’s name or ip address to prevent unnecessary warnings. The chances are that you do not have a local domain name server running so set the IP of your virtual machine here.
server_name 192.168.xx.xxx
Find the line that reads
root /var/www/html;
Note the line below it.
index index.html index.htm index.nginx-debian.html;
You need to add index.php to the above line so that nginx first servers files with a php extention. The modified line looks like this.
index index.php index.html index.htm index.nginx-debian.html;
You now need to uncomment the following lines.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Once you have completed these changes, save the file. It is crucial to test it for errors. To do this, run the following command.
sudo nginx -t
If there are no errors, move on. If you encounter errors, recheck what you changed.

Installing Program-O

You need to get the Program-O files into the web root of your web server. This should be /var/www/html if you have not changed this in nginx. To install Program-O, do the following.

  1. cd /var/www/html
  2. sudo git clone https://github.com/Program-O/Program-O.git

Setting ownership and permissions

One of the trickiest things when configuring web servers and web applications is to set the right ownership of files and folders. You have to get this right else php will be unable to write configuration information or logs may not be generated in the event of errors etc.
The web server files should not be owned by root and php should be permitted to write to the folders under the Program-O folder.To do all of this, execute the following commands.
sudo chown -R www-data:www-data /var/www/html/Program-O
The /var/logs/nginx folder should also be owned by www-data so that logs can be created.
sudo chown -R www-data:www-data /var/log/nginx

Running the installation script

You are ready to run the Program-O installation. Launch a web browser and navigate to the following link.
http://your_virtual_machine_ip_address/Program-O/install/install_programo.php
Follow the prompts and if there are no errors, you should be good to go and setup your chatbot.

References


Filed under: commonTasks,robotics — Tags: , , , — security-writer @ October 2, 2016 12:53