TIP게시판

제목 CI 멀티 사이트 설정하기..
글쓴이 듬직이 작성시각 2009/08/30 17:39:42
댓글 : 1 추천 : 1 스크랩 : 0 조회수 : 22237   RSS
주소 : http://www.askaboutphp.com/tutorials/88/codeigniter-setting-up-multiple-sites-on-one-install.html

좀 성의 없어 보일려나요 ^^;;
좋은 자료 같아서 원문을 옮겨 봅니다.

요약 하자면, 아파치의 virtual host를 사용해서 http://dev.ci/http://live.ci/를 나눠서 사용하는 방법입니다.
여러개의 사이트를 운영하거나 테스트용 사이트를 운영할려고 하면 도움이 될 것 같습니다.
그림이 워낙 잘 되어 있어서 그냥.. 그림만 보고 따라해도 될 정도네요 6^^


It’s been awhile since I last posted about Codeigniter. In this post, I’m going to walkthrough how I setup a CI install that can support multiple sites. This is by no means the only way to do it, but it’s what works for me.

CI’s default folder structure is really geared towards one site domain, and having both the application folder and the system folder visible to the browser is not exactly a secure approach.

By configuring your install to support multiple sites, not only do you make the updating of the CI core easier, but also make the CI install more secure as a whole. So without delay, let’s get started…

 

In this walkthrough, I’m setting up my multiple CI sites on my local XAMPP install, which is on my M:\ drive. Your Apache setup might be different, so do take note of my settings and adjust according to your own web server environment.

I’m planning to setup two sites just for illustration – http://dev.ci/ and http://live.ci/.

Codeigniter default folder structure
When you first unzip the downloaded CI file, you would get something like this:

You would have set your Apache’s configuration to point to your CI folder (which isM:\xampplite\CodeIgniter_1.7.1 for me) as the document root. Once you hit the site in your browser, you would get the standard welcome page.

If you have setup the default CI before, you may know that within the system folder are a bunch of core folders which you don’t normally need to touch and the applicationfolder which will house all your codes for your site. You may also have noticed theindex.php file in the root of the CI directory, which you didn’t really need to touch before but will become crucial in setting up multiple sites.

Adjusting the application folders
First thing I do is to move the application folder out of the system folder to the same level as the system folder.

Since I’m setting up to run two distinct sites sharing the same CI core, I will make another copy of the application folder and rename both folders to reflect the different sites.

Create the web root folders
Next, we would need two folders which will be the website’s root folders. This is how I setup mine.

Make copies of the index.php file located in the CI’s root folder (ieM:\xampplite\CodeIgniter_1.7.1) into each of the htdocs folder. In this case, I would have one index.php in each of my htdocs_ci_dev and htdocs_ci_live folders.

Open index.php file for each site and edit the following lines.

At Line 26:
	$system_folder = "system";
Change to 
	$system_folder = "../system";
 
At Line 43:
	$application_folder = "application";
Change to 
	$application_folder = "../app_ci_dev"; (for the htdocs_ci_dev)
or 
	$application_folder = "../app_ci_live"; (for the htdocs_ci_live)

Configure Apache virtual hosts
Once that’s done, the last thing to do is to setup the Apache virtual host configuration of my XAMPP install.

My Apache virtual host configuration looks like this:

Don’t forget to edit your local hosts file so that your system recognizes the dev.ci and live.ci domains.

Once you fire up your Apache web server, you should be able to load either site accordingly (*fingers crossed*)

Renaming the system folder
If you want to go further you can rename the system folder to reflect the different CI versions. This way, when a new version of the CI core is released, you can configure your sites easily by just changing $system_folder parameter in the index.php file (Line 26) for each site.

Conclusion
I think you will agree that with this setup, you can easily expand the CI install to more sites. There is also no doubt that this is more secure than the default CI setup, as the only folders which are exposed to the browser are the htdocs folders – all theapplication and system folders are no longer accessible through the web server.

Of course, this is not the only way you can configure CI for multiple sites/applications, check out some of these alternatives:
- CodeIgniter Wiki – Multiple Applications
- Michael Wales – CodeIgniter Advent: Day 1
- Multiple codeigniter sites, using symlinks

Please feel free to give your thoughts and feedback. Thanks!


태그 ci
 다음글 제가 초보라서 그럽니다. (2)
 이전글 첫글이닷.. (3)

댓글

행복충만 / 2009/08/31 14:36:03 / 추천 0

번역해 주신다면.. 추천...꾸욱~~