CodeIgniter 4 – Step 2: Installing CodeIgniter in Docker containers

In the previous article we’ve set up the infrastructure that will hold our CodeIgniter application. In this tutorial we are finally going to really install CodeIgniter 4. I promise!…

If you never had the chance to follow the previous tutorial on how to build the Docker containers, or if you don’t have the nerve of following it, maybe it would be faster for you to simply clone the repository I’ve set up on Github.com: https://github.com/avenirer/CodeIgniter4-Docker-Apache-PHP-MySQL. The end result of the cloning should look something on the line of this:

Once we’ve cloned the repository, we open the terminal in the directory where we’ve cloned the repository, and we type “docker-compose up -d “.

If, by any chance you meet an error like this: “ERROR: for codeigniter_web_1 Cannot start service web: error while creating mount source path ‘/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/ebc957f10edc09b607f3ae00d638eb7058d47ad57ae3df8c8684373c2895ecff’: mkdir /run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/ebc957f10edc09b607f3ae00d638eb7058d47ad57ae3df8c8684373c2895ecff: file exists”, you most likely didn’t close properly the containers in the past. In order to get passed this error, you need to remove all previous volumes. To do this, just type these 4 commands, one by one:

1. docker-compose down
2. docker rm -f $(docker ps -a -q)
3. docker volume rm $(docker volume ls -q)
4. docker-compose up

You can find out more about this and all related to Docker in here: https://docs.tibco.com/pub/mash-local/4.1.1/doc/html/docker/GUID-BD850566-5B79-4915-987E-430FC38DAAE4.html

OK… Now everything should be ok, with web, db and adminer services created.

Into the belly of the Beast!

Now, we need to go into the terminal of our “web” service in order to “install” CodeIgniter4.

To do this, we first need to know how the container is named. So type in the terminal “docker ps “. As you may see, our container name is “codeigniter_web_1“.

In order to get into the terminal of that container we only need to write: “docker exec -it codeigniter_web_1 bash “. And that’s it: we are in the container’s terminal.

Now, in the container’s terminal we simply write: “composer create-project codeigniter4/appstarter ./ “; and composer should start installing our CodeIgniter4 application. If, by any chance there is already a file inside your /var/www/html directory, the application will not be installed, so you must make sure that the directory is empty before installing.

Now, if you go in your browser to http://localhost you should see the CodeIgniter starter app. It doesn’t appear? Hmm… Maybe we don’t have read write rights. Then go inside wsl, in your directory and type: sudo chmod 777 ./ -R

In our next tutorial we will see how we can configure the application.

Read more here

https://docs.tibco.com/pub/mash-local/4.1.1/doc/html/docker/GUID-BD850566-5B79-4915-987E-430FC38DAAE4.html
https://codeigniter.com/user_guide/installation/installing_composer.html