Cover image for Codeigniter 4 with Docker on AWS Cloud9

Codeigniter 4 with Docker on AWS Cloud9

fadilxcoder profile image fadilxcoder ・3 min read

Hey devs 💻, I've been spending my days during lockdown trying get familiar with Docker & Amazon Web Services (AWS) Cloud9.

As a PHP developer, I once was using Codeigniter 3 for developing applications. Then it came to my attention that Codeigniter 4 (CI4) was released.

So I decided to combine these 3 and by using AWS - Ubuntu Server 18.04 LTS Platform, I will use Docker and have CI4 working on it.

My AWS environment settings are as follows :

  • Environment type : EC2
  • Platform : Ubuntu Server 18.04 LTS

Let the trip begin 😎

In your bash terminal on AWS, just to check the php version, we won't be using this one though.

ubuntu:~/environment $ php -v

Normally you should see php version 7.2,

PHP version
PHP version

I actually spent couple of days trying to built a nice Docker Environment comprising of

  • nginx
  • php-pfm
  • database

It is available on Github

GitHub logo fadilxcoder / docker-env

Docker Environment

  • PHP Extension installer : https://github.com/mlocati/docker-php-extension-installer
  • To verify if extension is present, use command : php -m|grep mysql for example
  • BUILD : docker-compose up --build
  • UP : docker-compose up
  • Connect to App Terminal : docker exec -it fx_php_fpm ash
  • Verify if container is UP : docker ps
  • URL : http://localhost:8881/

Clone the repository and move the files to the root of your project.

ubuntu:~/environment $ git clone https://github.com/fadilxcoder/docker-env.git
ubuntu:~/environment $ mv docker-env/{*,.*} ./
ubuntu:~/environment $ rmdir docker-env/


Okay, from here i'll explain to you the file structure.

  • In src folder, we will add only the application codes. It can be html, js, css, php files or assets (images / favicon). Overall , our codes goes in this folder.

  • In docker folder, it consist of a docker-compose file where we have the configuration parameters for docker and other Dockerfile each for an image. Depending on your application, you might need to updated these files before building it.

Now we will get CI4 working!

Let the trip continue 👽

You will have to edit the Dockerfile in php-fpm as CI4 uses the intl php extension.

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions gd xdebug mysqli intl

Ans also in docker-compose.yml, change port as AWS by default uses port 8080.

      - "8080:80"

AWS Environment does not have docker-compose command by default, you will need to install it by running sudo apt install docker-compose.

Once installed, go to docker repository and run :

ubuntu:~/environment/docker $ docker-compose up --build

It might take some time as it will have to download the image if it is not present.

Open up another terminal in your AWS and check the container status whether it is up and running,

ubuntu:~/environment/docker $ docker ps

AWS Docker Container
AWS Docker Container

Now you will need to connect to your container terminal,

ubuntu:~/environment $ docker exec -it fx_php_fpm ash
/var/www/html # composer create-project codeigniter4/appstarter ci4

The installation will start...

CI4 in Docker Container
CI4 in Docker Container

95% complete 😁

In the src folder, uncomment the phpinfo(); save the file and the preview your application.

php version 7.4.5
php version 7.4.5

To preview your CI4 application,

URL : http://xxxxxxxxxxxxxxxxxxxxxxxxx.vfs.cloud9.us-east-2.amazonaws.com/ci4/public/

Codeigniter 4
Codeigniter 4

One problem that you might come across is that you may not be able to edit the code of the codeigniter app.

But no worry 😃

Use the 2 commands below to change files ownership & group.

ubuntu:~/environment/src $ sudo chown -R ubuntu ci4/
ubuntu:~/environment/src $ sudo chgrp -R ubuntu ci4/

File Permission
File permission

Trip's over ✨✨✨ 👊 ❤️ ✌️ ✨✨✨

Now we have a fully functional docker container with Codeigniter on AWS C9 and you can code on it anytime/ anywhere...

We did it folks

Posted on by:

fadilxcoder profile



Web & Android App Developer - 🎮 💻 🎧 ☕


markdown guide