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!

Monero is your friendly neighbor - no not really, I mean friendly CPU miner

Monero is another one of those crypto currency that was really big news in 2017. Now the year ends and hoping for a fresh start in 2018. Just got my masternode up and so far so good. X11 is the algo chosen by Sucre so it's not really friendly to CPU. Now, back to Monero. Its algorithm is Cryptonite and it's friendly to miners that only has CPU. First off, get your monero wallet here . As for me, I do use FreeWallet so I don't worry other app/web for every wallet that I have. Anyway, if you get your monero wallet address, that's OK. All we have to do is to find pool to mine. I use MineXMR as it's simpler. You can choose whatever you like, just search for "monero mining pools" and you get bunch to choose from. Get the miner here, extract it to your location of choice and edit the config.json file. {     "algo": "cryptonight",  // cryptonight (default) or cryptonight-lite     "av": 0,                // algorithm var...

Hosting FTP server in your Local Machine

I use this method to share some files with my friends across the internet that is too large for Dropbox to handle. I tried hosting SQL data that's around 3G in size so I wanted to try FTP approach. I installed XAMPP and it has useful stuffs for HTTP and FTP projects. I use it once with my PHP development, but that's it -- nothing FTP related. This is a tutorial on how to basically set-up FTP server locally to host data to be shared by friends, etc. Once XAMPP is installed, we can directly go to the Control Panel. Clicking the Admin for FileZilla FTP Server administration might alert you with Security Warning, just allow access to it. Click OK to Connect to Server. We are now presented with the FileZilla server Administration interface. Go to Edit->Users to add users. I usually just add temporary users who can access specific files to be shared periodically, that means I'll disable it once I'm done with the file share and also I don't usually leave FTP s...