애플리케이션 관리
기본적으로는 CodeIgniter를 사용해 app 디렉터리에서 하나의 애플리케이션만 관리한다고 가정합니다. 하지만 하나의 CodeIgniter 설치를 여러 애플리케이션 세트가 공유하도록 구성하거나, 애플리케이션 디렉터리의 이름을 바꾸거나 위치를 옮길 수도 있습니다.
애플리케이션 디렉터리 이름 변경 또는 위치 이동
If you would like to rename your application directory or even move
it to a different location on your server, other than your project root, open
your main app/Config/Paths.php and set a full server path in the
$appDirectory variable (at about line 45):
<?php
namespace Config;
class Paths
{
// ...
public string $appDirectory = '/path/to/your/app';
// ...
}
Paths 설정 파일을 찾을 수 있도록 프로젝트 루트의 추가 파일 두 개도 수정해야 합니다:
spark 는 명령줄 앱을 실행합니다.
require FCPATH . '../app/Config/Paths.php'; // ^^^ Change this line if you move your application folder
public/index.php 는 웹앱의 프론트 컨트롤러입니다.
require FCPATH . '../app/Config/Paths.php'; // ^^^ Change this line if you move your application folder
하나의 CodeIgniter 설치로 여러 애플리케이션 실행
공통 CodeIgniter 프레임워크 설치를 여러 애플리케이션에서 공유하려면, 애플리케이션 디렉터리 안에 있는 모든 디렉터리를 각각의 (하위) 디렉터리로 옮기면 됩니다.
For example, let’s say you want to create two applications, named blog and shop. You could structure your application project directories like this:
blog/
app/
public/
tests/
writable/
env
phpunit.dist.xml
spark
shop/
app/
public/
tests/
writable/
env
phpunit.dist.xml
spark
vendor/
autoload.php
codeigniter4/framework/
composer.json
composer.lock
참고
Zip 파일에서 CodeIgniter를 설치한 경우 디렉터리 구조는 다음과 같습니다:
blog/
shop/
codeigniter4/system/
This would have two apps, blog and shop, both having standard application directories and a public folder, and sharing a common codeigniter4/framework.
각 앱의 app/Config/Paths.php 에 있는 $systemDirectory 변수는 공유되는 codeigniter4/framework 폴더를 가리키도록 설정합니다:
<?php
namespace Config;
class Paths
{
// ...
public $systemDirectory = __DIR__ . '/../../../vendor/codeigniter4/framework/system';
// ...
}
그리고 각 앱의 app/Config/Constants.php 에서 COMPOSER_PATH 상수도 수정합니다:
<?php
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . '../vendor/autoload.php');
참고
If you install CodeIgniter from the Zip file, the $systemDirectory would be __DIR__ . '/../../../codeigniter4/system'.
If you don’t use Composer, you don’t have to edit the COMPOSER_PATH.
애플리케이션 디렉터리를 변경한 경우에만 애플리케이션 디렉터리 이름 변경 또는 위치 이동 를 참고하여 index.php 와 spark 의 경로를 수정하세요.
.env 파일 위치 변경
필요하면 app/Config/Paths.php 의 $envDirectory 속성을 조정해 .env 파일 위치를 변경할 수 있습니다.
기본적으로 프레임워크는 app/ 디렉터리에서 한 단계 위(ROOTPATH)에 있는 .env 파일에서 환경 설정을 로드합니다. 권장 사항대로 도메인이 public/ 디렉터리를 올바르게 가리키는 경우 이 위치는 안전합니다.
하지만 실제로는 일부 애플리케이션이 메인 도메인이 아닌 하위 디렉터리(예: http://example.com/myapp)에서 서비스됩니다. 이런 경우 .htaccess 나 기타 보호 설정이 잘못되면 ROOTPATH 내의 .env 파일이 민감한 구성 데이터를 노출할 수 있습니다.
이런 구성에서 위험을 피하려면 .env 파일을 웹에서 접근 가능한 디렉터리 밖에 두는 것을 권장합니다.
경고
.env 파일 위치를 변경한다면 외부에서 절대 접근할 수 없도록 반드시 확인하세요. 이 파일이 노출되면 자격 증명이 유출되고 데이터베이스, 메일 서버, 서드파티 API 같은 핵심 서비스 접근 권한이 침해될 수 있습니다.