views:

177

answers:

4

I run multiple websites all running off of a single installation of CodeIgniter on my server (separate application directories and a single system directory). This has been working fabulously and I don't see any reason to change it at this point.

I find myself writing library classes to extend/override CI all of the time and many times if I find a bug or improve effeciency I have to go back to several websites to make the same adjustments at risk of a typo that breaks one of the websites. Because of this it requires that I change each file and then test that site for bugs.

I have been pondering a solution of using a single libraries directory in a central location and symlinking all of my websites to that central directory. Then when I make a file change it will immediately propagate to all of the downstream websites. It will still require that I test each one for errors, but I won't have to make the changes multiple times. Anything that is specific to a single website will either be a non-shared file (still in the linked directory just not used elsewhere) or can be put in a local helper.

Also, I keep separate 'system' directories by CI version so I can migrate my websites independently if necessary--this central libraries file would be attached to a specific version to reduce possible breaks.

Does anyone see potential issues or pitfalls from taking this approach? Has anyone accomplished this in another direction that I should consider?

Thanks in advance!

+2  A: 

I think this actually makes sense :] Go for it. Even on official CodeIgniter page, they mention it's possible.

Also, I don't see one reason why there should be any problem.

Edit: they touch the problem of multiple sites here: http://codeigniter.com/user_guide/general/managing_apps.html

also: http://codeigniter.com/wiki/Multiple_Applications/
http://www.exclusivetutorials.com/setting-multiple-websites-in-codeigniter-installation/
http://stackoverflow.com/questions/1561262/how-to-handle-multiple-projects-sites-in-codeigniter
http://codeigniter.com/forums/viewthread/56436/

Adam Kiss
+1  A: 

I have a single system directory and separate application directories for my CI apps. In order to share libraries and some view templates between my apps, I have created a "Common" directory, in the same folder as the CI system and with the same structure as a regular app folder and used symlinks, but you can modify the Loader class so that it looks in the Common folder too. My setup looks something like this:

/var/CodeIgniter/
/var/Common/
/var/Common/config/
/var/Common/controllers/
...
/var/Common/libraries/
...
/var/www/someapp/
/var/www/someotherapp/
...
Ch4m3l3on
+1  A: 

I wrote a MY_Loader to do exactly that.

http://codeigniter.com/forums/viewthread/136321/

Phil Sturgeon
+1  A: 

I'm not sure how you handle publishing your sites (assuming you actually do any of that), but I'd look into version control. For example, in SVN you can make external to another svn directory (or file) and then just update the current svn directory which grabs the external file. This approach gains one benefit from the others, which is when you modify the common library, the others aren't immediately affected. This prevents unwanted breaks before you have time to go test all the sites using the common library. You can then just update each site's folder whenever you are ready to test the changes. This is "more work", but it prevents code duplication AND unwanted breaks.

ocdcoder
@ocdcoder - I actually do use SVN (considering trying GIT sometime in the near future). Even with just a few sites I found that having version control was VERY helpful. Thanks for the suggestion ocdcoder.
angryCodeMonkey