This is an old revision of the document!


CodeIgniter 4

Simple demo of CI4 framework.

Environment

Devuan Chimaera 4.0

Install Apache & PHP

Update

apt update
apt full-upgrade

Install

apt install apache2 php php-cli php-mbstring php-intl php-curl php-json php-mysqlnd

PHP version

php --version
PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

Install CI4

Download package and unzip into htdocs.

mkdir -p /var/www/htdocs
cd /var/www/htdocs
wget https://api.github.com/repos/codeigniter4/CodeIgniter4/zipball/v4.1.9 -O ci4.zip
unzip ci4.zip
mv codeigniter4-CodeIgniter4-202f41a hostname.kewl.org
cd hostname.kewl.org
chown www-data:www-data writable

Configure apache

<VirtualHost *:80>
    DocumentRoot "/var/www/htdocs/hostname.kewl.org/public"
    ServerName hostname.kewl.org
    ServerAdmin root

    Header append X-FRAME-OPTIONS "SAMEORIGIN"

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* /var/www/htdocs/hostname.kewl.org/public/index.php [L]

    <Directory "/var/www/htdocs/hostname.kewl.org/public">
        Options None
        AllowOverride None
    </Directory>

    CustomLog /var/log/apache2/hostname.kewl.org/access.log combined
    ErrorLog  /var/log/apache2/hostname.kewl.org/error.log
</VirtualHost>

Configure CI4

Change baseURL and indexPage in app config.

vi app/Config/App.php

Change logging threshold if required.

vi app/config/Logger.php

Hello world

Create controller
vi app/Controllers/Hello.php
<?php

namespace App\Controllers;

class Hello extends BaseController
{
    public function index()
    {
        echo view('Hello');
    }
}
?>
Create view
vi app/Views/Hello.php
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Hello World</title>
</head>
<body>

<p>Hello World</p>

</body>
</html>
Visit URL
http://hostname.kewl.org/Hello
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies