Skip to main content

Multiple configuration files for CodeIgniter

I recently came across a problem which is very common when deploying a web application. This time, I'm trying it with CodeIgniter. I purchased a domain and a small shared hosting to which I deploy a simple app. Along with it, I purchased the SSL so it should be accessed with https rather than http. Even all http request should be redirected to https, that's two problems.

A way to solve it is via .htaccess in the root app directory. For multi environments, we can set a CI_ENV variable via


    SetEnv CI_ENV development


So in our application/config directory we can add production directory which consist of config.php and database.php. These settings are then for production. So when we deploy the application, we need to updated those settings for production. As for me, I also have test and stage settings so I also have those directories in my config directory with config.php and database.php corresponding to that environments. This is preferred since we need to test it and put it to stage when testing is done with no issues. Stage connects to the production data but with the php files from my develop branch. In a way this tests the application with the production data. If all goes well, we can proceed to deploying to production.

Another problem is the https redirect. We can solve it with

# Uncomment these lines for https redirection
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# End http redirection

This is still in the .htaccess file. Just below the RewriteEngine on. So accessing the site via http will redirect to https.

And... we are good to go. I just couldn't find a solution for multiple .htaccess for different environments. But maybe it'll be for another post. Right now, I comment/uncomment the redirect statements when I develop locally and when I deploy it to my hosting. Anyway, I'm happy with what I have for now so yeah, if you have comments and suggestions please do comment below and I'll try to answer as best as I can.

Thanks and have a great day everyone!

Comments

Popular posts from this blog

Restoring .dat data to MSSQL

This is just a document in case I forgot to restore data files to MSSQL. I had this problem before when a colleague gave me a .dat files to be restored to SQL server. I had a 2008 version of the server and had no trouble restoring it. The problem is, I forgot how I did it when I had a new PC and I upgraded it to 2012 SQL server. But this is a simple task (although I had a full day remembering how I did it and I had no luck finding the solution from google). First off, click restore, like so I had trouble with the database whether or not to add a new database and restore the file to it, or not. Simple answer is no need. With the next image you can see that the configuration is very simple. Just set it to device as the source and find the .mdf file. It automatically displays a suggestion for the database name and you're done. Click OK and wait a couple of minutes for SQL server to restore the data. [EDIT] In case you are restoring a backup file without an extension. You c...

Windows 10 HP Netbook Sucks, Lubuntufies it, Great!

I purchased a small netbook from HP few years back and it was installed with Windows 10 Home Edition. I tried it at the shop and works fine until I arrived at home and installed office suites, and some basic programming  tools like Chrome, Python, Visual Studio Code that it became useless. Now it lags and my daughter can't even work with office suites. It was for her, it was a gift, it's suppose to work and not bother her. And now it becomes a pain for her doing research and Google Chrome always says "Not Responding". I just remembered it was 2 years ago. The netbook was just kept at the closet, intended never to see the light again. I was cleaning my small office at home and I found it, I remembered the pain. I remembered it all like yesterday. It was horrible, I cried and asked God, why did I remember all those miseries. Seriously, I just found it, that's it, and just thought, well I think I can have a use for it for a small server at home. Then it hits me, it...

Add Brave Browser to Netbeans

We'll I'm liking Brave now, great isn't it. With the token and all and privacy and stuff. And all the good stuff, right? So what other good thing we can do about it other than adding it to our favorite editor. So here it is, adding it is through Tools->Options->General Edit Web Browser Manager and add this setting below. Find the brave.exe usually it can be found in C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe and voila we're good. See you next posts everyone!