Deploy CodeIgniter to Heroku successfully
CodeIgniter is an open-source software rapid development web framework, for use in building dynamic web sites with PHP. The CodeIgniter framework is a very handy, straight forward, and easy to learn application development framework for building robust and scalable PHP applications.
Requirements
- Codeigniter
- Heroku Account
- Heroku Toolbelt (I won't cover how to use this in this article)
- Git installed on your development machine.
Step 1
Download Codeigniter from this link;
Extract it to your desired working directory
Open your working directory with Visual Studio Code
Step 2
Login to your Heroku account and create a new app.
Under the deployment, tab follow the instructions for deployment to successfully set up your Heroku app with your working directory
i.e
a. Run Heroku login in your command prompt;
b. Open your working directory and run the following commands
$ cd your-working-directory/
$ git init
$ heroku git:remote -a your-heroku-app-name
Replace your-working-directory
with the name of your working directory
Replace your-heroku-app-name
with the name of your Heroku app (the app you just created).
Step 3: Deploy your application
Commit your code to the repository and deploy it to Heroku using Git.
$ git add .
$ git commit -am "initial commit"
$ git push heroku master
Inside your Heroku account click “open app”. This should open the link to your app. Optionally copy the link to your app URL from the command prompt. The link is displayed right after you push your code to Heroku :)
Step 4: Adding database support
To install MySQL go to the overview tab inside Heroku and click
configure-addons
In the Add-ons search field, type ClearDB MySQL
and select it. Choose the free plan (Ignite) and click provision.
So now you’ve got MySQL installed, now we need to set it up so the app uses our local env config on our machine and our Heroku DB config when we deploy to Heroku.
Step 5: Edit Config File.
Open application/config/database.php
Now that we have our Heroku DB credentials, let’s update our database.php file so that the app can access the ClearDB database when deployed to Heroku.
My credentials now look like this.
Okay then, let's proceed
Run
$ git add .
$ git commit -am "Edited Database Config"
$ git push heroku master
You have now successfully connected Codeigniter to Heroku and even added database support.
If you love my stories, follow me Paul Obunga and I’ll keep the stories coming your way. Thank you