Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a CodeIgniter application in a subfolder

I'm trying to install an application made with codeIgniter in a subfolder, so that I can access it using : http://www.domain.com/my_subfolder/ At the root, there's a Wordpress application. I edited the .htaccess of the Wordpress install to let the request go to the folder /my_subfolder/

It's working fine, the only problem I get is that CodeIgniter is unable to dynamically load the classes in the "libraries" directory. So everything in the CI application works fine until it tries to use an object declared in the "libraries" subfolder, then I get a : Unable to load the requested class: my_class

It doesn't seems that there's a parameter in the "config" folder to change that... any idea?

like image 227
mrmuggles Avatar asked Feb 04 '10 03:02

mrmuggles


3 Answers

What you need is to edit your CodeIgniter config.php in System > application > config.

and then edit config.php and set the property:

$config['base_url'] = "http://www.domain.com/my_subfolder/"
like image 191
Pedro Avatar answered Nov 05 '22 17:11

Pedro


Well it seems that the config param base_url should be updated. Also, I used a library with the "MY_" prefix, and I should'nt since I was'nt extending any CI class.

like image 31
mrmuggles Avatar answered Nov 05 '22 15:11

mrmuggles


This is 2021. In case anyone is having this same issue with CodeIgniter 4, this is how I solved it when I came across this issue.

Problem I installed CI in a subfolder in my public_html folder i.e example.com/api. When I visited www.example.com/api, I saw a 403 forbidden error.

Solution

  • Download and unzip CI on your local machine or use composer.

  • Rename public folder to the name of your subfolder. In my case, I named it api.

  • Create another folder and give it any name of choice, for example, let's use mango (yes, I love mangoes). Copy all the remaining files and folders (app, system, writables, env, LICENSE, README, composer, phpunit, spark) into the mango folder. After doing this, we should have 2 folders: api and mango

  • Copy both folders to your live server cpanel root (Do not copy into public_html or www). Let them be on the same level as public_html

  • Open api/index.php and change $pathsConfig = FCPATH . '../app/Config/Paths.php'; to $pathsConfig = FCPATH . '../mango/app/Config/Paths.php';

  • Create a subdomain and point it to /api

  • Go to the api folder, duplicate the env file and rename it to .env

  • Open .env and look for app.baseURL=''. Remove the '#' to uncomment that line and the change it to app.baseUrl='http://subdomain' where subdomain is the subdomain you created above e.g http://api.example.com

  • Open mango/app/config/App.php and look for public $baseUrl and set it to subdomain e.g $baseUrl = 'http://api.example.com'

  • Your CI project is now well configured. Visit http://api.example.com. and you should see the CodeIgniter welcome page.

like image 37
femchaps Avatar answered Nov 05 '22 15:11

femchaps