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,
I actually spent couple of days trying to built a nice Docker Environment comprising of
- nginx
- php-pfm
- database
It is available on Github
fadilxcoder / docker-env
Docker Environment Configuration
NGINX / APACHE / PHP-FPM / ADMINER
- PHP Extension installer : https://github.com/mlocati/docker-php-extension-installer (Git repo)
-
NOTE : Replace with :
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions
Example :
FROM php:7.2-cli
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd xdebug
- To verify if extension is present, use command :
php -m|grep mysql
for example - Connect to App Terminal :
docker exec -it fx_php_fpm ash
- Verify if container is UP :
docker ps
NOTES
- Docker Apache : https://github.com/fadilxcoder/docker-env/tree/master-apache
- Docker symfony : https://github.com/fadilxcoder/docker-env/tree/symfony
- BUILD / UP :
docker-compose up --build -d
- UP :
docker-compose up
- DOWN :
MySQL version - docker-compose down --remove-orphans
DETAILS
- PHP :
8.1.5
- NGINX :
nginx/1.21.6
- MySQL version :
10.7.3-MariaDB-1:10.7.3+maria~focal
URL
- URL : http://localhost:8881/
- PHPINFO : http://localhost:8881/phpinfo.php
- ADMINER : http://localhost:8881/adminer.php
-
-
Server :
database
-
Server :
-
-
Username :
myuser
-
Username :
-
-
Password :
secret
-
Password :
-
-
Database :
mydb
-
Database :
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
.
ports:
- "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
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...
95% complete 😁
In the src
folder, uncomment the phpinfo();
save the file and the preview your application.
To preview your CI4 application,
URL : http://xxxxxxxxxxxxxxxxxxxxxxxxx.vfs.cloud9.us-east-2.amazonaws.com/ci4/public/
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/
Trip's over ✨✨✨ 👊 ❤️ ✌️ ✨✨✨
Now we have a fully functional docker container with Codeigniter on AWS C9 and you can code on it anytime/ anywhere...
Top comments (3)
After cloning I would suggest to remove the
.git
folder because the moving command will move it alsoand every other file in the home directory will get check in the repo
So
Or even better to create an app folder and move inside first
This port configuration worked for me