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

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!

Theory of the Genesis of Bam-e

Well, I was pondering of things today. I mean no things? Like nothing? Can't mine like shit, electricity is down almost every 2 hours so I was wondering to myself... How the hell the name "Bam-e" came to be? As a programmer I need to know the origin of it. Like learning new techniques in programming. I need to dissect things. First off, maybe it's a Tagalog term. I think so. And yeah I found it, or did I. I thought the story goes like this. Someone named Dave came to visit Bam. Here it goes... Dave: Hi, Bam ano yang ginawa mo? Bam: Nagluluto Dave: Yay, maganda yan! Masarap ba yan? Bam: Ah wala, hinalo ko lang ang mga natirang ingredients Dave: Ano name nyan? Bam: Hindi ako sure eh! Dave: Patingin nga? Bam: Sure Dave: Pancit lang naman yan Bam eh! Well, if you don't know tagalog. I'm sorry, I'm not the person to talk to. I'm Bisaya and I'm very bad at tutoring Filipino. The hell, I got 79% when I was in high school. I hate the God ...

Create Your Own Onion Website

Well, if you're into cooking, this is not it. It's a hidden service within Tor, or the onion router. Ever heard of facebookcorewwwi.onion ? This blog post is about this kind of onion. If you're also familiar with the silk road then you are on the right spot. Onion sites are well hidden inside Tor and it's difficult for anyone to track. A bit of an Intro Hosting your own domain can be a bit tricky. First off, you need money. Well, of course, you do. You need to sign up for a hosting company. GoDaddy is one good example. There are lots though and I don't need to put it here. It seems I'm advertising GoDaddy. I only got 2 accounts, GoDaddy and ASmallOrange , SmallOrange is crap, although a bit cheaper than GoDaddy. I have Vultur but I don't know how to get my custom domain so that doesn't count. Had PesoHosting but, will get your high blood pressure rolling just mentioning it here. After you get an account, and that's after you pay for like a few ...