ocilapp

Get started with CodeIgniter

Overview

The CodeIgniter framework is installed in the frameworks/codeigniter directory in the installation directory. This directory includes an example application. Application configuration files are in the conf/ directory and public files, such as HTML pages, CSS and JavaScript files, images and other media assets are stored in the htdocs/ directory.

Activation and Testing

To enable the example application, edit the Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf and uncomment the following line

Include "/opt/bitnami/frameworks/codeigniter/conf/httpd-prefix.conf"

Then, restart the Apache server.

$ sudo /opt/bitnami/ctlscript.sh restart apache

You can now verify that the example application is working by visiting its URL using your browser at http://SERVER-IP/codeigniter.

Here is an example of what you might see:

CodeIgniter welcome page

Configuration

Before using the example application, here are a few important points to consider:

  • To secure your application session, modify the encryption keys in the application/config/config.php file. Ideally, use a key that’s 32 characters or longer in length.

    $config['encryption_key'] = '';
    

    On Linux, you can use a command like pwgen 32 to generate a 32-character random key. On Windows, you can use a tool like PWGen.

  • If your application will use a database, edit the database settings at app/Config/database.php.

    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'user';
    $db['default']['password'] = 'pass';
    $db['default']['database'] = 'database_name';
    $db['default']['dbdriver'] = 'mysql';
    $db['default']['port'] = 3306;
    $db['default']['dbprefix'] = '';
    

    MySQL support is already available by default. If you plan to use PostgreSQL, enable the php_pdo_pgsql extension in the /opt/bitnami/php/etc/php.ini file.

    extension=php_pdo_pgsql
    
  • To move the CodeIgniter example application such that it is available at the root URL of the server (without the /codeigniter URL suffix), follow these steps:

    • Edit the /opt/bitnami/frameworks/codeigniter/conf/httpd-prefix.conf file so that it looks like this:

      DocumentRoot "/opt/bitnami/frameworks/codeigniter/htdocs"
      #Alias /codeigniter/ "/opt/bitnami/frameworks/codeigniter/htdocs/"
      #Alias /codeigniter "/opt/bitnami/frameworks/codeigniter/htdocs"
      Include "/opt/bitnami/frameworks/codeigniter/conf/httpd-app.conf"
      
    • Edit the */opt/bitnami/frameworks/codeigniter/conf/httpd-app.conf * file replace the AllowOverride None directive with the AllowOverride All directive:

      AllowOverride All
      
    • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
      

    You should now be able to access the example application at the root URL of your server.

Upgrading to CodeIgniter 3.x

If your Bitnami stack currently uses CodeIgniter 2.x and you would like to upgrade to CodeIgniter 3.x, follow these steps:

NOTE: The steps below assume that you have already activated the CodeIgniter framework and example application.

  • Log in to your server console.

  • Back up the current version of CodeIgniter:

    $ cd /opt/bitnami/frameworks
    $ sudo mv codeigniter codeigniter.old
    
  • Download and install the latest version of CodeIgniter (3.0.0 at the time of writing):

    $ cd /opt/bitnami/frameworks
    $ sudo wget https://github.com/bcit-ci/CodeIgniter/archive/3.0.0.zip
    $ sudo unzip 3.0.0.zip
    $ sudo mv CodeIgniter-3.0.0 codeigniter
    
  • Create a demo application:

    $ cd /opt/bitnami/frameworks/codeigniter
    $ sudo composer self-update
    $ sudo composer create-project --prefer-dist codeigniter/app app
    
  • Copy the necessary configuration files from the previous CodeIgniter installation:

    $ sudo cp -R /opt/bitnami/frameworks/codeigniter.old/conf /opt/bitnami/frameworks/codeigniter/
    $ cd /opt/bitnami/frameworks/codeigniter
    $ sudo mkdir htdocs
    $ sudo mv index.php user_guide htdocs
    
  • Modify the index.php file:

    $ cd /opt/bitnami/frameworks/codeigniter/htdocs
    $ sudo vi index.php
    
  • Within the file, update the values of the $system_path and $application_folder variables so they look like this.

    <?php
    $system_path = '/opt/bitnami/frameworks/codeigniter/system';
    $application_folder = '/opt/bitnami/frameworks/codeigniter/application';
    
  • Change file ownerships of the CodeIgniter directory:

    $ cd /opt/bitnami/frameworks
    $ sudo chown -R bitnami:root codeigniter
    

You should now be able to access the example application and verify that it is using CodeIgniter 3.x, as shown below:

CodeIgniter upgrade

More Information

Learn more about developing applications with CodeIgniter at http://codeigniter.com/user_guide.

Last modification May 9, 2019