Initial configuration

Configure config.php

Set the base url

The first configuration option you need to set inside config.php is the base URL of your application. You do that by setting the absolute URL (including the http:// part) for $config[ ‘ base_url ’ ].

For local purposes you can use this:

$config['base_url'] = 'http://localhost/local_website/';

For online purposes you can use this:

$config['base_url'] = 'http://www.mywebsite.com/test_website_online/';

I like to combine them using the code below:

if (stristr($_SERVER['HTTP_HOST'], 'local') || (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168')) {
    // echo 'local';
    $config['base_url'] = 'http://localhost/local_website/';
} else {
    // echo 'online';
    $config['base_url'] = 'http://www.mywebsite.com/test_website_online/';
}

Once you’ ve set this configuration option, you can recall it whenever you want using the CodeIgniter base_url() function, which can be a very handy thing to know. This one feature keeps you from having to rewrite hard – coded URLs in your application, when you migrate from development to test or from test to production.

Remove index.php from address

Set this parameter:

$config['index_page'] = '';

And use htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Configure routes.php

$route['default_controller'] = "home";

Configure autoload.php

The autoload.php file specifies which systems are automatically loaded by CodeIgniter. I prefer to autoload certain frequently used systems instead of calling them at the local level repeatedly.

Here are my typical settings:

$autoload['libraries'] = array('database','session','email','form_validation');
$autoload['helper'] = array('html','url','form');

Setting the encryption key

In order to use the Session library you are required to set an encryption key in your config file.

You can use this online codeIgniter encryption key generator. Copy the key and paste it in your config file:

$config['encryption_key'] = 'paste_the_key_here';

Create your database

Use your hosting server’s cpanel to create your site’s database and its users.

Configure database.php

The database.php file contains all the information required to connect to a database. To connect to your database, simply enter valid information for your hostname, username, password, database name, and database driver.

$db['default']['hostname'] = 'xxx.xxx.xx.xxx'; // your server's ip
$db['default']['username'] = 'db_username';
$db['default']['password'] = 'my_password';
$db['default']['database'] = 'my_database';
$db['default']['stricton'] = TRUE; // for extra security

Allowing remote MySQL connections

Allowing remote MySQL connections is often done to enable a program on your personal computer (such as Adobe Dreamweaver) to access the database on the server.

What you need to do is enter the IP address of the computer that will be making the remote connection.

To find our what your own IP address is, go to hostgator.com/ip.shtml (your IP address will be listed in red).

Post A Comment

Anti-Spam Quiz: