CodeIgniter

To run apps built with the CodeIgniter web framework using Unit:

  1. Install Unit with a PHP language module.

  2. Download CodeIgniter’s core files and build your application. Here, let’s use a basic app template, installing it at /path/to/app/.

  3. Change ownership:

    Run the following command (as root) so Unit can access the application directory (If the application uses several directories, run the command for each one):

    # chown -R unit:unit /path/to/app/  # User and group that Unit's router runs as by default
       
    The unit:unit user-group pair is available only with official packages , Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  4. Next, prepare the CodeIgniter configuration for Unit:

    {
       "listeners": {
          "*:80": {
                "pass": "routes"
          }
       },
    
       "routes": [
          {
                "match": {
                   "uri": "!/index.php"
                },
                "_comment_match": "Denies access to index.php as a static file",
    
                "action": {
                   "share": "/path/to/app/public$uri",
                   "_comment_share": "Path to the application directory; use a real path in your configuration",
                   "fallback": {
                      "pass": "applications/codeigniter"
                   },
                   "_comment_fallback": "Serves any requests not served with the 'share' immediately above"
                }
          }
       ],
    
       "applications": {
          "codeigniter": {
                "type": "php",
                "root": "/path/to/app/public/",
                "_comment_root": "Path to the application directory; use a real path in your configuration",
                "script": "index.php"
          },
          "_comment_script": "All requests are served by a single script"
       }
    }
  5. Upload the updated configuration.

    Assuming the JSON above was added to config.json. Run the following command as root:

    # curl -X PUT --data-binary @config.json --unix-socket \
          /path/to/control.unit.sock \  # Path to Unit's control socket in your installation
          http://localhost/config/      # Path to the config section in Unit's control API
       
    The control socket path may vary; run unitd -h or see Startup and shutdown for details.

    After a successful update, your app should be available on the listener’s IP address and port:

    CodeIgniter Sample App on Unit


Last modified February 6, 2025