nativeInstallerwamp

Get started with CodeIgniter

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "installdir/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Approach A: Bitnami installations using system packages

The CodeIgniter framework is not installed by default in Bitnami installations using system packages. However, it can be easily enabled using Composer. In this guide, you will learn how to install and configure a CodeIgniter 4 project.

Installation and Testing

NOTE: This section assumes that the application project directory will be located at installdir/projects/APPNAME. Remember to replace the APPNAME placeholder with the application name, such as myapp.

  • First, create a project directory where to store your application. Run the following commands:

    $ sudo mkdir -p installdir/projects/APPNAME
    $ sudo chown $USER installdir/projects/APPNAME
    
  • Create the CodeIgniter project. Run the following command:

    $ composer create-project codeigniter4/appstarter installdir/projects/APPNAME
    
  • Grant write permissions for the web server to the writable directory. Run the following command:

    $ sudo chown daemon:daemon installdir/projects/APPNAME/writable
    
  • Create the Apache configuration for your application. Follow these steps:

    • Create the installdir/apache2/conf/vhosts/APPNAME-vhost.conf file containing the application’s HTTP virtual host configuration with the configuration block shown below:

      <VirtualHost 127.0.0.1:80 _default_:80>
        ServerAlias *
        DocumentRoot /opt/bitnami/projects/APPNAME/public
        <Directory "/opt/bitnami/projects/APPNAME/public">
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
      
    • Create the installdir/apache2/conf/vhosts/APPNAME-https-vhost.conf file containing the application HTTPS virtual host configuration with the configuration block shown below:

      <VirtualHost 127.0.0.1:443 _default_:443>
        ServerAlias *
        DocumentRoot installdir/projects/APPNAME/public
        SSLEngine on
        SSLCertificateFile "installdir/apache2/conf/bitnami/certs/server.crt"
        SSLCertificateKeyFile "installdir/apache2/conf/bitnami/certs/server.key"
        <Directory "installdir/projects/APPNAME/public">
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
      
  • Finally, restart the Apache server:

    $ sudo installdir/ctlscript.sh restart apache
    

You can now verify that the example application is working by visiting its URL using your browser at http://localhost/. Here is an example of what you might see:

CodeIgniter 4 welcome page

Configuration

Before using the example application, if your application will use a database, edit the database settings at the .env file.

NOTE: If the installdir/projects/APPNAME/.env file does not exist, create it.

database.default.hostname = localhost
database.default.port = 3306
database.default.database = database_name
database.default.username = user
database.default.password = pass
database.default.DBDriver = MySQLi
# database.default.DBPrefix =

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

extension=pdo_pgsql

Approach B: Self-contained Bitnami installations

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. In this guide, you will learn how to enable and configure a CodeIgniter 3 project.

Activation and Testing

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

Include "installdir/frameworks/codeigniter/conf/httpd-prefix.conf"

Then, restart the Apache server.

$ sudo installdir/ctlscript.sh restart apache

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

Here is an example of what you might see:

CodeIgniter 3 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 installdir/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 installdir/frameworks/codeigniter/conf/httpd-prefix.conf file so that it looks like this:

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

      AllowOverride All
      
    • Restart the Apache server:

      $ sudo installdir/ctlscript.sh restart apache
      

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

More Information

Learn more about developing applications with CodeIgniter at https://codeigniter.com/user_guide/index.html.

Last modification June 10, 2020