Welcome Guest, Not a member yet? Register   Sign In
HOW TO setup CodeIgniter 2 with a WAMPServer installation
#1

[eluser]Rushino[/eluser]
Hello,

Since ive got myself lots of problems setting up CodeIgniter 2 with WAMPServer, i will explain here what i did to make it work. I am pretty sure that gonna help someone in the futur.

This apply with the scenario of having an alias with apache in wampserver and wanting to have clean URLs without the "index.php". I believe this scenario is common.

STEPS FOR CREATING A NEW CODEIGNITER PROJECT WITH WAMPSERVER

1. Download and unzip CodeIgniter in the directory where your web projects are and create an alias for it in apache.

The alias must be something like that.. otherwise it won't work.

Code:
Alias /cigestion/ "i:/PATH_TO_YOUR/PROJECT_ALIAS/"

<Directory "i:/PATH_TO_YOUR/PROJECT_ALIAS/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
    Allow from 127.0.0.1
</Directory>

Also your .htaccess file must be like that ..

It enable you to use YOUR_PROJECT_ALIAS/some_controller_method instead of YOUR_PROJECT_ALIAS/index.php/some_controller_method.

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /YOUR_PROJECT_ALIAS/index.php/$1 [L]

YOUR_PROJECT_ALIAS = Is the alias name of your project.

This code must be put in the .htaccess where your index.php file are which is the file executed to render your pages. In most case its the codeigniter root but this can change depending where youve put this file or configured your codeigniter installation.

Note with the config file :

Also it doesnt mind if $config['index_page'] = ''; is empty or contains index.php or the uri_protocol contains AUTO it will still work. (At least for me it do) Maybe this is another story if you put it on a different webserver.

Code:
The $config['base_url']    = '';
can be empty too.

2. If you need to use encryption.. set your encryption key in $config['encryption_key'] also if you need to use databases set your databases informations in config/database.php.

3. Do not forget to use routes..

if you have a method called login in your front controller called welcome.. then

Code:
$route['login'] = "welcome/login";

4. On a security side.. you could also put your files like this ..

c:/web/
|__ ci
|___ ci-1.7.0 (system folder)
|___ ci-1.7.1 (system folder)
|___ erp (application folder)
|___ config
|___ controllers
|___ errors
|___ helpers
|___ hooks
|___ language
|___ libraries
|___ models
|___ public_html
| |___ assets
| | |___ js
| | |___ css
| | |___ images
| index.php
| .htaccess
|___ views

The directories.. ci-1.7.0, ci-1.7.1 correspond to codeigniter system directory (but different version).

Thanks cahva it helped me a lots! As you can see the public files are located in public_html and the .htaccess is there along with the index.php. There no way someone can get in system and also you can upgrade anytime your codeigniter system and switch between versions using the :

Code:
$system_path = '../../ci-1.7.0';

Also be sure to change your application folder.. this can be renamed offcourse but you will have to apply the changes to your alias file.

Code:
$application_folder = '../../application';

Then alias would change to ..

Code:
Alias /cigestion/ "i:/PATH_TO_YOUR/PROJECT_ALIAS/application/public_html/"

<Directory "i:/PATH_TO_YOUR/PROJECT_ALIAS/application/public_html/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
    Allow from 127.0.0.1
</Directory>

and the .htaccess file won't change since it work with the alias name and not the path..

5. Done !

On a pesonnal note i want to say that CodeIgniter is probably the most simple/clean and very powerful solution for developping PHP applications that ive seen so far. I am impressed.

Note: If this can be a sticky i would be glad.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB