Coder Social home page Coder Social logo

atsanna / codeigniter4-docker Goto Github PK

View Code? Open in Web Editor NEW
121.0 11.0 87.0 27.51 MB

🐳 PHP Docker Image for CodeIgniter4 development

License: MIT License

Dockerfile 26.32% Shell 47.37% Roff 26.32%
docker-image docker docker-compose codeigniter4 php

codeigniter4-docker's Introduction

Docker Image for CodeIgniter4 development

Docker Build Status Docker Stars Docker Image Version (tag latest semver) Docker Pulls Docker Image Size

This repository provides you a development environment without requiring you to install PHP, a web server, and any other server software on your local machine. For this, it requires Docker and Docker Compose.

Basic example to create your container (tested on Ubuntu 20.04 - Docker version 20.10.11, build dea9396 - docker-compose version 1.25.0 ):

NOTE: This package is under early development and is not ready for prime-time.

The old version is still available in the branch called "old"

Build Image

Clone thi repository and run:

./build.sh

start the container with php 7.4:

docker container run -it --publish 80:80 --name ci4 -v /localfolder:/var/www/html codeigniter4.2.3:7.4.30-apache

start the container with php 8.0:

docker container run -it --publish 80:80 --name ci4 -v /localfolder:/var/www/html codeigniter4.2.3:8.0.20-apache

start the container with php 8.1:

docker container run -it --publish 80:80 --name ci4 -v /localfolder:/var/www/html codeigniter4.2.3:8.1.9-apache

Installation

  1. Install docker and docker-compose ;

  2. Copy docker-compose.yml file to your project root path, and edit it according to your needs ;

  3. Uncomment, in the docker-compose.yml file, the image you want to use it ;

  4. From your project directory, start up your application by running:

docker-compose up -d
  1. From your project directory, stop your application by running:
docker-compose down --volumes

Environment variables summary:

Environment file

allowed values are: [0, 1]

  • REGEN_ENV_FILE - if 1, the .env file will be created and overwritten when the container starts

App Configuration

  • CI_ENVIRONMENT - ENVIRONMENT [production, develompent, tests]
  • APP_BASE_URL - URL to your CodeIgniter root. Typically this will be your base URL, WITH a trailing slash [http://localhost/]
  • APP_FORCE_GLOBAl_SECURE_REQUESTS - If true, this will force every request made to this application to be made via a secure connection (HTTPS) [true, false]

App Session

  • APP_SESSION_DRIVER - [CodeIgniter\Session\Handlers\FileHandler]
  • APP_SESSION_COOCKIE_NAME - [ci_session]
  • APP_SESSION_EXPIRATION - [7200]
  • APP_SESSION_SAVE_PATH - [null]
  • APP_SESSION_MATCH_CHIP - [true, false]
  • APP_SESSION_TIME_TO_UPDATE - [300]
  • APP_SESSION_REGENERATE_DESTROY - [true, false]
  • APP_CSP_ENABLED - [true, false]

Default Database Configuration

  • DB_DEFAULT_HOSTNAME - default hostname [127.0.0.1]
  • DB_DEFAULT_DATABASE - default database name
  • DB_DEFAULT_USERNAME - default database username
  • DB_DEFAULT_PASSWORD - default database password
  • DB_DEFAULT_DRIVER - default database driver [MySQLi, SQLSRV, Postgre, OCI8, SQLite3]
  • DB_DEFAULT_PORT - default database port [3306, 1443, 5432, 1521]
  • DB_DEFAULT_PREFIX - default database prefix

Tests Database Configuration

  • DB_TESTS_HOSTNAME - tests hostname [127.0.0.1]

  • DB_TESTS_DATABASE - tests database name

  • DB_TESTS_USERNAME - tests database username

  • DB_TESTS_PASSWORD - tests database password

  • DB_TESTS_DRIVER - tests database driver [MySQLi, SQLSRV, Postgre, OCI8, SQLite3]

  • DB_TESTS_PORT - tests database port [3306, 1443, 5432, 1521]

  • DB_TESTS_PREFIX - tests database prefix

  • DB_DEFAULT_PREFIX - default database prefix

Content Secure Policy Configuration

  • CONTENT_SECURE_POLICY_REPORT_ONLY - Default CSP report context [true, false]
  • CONTENT_SECURE_POLICY_DEFAULT_SRC - Will default to self if not overridden [none]
  • CONTENT_SECURE_POLICY_SCRIPT_SRC - Lists allowed scripts' URLs [self]
  • CONTENT_SECURE_POLICY_STYLE_SRC - Lists allowed stylesheets' URLs [self]
  • CONTENT_SECURE_POLICY_IMAGE_SRC - Defines the origins from which images can be loaded [self]
  • CONTENT_SECURE_POLICY_BASE_URI - Restricts the URLs that can appear in a page's <base> element [null]
  • CONTENT_SECURE_POLICY_CHILD_SRC - Lists the URLs for workers and embedded frame contents [null]
  • CONTENT_SECURE_POLICY_CONNECT_SRC - Limits the origins that you can connect to (via XHR, WebSockets, and EventSource)[self]
  • CONTENT_SECURE_POLICY_FONT_SRC - Specifies the origins that can serve web fonts [null]
  • CONTENT_SECURE_POLICY_FORM_ACTION - Lists valid endpoints for submission from <form> tags [null]
  • CONTENT_SECURE_POLICY_FRAME_ANCESTORS - Specifies the sources that can embed the current page [null]
  • CONTENT_SECURE_POLICY_RFAME_SRC - The frame-src directive restricts the URLs which may be loaded into nested browsing contexts [null]
  • CONTENT_SECURE_POLICY_MEDIA_SRC - Restricts the origins allowed to deliver video and audio [null]
  • CONTENT_SECURE_POLICY_OBJECT_SRC - Allows control over Flash and other plugins [null]
  • CONTENT_SECURE_POLICY_PLUGIN_TYPES - Limits the kinds of plugins a page may invoke [null]
  • CONTENT_SECURE_POLICY_REPORT_URI - Specifies a URL where a browser will send reports when a content security policy is violated [null]
  • CONTENT_SECURE_POLICY_SANDBOX - List of actions allowed [true, false]
  • CONTENT_SECURE_POLICY_UPGRADE_INSECURE_REQUESTS - Instructs user agents to rewrite URL schemes, changing HTTP to HTTPS. This directive is for websites with large numbers of old URLs that need to be rewritten[true, false]

Cookie Configuration

  • COOKIE_PREFIX - Set a cookie name prefix if you need to avoid collisions [``]
  • COOKIE_EXPIRES - Default expires timestamp for cookies [0]
  • COOKIE_PATH - Typically will be a forward slash [/]
  • COOKIE_DOMAIN - Set to .your-domain.com for site-wide cookies [``]
  • COOKIE_SECURE - Cookie will only be set if a secure HTTPS connection exists [true, false]
  • COOKIE_HTTP_ONLY - Cookie will only be accessible via HTTP(S) (no JavaScript) [true, false]
  • COOKIE_SAME_SITE - Configure cookie SameSite setting [None, Lax, Strict, '']
  • COOKIE_RAW - This flag allows setting a "raw" cookie [true, false]

Encryption Configuration

  • ENCRYPTION_KEY - If you use the Encryption class you must set an encryption key (seed) [``]
  • ENCRYPTION_DRIVER - One of the supported encryption drivers [OpenSSL, Sodium]
  • ENCRYPTION_BLOCK_SIZE - This is the number of bytes that will be padded to the plaintext message before it is encrypted [16]
  • ENCRYPTION_DIGEST - HMAC digest to use [SHA256, SHA512]

Honeypot Configuration

  • HONEYPOT_HIDDEN - Makes Honeypot visible or not to human [true, false]
  • HONEYPOT_LABEL - Honeypot Label Content [Fill This Field]
  • HONEYPOT_NAME - Honeypot Field Name [honeypot]
  • HONEYPOT_TEMPLATE - Honeypot HTML Template [<label>{label}</label><input type="text" name="{name}" value=""/>]
  • HONEYPOT_CONTAINER - Honeypot container [<div style="display:none">{template}</div>]

Security Configuration

  • SECURITY_CSRF_PROTECTION - Protection Method for Cross Site Request Forgery protection [cookie, session]
  • SECURITY_TOKEN_RANDOMIZE - Randomize the CSRF Token for added security [true, false]
  • SECURITY_TOKEN_NAME - Token name for Cross Site Request Forgery protection [csrf_token_name]
  • SECURITY_HEADER_NAME - Header name for Cross Site Request Forgery protection [X-CSRF-TOKE]
  • SECURITY_COOKIE_NAME - Cookie name for Cross Site Request Forgery protection [csrf_cookie_name]
  • SECURITY_EXPIRES - Expiration time for Cross Site Request Forgery protection cookie [7200]
  • SECURITY_REGENERATE - Regenerate CSRF Token on every submission [true, false]
  • SECURITY_REDIRECT - Redirect to previous page with error on failure [true, false]
  • SECURITY_SAME_SITE - Setting for CSRF SameSite cookie token [None, Lax, Strict, '']

Logger Configuration

  • LOGGER_THRESHOLD - You can enable error logging by setting a threshold over zero [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    • Threshold options are:
      • 0 = Disables logging, Error logging TURNED OFF
      • 1 = Emergency Messages - System is unusable
      • 2 = Alert Messages - Action Must Be Taken Immediately
      • 3 = Critical Messages - Application component unavailable, unexpected exception.
      • 4 = Runtime Errors - Don't need immediate action, but should be monitored.
      • 5 = Warnings - Exceptional occurrences that are not errors.
      • 6 = Notices - Normal but significant events.
      • 7 = Info - Interesting events, like user logging in, etc.
      • 8 = Debug - Detailed debug information.
      • 9 = All Messages

Curl Request Configuration

  • CURL_REQUEST_SHARE_OPTIONS - Whether share options between requests or not [true, false]

Sendmail Configuration

  • ROOT_EMAIL - The user that gets all mail for userids less than 1000. Ifblank, address rewriting is disabled.
  • MAIL_SERVER - The host to send mail to, in the form host.
  • MAIL_SERVER_PORT - The port to send mail to, in the form host.
  • MAIL_SERVER_USER - The user name to use for SMTP AUTH.
  • MAIL_SERVER_PASSWORD - The password to use for SMTP AUTH.
  • MAIL_SERVER_TLS - Specifies whether ssmtp uses TLS to talk to the SMTP server.
  • MAIL_SERVER_STARTTLS - Specifies whether ssmtp does a EHLO/STARTTLS before starting SSL negotiation.

List of Apache Modules pre-installed on these Docker images (apachectl -M)

  • core_module (static)
  • so_module (static)
  • watchdog_module (static)
  • http_module (static)
  • log_config_module (static)
  • logio_module (static)
  • version_module (static)
  • unixd_module (static)
  • access_compat_module (shared)
  • alias_module (shared)
  • auth_basic_module (shared)
  • authn_core_module (shared)
  • authn_file_module (shared)
  • authz_core_module (shared)
  • authz_host_module (shared)
  • authz_user_module (shared)
  • autoindex_module (shared)
  • cgi_module (shared)
  • deflate_module (shared)
  • dir_module (shared)
  • env_module (shared)
  • expires_module (shared)
  • fcgid_module (shared)
  • filter_module (shared)
  • headers_module (shared)
  • mime_module (shared)
  • mpm_prefork_module (shared)
  • negotiation_module (shared)
  • php_module (shared)
  • proxy_module (shared)
  • proxy_http_module (shared)
  • reqtimeout_module (shared)
  • rwrite_module (shared)
  • setenvif_module (shared)
  • socache_shmcb_module (shared)
  • ssl_module (shared)
  • status_module (shared)

List of PHP Modules pre-installed on these Docker images (php -m)

[PHP Modules]

  • amqp
  • ast
  • bcmath
  • bz2
  • calendar
  • Core
  • csv
  • ctype
  • curl
  • date
  • dba
  • decimal
  • dom
  • ds
  • enchant
  • ev
  • event
  • excimer
  • exif
  • FFI
  • fileinfo
  • filter
  • ftp
  • gd
  • geospatial
  • gettext
  • gmp
  • gnupg
  • grpc
  • hash
  • http
  • iconv
  • igbinary
  • imagick
  • imap
  • inotify
  • intl
  • json
  • json_post
  • ldap
  • libsmbclient
  • libxml
  • lzf
  • mailparse
  • maxminddb
  • mbstring
  • mcrypt
  • memcache
  • memcached
  • mongodb
  • msgpack
  • mysqli
  • mysqlnd
  • OAuth
  • oci8
  • odbc
  • opencensus
  • openssl
  • openswoole
  • pcntl
  • pcov
  • pcre
  • PDO
  • pdo_dblib
  • PDO_Firebird
  • pdo_mysql
  • PDO_OCI
  • PDO_ODBC
  • pdo_pgsql
  • pdo_sqlite
  • pdo_sqlsrv
  • pgsql
  • Phar
  • posix
  • pspell
  • raphf
  • readline
  • redis
  • Reflection
  • SeasLog
  • session
  • shmop
  • SimpleXML
  • smbclient
  • snmp
  • soap
  • sockets
  • sodium
  • SPL
  • sqlite3
  • sqlsrv
  • ssh2
  • standard
  • tokenizer
  • uuid
  • xdebug
  • xml
  • xmldiff
  • xmlreader
  • xmlrpc
  • xmlwriter
  • xsl
  • yac
  • yaml
  • yar
  • Zend OPcache
  • zend_test
  • zephir_parser
  • zip
  • zlib
  • zstd

[Zend Modules]

  • Xdebug
  • Zend OPcache

Changelog

You can find the changes made in the changelog file

Contributing

Contributions are welcome! Leave an issue on Github, or create a Pull Request.

Licence

This work is under MIT licence.

codeigniter4-docker's People

Contributors

atsanna avatar fagnerdin avatar guxmartin avatar kenjis avatar kevinadhiguna avatar nicicalu avatar tansherjun-nixora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter4-docker's Issues

database

hi atsanna, what is credentials from phpmyadmin and database ?

How do migration via spark

Premise

I did success connect to database via local server.
I understand basic of codeigniter4.
image

step1 docker-compose.yml

I'm changed port for codeigniter4_mysql because the port conflicts with the local MySQL.

version: "3"

services:
    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    #                     C O D E I G N I T E R  v4.1.4                        #
    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    codeigniter4:
        image: atsanna/codeigniter4:latest
        container_name: 'codeigniter4'
        ports:
            - 80:80
        links:
            - codeigniter4_mysql
        volumes:
            - ./localfolder/www:/var/www/html

    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    #                               M Y S Q L                                  #
    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    codeigniter4_mysql:
        image: mariadb:10.5.5
        container_name: 'codeigniter4_mysql'
        ports:
            - 3307:3306
        volumes:
            - ./localfolder/mysql:/var/lib/mysql
            - ./localfolder/logs/mysql:/var/log/mysql
        environment:
            MYSQL_ROOT_PASSWORD: rootpassword
            MYSQL_DATABASE: codeigniter4
            MYSQL_USER: codeigniter4
            MYSQL_PASSWORD: codeigniter4

    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    #                         P H P M Y A D M I N                              #
    #--------------------------------------------------------------------------#
    #--------------------------------------------------------------------------#
    codeigniter4_phpmyadmin:
        image: phpmyadmin/phpmyadmin:5.0.2
        container_name: 'codeigniter4_phpmyadmin'
        links:
            - codeigniter4_mysql
        environment:
            PMA_HOST: codeigniter4_mysql
            PMA_PORT: 3306
        ports:
            - 81:80
        volumes:
            - ./localfolder/sessions:/sessions

it's ok!
image

step2 connect to database

 // localfolder/www/codeigniter4/.env
 database.default.hostname = codeigniter4_mysql
 database.default.database = codeigniter4
 database.default.username = codeigniter4
 database.default.password = codeigniter4
 database.default.DBDriver = MySQLi

Some values ​​are in Japanese, but please focus to the numbers.

CREATE TABLE `users` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `name` VARCHAR(32) NULL DEFAULT NULL,
  `age` INT UNSIGNED NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `user_id` (`user_id`)
);

INSERT INTO `codeigniter4`.`users` (`user_id`, `name`, `age`) 
VALUES 
(100, '屋代駿介', 35),
(101, '須加友枝', 29),
(102, '永来一八', 15),
(103, '荷宮知愛', NULL);

create a entity

> php spark make:entity
  Entity class name: User
  File created: APPPATH\Entities\User.php

I append cast information.

    protected $casts   = [
        'id' => 'integer',
        'user_id' => 'integer',
        'age' => '?integer',
    ];

create a model.
no edit.

> php spark make:model
  Model class name: UserModel
  File created: APPPATH\Models\UserModel.php

step3 Editing Controller

it's simple

<?php

namespace App\Controllers;

use App\Models\UserModel;

class Home extends BaseController
{
    public function index($userId)
    {
        $userModel = new UserModel();
        $user = $userModel->where('user_id', $userId);
    
        d($user);
        d($user->id);
        d($user->user_id);
        d($user->name);
        d($user->age);
        
        return view('welcome_message');
    }
}

retrieve is failed. What may be the cause.
image

problem

What I'm curious about is that the connection information is null
image

I'm also worried that migrate cannot be executed. Please let me know if you can understand anything. thank you. :)

localfolder\www\codeigniter4> php spark migrate

CodeIgniter v4.1.4 Command Line Tool - Server Time: 2021-09-20 03:17:33 UTC-05:00

Running all new migrations...

[CodeIgniter\Database\Exceptions\DatabaseException]

Unable to connect to the database.
Main connection [MySQLi]: php_network_getaddresses: getaddrinfo failed: ̂悤ȃzXg͕słB

at SYSTEMPATH\Database\BaseConnection.php:400

Backtrace:
  1    SYSTEMPATH\Database\BaseConnection.php:570
       CodeIgniter\Database\BaseConnection()->initialize()

  2    SYSTEMPATH\Database\BaseConnection.php:1320
       CodeIgniter\Database\BaseConnection()->query('SHOW TABLES FROM `codeigniter4`')

  3    SYSTEMPATH\Database\BaseConnection.php:1351
       CodeIgniter\Database\BaseConnection()->listTables()

  4    SYSTEMPATH\Database\MigrationRunner.php:754
       CodeIgniter\Database\BaseConnection()->tableExists('migrations')

  5    SYSTEMPATH\Database\MigrationRunner.php:166
       CodeIgniter\Database\MigrationRunner()->ensureTable()

  6    SYSTEMPATH\Commands\Database\Migrate.php:84
       CodeIgniter\Database\MigrationRunner()->latest(null)

  7    SYSTEMPATH\CLI\Commands.php:63
       CodeIgniter\Commands\Database\Migrate()->run([])

  8    SYSTEMPATH\CLI\CommandRunner.php:70
       CodeIgniter\CLI\Commands()->run('migrate', [])

  9    SYSTEMPATH\CLI\CommandRunner.php:56
       CodeIgniter\CLI\CommandRunner()->index([])

 10    SYSTEMPATH\CodeIgniter.php:800
       CodeIgniter\CLI\CommandRunner()->_remap('index', 'migrate')

 11    SYSTEMPATH\CodeIgniter.php:399
       CodeIgniter\CodeIgniter()->runController(Object(CodeIgniter\CLI\CommandRunner))

 12    SYSTEMPATH\CodeIgniter.php:317
       CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

 13    SYSTEMPATH\CLI\Console.php:48
       CodeIgniter\CodeIgniter()->run()

 14    ROOTPATH\spark:63
       CodeIgniter\CLI\Console()->run()

apache urlrewrite not working

Hi,
First of all, thank you very much for this docker image. It gets me on codeigniter4 on macbook in only a few hours.
I have 1 suggestion for improvement. Currently the mod rewrite is not enable the .htaccess does not work (at least in my installation). I needed to ssh into the docker and run "a2enmod rewrite" and restart the apache to get the rewrite working.
Maybe can add a line in Dockerfile:
RUN a2enmod rewrite

Just in case you are interested, I have also map apache.conf and startScript.sh to local directory.

Again, thank you for this project. Great job!

Cant change apache document root

Hi ! Congratulations on your project. I find it great. I am new to Docker and this solves many problems!
I would like to know how to change apache Documentroot to /var/ww/html
I tried many different ways and I can not get it changed I have always Codeigniter 4..1.1 starting at locahost.
I need to run different instances and diferent projects on localhost that's why I need to change it, but no way!
Can you please help me ?
Thank you and congratulatins again!
Paul

Build fail: missing asset/ecw/hexagon.zip

hexagon.zip contain ERDAS-ECW_JPEG_2000_SDK-5.5.0

File asset/ecw/hexagon.zip is 291.46 MB; this exceeds GitHub's file size limit of 100.00 MB

error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

I am thinking of removing this component from the repository

stopping application

Stopping Application wont stop.

$:~/codeigniter$ docker-compose down
Removing network codeigniter_default
WARNING: Network codeigniter_default not found.

I have to stop the container manually.

Apache2 not starting on container start?

Hello,

Thank you for creating this image ... it's great! I do have one issue ... Apache2 is not starting when I launch the container. I've been trying to dig for logs or any way to debug this, but I can't find anything. dmesg fails, etc.

Any ideas on why?

Each time I launch the container I have to issue a "service apache2 restart" and then everything is ok.

Unable to connect to the database.

Hi, thank you for your work.
I created and started the containers on both a mac book pro and windows but codeigniter gives the error "Unable to connect to the database." while phpmyadmin container works fine.

in Database.php I tried both with 'hostname' => 'codeigniter4_mysql', and with 'hostname' => 'localhost'.

Can you help me?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.