How to install and Configure CodeIgniter / GroceryCRUD

Post Reply
User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

How to install and Configure CodeIgniter / GroceryCRUD

Post: # 504Post LHammonds
Tue May 02, 2017 3:20 pm

Overview

CodeIgniter is an application framework for PHP web apps. GroceryCRUD is a library for CodeIgniter that allows you to make an application in seconds that can Create, Read, Update and Delete records in your database. It is great for a quick front-end or back-end administration tool for data entry.

Software Used in this Article
  1. Ubuntu Server 16.04.2 LTS
  2. Apache Web Server 2.4.18
  3. MariaDB 10.1.23
  4. PHP 7.0.15
  5. CodeIgniter 3.1.4
  6. GroceryCRUD 1.5.8
  7. PuTTY 0.62
This article will assume you have an Ubuntu Server setup similar to this tutorial.

It will also be assumed you have a separate dedicated MariaDB / MySQL database server.

Wherever you see RED in this document, you need to substitute it for what your company uses. Use the list below as a template you need to have answered before you continue.
  • Ubuntu Server name: srv-php
  • Ubuntu Server IP address: 192.168.107.55
  • Ubuntu Admin ID: administrator
  • Ubuntu Admin Password: myadminpass
  • MySQL Server (remote): srv-mysql (192.168.107.20)
  • MySQL example user: grocerycruduser
  • MySQL example Password: grocerycrudpass
I also assume the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Install Ubuntu Server

Post: # 505Post LHammonds
Tue May 02, 2017 3:27 pm

Install Ubuntu Server

The Ubuntu Server Long-Term Support (LTS) is free but we have the option of buy support and that is the main reason this server was selected.

The steps for setting up the base server are covered in this article: How to install and configure Ubuntu Server

User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Install Apache Web Server and PHP

Post: # 506Post LHammonds
Tue May 02, 2017 3:27 pm

Install Apache Web Server and PHP
  1. Connect to the SRV-PHP server using PuTTY.
  2. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privileges by typing sudo su
  3. Type the following commands:

    Code: Select all

    apt -y install apache2 php7.0 libapache2-mod-php7.0 php7.0-mysql
  4. Once that is done, open a web browser and go to http://192.168.107.55 and you should see a web page that says "It works!"
Install CodeIgniter
  1. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privileges by typing sudo su
  2. Type the following commands:

    Code: Select all

    mkdir /var/www/html/ci
    cd /tmp
    wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.4.zip -O /tmp/codeigniter.zip
    unzip /tmp/codeigniter.zip
    mv /tmp/CodeIgniter*/* /var/www/html/ci/.
    chown www-data:root /var/www/html/ci -R
    
Install GroceryCRUD
  1. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privileges by typing sudo su
  2. Type the following commands:

    Code: Select all

    cd /tmp
    wget https://github.com/scoumbourdis/grocery-crud/archive/v1.5.8.1.zip -O /tmp/grocerycrud.zip
    unzip /tmp/grocerycrud.zip
    cp /tmp/grocery-crud*/* /var/www/html/ci/. -R
    chown www-data:root /var/www/html/ci -R
    
Configure MariaDB / MySQL

In this scenario, a dedicated and general-purpose database server already exists and it will be used to hold the application's database.
  1. Connect to the MariaDB/MySQL server using PuTTY.
  2. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privileges by typing sudo su
  3. Type the following commands:
    mysql -u root -p Enter password: rootpass
    CREATE DATABASE grocerycrud CHARACTER SET utf8 COLLATE utf8_bin; CREATE USER 'grocerycruduser'@'%' IDENTIFIED BY 'grocerycruduserpass'; GRANT ALL ON grocerycrud.* TO 'grocerycruduser'@'%'; FLUSH PRIVILEGES; exit
    The above commands will allow the database account to connect from any machine from anywhere in the world. This might be OK if your database is not accessible outsite your local network or if your machine name changes or you have multiple servers that connect to the same database that use the same ID. You can make this more secure by specifying your application server when granting access. Make sure the database server will recognize the server name (via hosts file or DNS) or just use the IP address:
    CREATE USER 'grocerycruduser'@'srv-grocerycrud' IDENTIFIED BY 'grocerycruduserpass'; GRANT ALL ON grocerycrud.* TO 'grocerycruduser'@'srv-grocerycrud';
    or
    CREATE USER 'grocerycruduser'@'192.168.107.55' IDENTIFIED BY 'grocerycruduserpass'; GRANT ALL ON grocerycrud.* TO 'grocerycruduser'@'192.168.107.55';
    This will prevent anyone knowing the credentials from logging into the database from any other remote machine not specified in the grant command.

    If your application is running on the database server (typical on a developer machine / non-production scenario), create the user like this:
    CREATE USER 'grocerycruduser'@'localhost' IDENTIFIED BY 'grocerycruduserpass'; GRANT ALL ON grocerycrud.* TO 'grocerycruduser'@'localhost';
    This will prevent anyone knowing the credentials from logging into the database from any other remote machine.

    If you mess anything up, you can remove the database and user by issuing these commands:
    DROP USER grocerycruduser; FLUSH PRIVILEGES; DROP DATABASE grocerycrud;
Install Example Database
  1. Extract the example SQL archive:

    Code: Select all

    cd /var/www/html/ci
    unzip examples_database.sql.zip
  2. Copy the SQL file to your MySQL or MariaDB server:
    scp /var/www/html/ci/examples_database.sql administrator@srv-mysql:/tmp/.
  3. On your database server, import the example tables and data:

    Code: Select all

    mysql grocerycrud < /tmp/examples_database.sql
    
Link CodeIgniter to the Database
  1. Edit the database file and set the following values:

    Code: Select all

    vi /var/www/html/ci/application/config/database.php
    'hostname' => 'srv-mysql', 'username' => 'grocerycruduser', 'password' => 'grocerycruduserpass', 'database' => 'grocerycrud', 'dbdriver' => 'mysqli',
  2. Edit the config file and set the applications base URL:

    Code: Select all

    vi /var/www/html/ci/application/config/config.php
    $config['base_url'] = 'http://192.168.107.55/ci';
  3. Visit the examples page and see if it worked: http://192.168.107.55/ci/index.php/examples

Post Reply