nativeInstallernginx

Get started with CodeIgniter

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 NGINX configuration for your application. Follow these steps:

    • Create the installdir/nginx/conf/server_blocks/APPNAME-server-block.conf file containing the application’s HTTP server block configuration with the configuration block shown below:

      server {
          # Port to listen on, can also be set in IP:PORT format
          listen 80;
          root installdir/myapp/public;
          # Catch-all server block
          # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names
          server_name _;
          include  "installdir/nginx/conf/bitnami/*.conf";
      }
      
    • Create the installdir/nginx/conf/server_blocks/APPNAME-https-server-block.conf file containing the application HTTPS server block configuration with the configuration block shown below:

      server {
          # Port to listen on, can also be set in IP:PORT format
          listen 443 ssl;
          root installdir/myapp/public;
          # Catch-all server block
          # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names
          server_name _;
          ssl_certificate      bitnami/certs/server.crt;
          ssl_certificate_key  bitnami/certs/server.key;
          include  "installdir/nginx/conf/bitnami/*.conf";
      }
      
  • Finally, restart the NGINX server:

    $ sudo installdir/ctlscript.sh restart nginx
    

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

More Information

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

Last modification June 10, 2020