Language and Framework Guides

Run a CodeIgniter Container App

11min

Back4App Containers is a powerful platform for hosting CodeIgniter Applications. With its ability to automatically deploy Dockerized applications, you can launch your project in a scalable and flexible environment with ease.

In this guide, we will walk you through the process of preparing and deploying your CodeIgniter application on Back4App Containers, covering everything from simple projects to more complex setups. We will begin with the necessary preparations, then move on to dockerizing the application, testing it locally, pushing the project to GitHub, setting up the project on Back4App Containers, monitoring deployment, and troubleshooting common issues.

If you have any questions or comments, feel free to join the conversation in the #Containers channel on the Back4app Community on Slack. Anytime you can also contact us at [email protected].

1-Prepare your CodeIgniter application

To prepare your CodeIgniter application for deployment on Back4App Containers, follow these steps:

  1. Ensure that you have the latest version of CodeIgniter installed and configured according to the official documentation.
  2. Ensure that all dependencies are installed and up-to-date using the package manager (e.g., Composer). You can do this by running the following command: composer update.
  3. Optimize your application for production by following CodeIgniter best practices, such as using the ENVIRONMENT constant to switch between development and production configurations, minifying and concatenating JavaScript and CSS files, and enabling caching.
  4. Update your database configuration to use environment variables for easier configuration management. In the application/config/database.php file, replace the hardcoded database credentials with references to environment variables, like this:
  5. Ensure that your application's URL is configured to use the base_url() function, which dynamically generates the correct URL based on the current environment. This will allow your application to work seamlessly both in development and production.

2-Dockerization

To dockerize your CodeIgniter application, create a Dockerfile in the root of your project with the following content:

Dockerfile


This Dockerfile specifies the base image as php:7.4-apache, copies the application files into the /var/www/html/ directory, and sets the appropriate ownership and permissions. It also enables the Apache mod_rewrite module for URL rewriting.

3-Test your Project Locally

To test your project locally using Docker, run the following command in the terminal:

Text


This will build the Docker image and run a new container with the specified environment variables from the .env file. You can then access your application at http://localhost:8080.

4-Push your project to GitHub

To push your project to GitHub, follow these steps:

  1. Create a new repository on GitHub.
  2. Initialize your local project as a Git repository by running git init.
  3. Add all files to the repository by running git add ..
  4. Commit the changes by running git commit -m "Initial commit".
  5. Connect your local repository to the remote repository on GitHub by running git remote add origin https://github.com/yourusername/your-repo-name.git.
  6. Push your local commits to the remote repository by running git push -u origin master.

5-Deploy your application on Back4app Containers

To deploy your CodeIgniter application on Back4App Containers, follow these steps:

  1. Log in to your Back4App account and navigate to the "Containers" section.
  2. Click "Create New App" and then choose "Edit GitHub Permissions".
  3. Authorize Back4App to access your GitHub account and select the repository containing your CodeIgniter project.
  4. Once connected to your repo select it to coninue.
  5. Choose the appropriate branch and configure any required environment variables.
  6. Click "Create" to start the deployment process. Back4App Containers will automatically build and deploy your application using the provided Dockerfile.

You can follow these Docs for a better guidance:

In summary, containers will follow the instructions detailed on your Dockerfile and start to create your App.

After configuring your container app, Back4app will automatically build the container image using your Dockerfile and deploy your Express app on the platform. The deployment process may take a few minutes, depending on the size and complexity of your application.

Once the deployment is complete, Back4app Containers will provide you with a unique URL where you can access your deployed app.

6-Monitor deployment and address possible errors

You can monitor your application's deployment process and view logs on the Back4App dashboard. Pay attention to error and warning messages, as they may indicate issues with your application or configuration. Address these issues and redeploy your application to ensure a successful deployment.

7-Troubleshooting common problems

Here are some common problems you may encounter when deploying and running an application on Back4App Containers, along with their solutions:

  1. Permission issues: Ensure that your Dockerfile sets the correct ownership and permissions for your application files, as demonstrated in the example Dockerfile in this guide.
  2. Database connection errors: Verify that your database configuration uses environment variables and that the correct values are set in the Back4App dashboard.
  3. Incorrect URLs: Make sure your application uses the base_url() function to generate URLs dynamically, allowing it to work seamlessly in both development and production environments.
  4. Missing dependencies: Ensure that all dependencies are installed and up-to-date using the package manager (e.g., Composer). Double-check your composer.json and composer.lock files, and update them if necessary.
  5. Application errors: Monitor the application logs on the Back4App dashboard for any errors or warnings. Debug your application locally using Docker and fix any issues before redeploying.

When troubleshooting, remember that logs are your best friend. The Back4App Containers platform provides detailed logs for your application, allowing you to identify and resolve issues quickly. By addressing these common problems, you can ensure a smooth deployment and runtime experience for your CodeIgniter application on Back4App Containers.

8-Scaling your application on Back4App Containers

As your CodeIgniter application grows in popularity, you may need to scale it to handle increased traffic. Back4App Containers makes scaling your application easy by allowing you to adjust the number of containers running your application.

  1. Horizontal scaling(Under Development): Increase the number of containers running your application to distribute the load among multiple instances. You can do this by adjusting the container count in your Back4App dashboard. This helps ensure that your application remains responsive under high traffic conditions.
  2. Vertical scaling: Upgrade the resources allocated to your containers, such as CPU and memory, to handle more demanding workloads. You can do this by selecting a higher-tier container plan in your Back4App dashboard. This ensures that your application can handle more complex tasks or larger datasets.

9-Updating your application on Back4App Containers

Keeping your CodeIgniter application up-to-date is essential for maintaining security and performance. To update your application on Back4App Containers, follow these steps:

  1. Update your application's dependencies and configurations locally, ensuring that everything works as expected.
  2. Test your updated application locally using Docker to verify that it runs without issues.
  3. Commit your changes to your Git repository and push the updates to GitHub.
  4. Back4App Containers will automatically detect the changes and initiate a new deployment. Monitor the deployment process and address any issues that may arise during the update.



With the help of this guide, you should now have a better understanding of how to prepare, deploy, and troubleshoot a CodeIgniter application on Back4App Containers. This powerful platform offers a seamless and efficient way to host your Rust applications, freeing you from the complexities of DevOps and allowing you to focus on your code.