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...

How to Backup using SQL Server Data

 Sometimes Task->Generate Scripts takes too time to backup especially when you want to backup only selected tables in the database. This can be done easily with bcp, issuing the command in your power shell dumps the data in tab-delimited values into a file. \> bcp "DATABASE.dbo.TABLE" out "C:\Downloads\TABLE.sql" -c -S "HOSTNAME" -U USERNAME -P PASSWORD Hope this helps, this is very useful for migrating data and for seeders where some tables are only needed to be seeded into the database as dependent values for other tables. We are heavily using this technique for testing. As for reference, here's our use case Dump data into .sql files Seed using QueryFromFile Run automation; this can insert new values to other tables based from the seed data from .sql file Rollback new values We need to rollback each time since we want to have data the same as it was so we can run each time and expect the same results for our testing. If not, there should be err...

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...