Prerequisites

FuelPHP uses Composer, both for installation and for package dependencies. Make sure you installed composer locally before you continue, because the installation methods described below depend on it being present. See the Download Composer page on how to install composer on your machine.

Command Line Installation

using Oil

Our quick installer is a stripped down interface for the Oil package. It allows you to create a new project with one command. You will also no longer need to use 'php' in your oil commands.

クイックインストーラをインストールするためには、シェルを開き次のコマンドを実行するだけです:

$ curl -L https://get.fuelphp.com/oil | sh

この場合、スクリプトを /usr/bin にインストールするためパスワードを尋ねてくるでしょう。

これであなたのプロジェクトでは php oil の代わりに oil だけを使用することができます。

バージョン 1.6 以前の oil スクリプトをインストール済みの場合は、composer を実行させるために再度、インストールし直す必要があります!

新しいプロジェクトを作成するには単に以下を実行します:

$ oil create <project_name>

これで、カレントディレクトリにあなたが指定したプロジェクト名のフォルダが作成されます。そしてリポジトリとすべてのサブモジュールをそのフォルダに複製します。

Note: This will also run $ oil refine install which makes the necessary directories writable, and $ composer update to pull in the defined composer dependencies.

This currently only works on *nix systems (Linux, OS X, Unix, etc).

using Composer

これはバーチャルホストのルートディレクトリに FuelPHP フレームワークをデフォルトインストールします。

GitHub から最新のリリースを clone する

$ cd /where/ever/your/virtualhost/root/is
$ git clone git://github.com/fuel/fuel.git .
$ composer install --prefer-dist

最後のドットを忘れないでください。さもないと、バーチャルホストのルートディレクトリに fuel というフォルダが作成されます!

Alternatively, you can use composer to install everything in one go:

$ composer create-project fuel/fuel --prefer-dist .

The first method has the advantage that you install the part that will contain your application installed as a git repository. You can change the origin of that repository to your own git server, so your application development is under version control.

The second method creates a complete package with all dependencies. If you want to add that to a git repository, you will also add all dependencies to it. You would like to take this route if your target server on which you run production doesn't have the option to run composer locally to download application dependencies.

Clone the latest development branch from github

$ cd /where/ever/your/virtualhost/root/is
$ git clone git://github.com/fuel/fuel.git -b 1.9/develop .
$ composer install

最後のドットを忘れないでください。さもないと、バーチャルホストのルートディレクトリに fuel というフォルダが作成されます!

Alternatively, you can use composer to install everything in one go:

$ composer create-project fuel/fuel:dev-1.9/develop --prefer-source .

Both will do exactlt the same, and install the latest development version as local git repository clones.

Download the zip file

If for some reason you can't have access to composer, you can also Download the Fuel Framework in a single ZIP file. It contains exactly the same as the command composer create-project fuel/fuel --prefer-dist . would produce.

Altering the default installation

After installation, you will find a folder structure in your installation directory that looks like this:

/
  docs/
  fuel/
    app/
    core/
    packages/
  public/
    .htaccess
    assets/
    index.php
  oil

In this structure, the public directory in the source equals your web server's public document directory. If you can't define your own public folder (or DocumentRoot) in your webserver configuration, Move its contents of the public directory to the folder your provider dictates, i.e. public_html, public, htdocs, etc.

If you want to re-locate the fuel directory, or any directory inside the fuel directory, you need to modify the constants defined in the web frontloader (public/index.php) and the commandline frontloader (oil) so that they point to the correct app, core and packages directories.

After installation, make sure the permissions are correct on folders that the framework needs access to. There is an oil task available to set the default folders writable:

$ oil refine install
	Made writable: APPPATH/cache
	Made writable: APPPATH/logs
	Made writable: APPPATH/tmp
	Made writable: APPPATH/config

If you haven't installed oil like documented at the top of this page, you can also run oil from the installation root directory using:

$ cd /where/ever/your/virtualhost/root/is
$ php oil refine install
	Made writable: APPPATH/cache
	Made writable: APPPATH/logs
	Made writable: APPPATH/tmp
	Made writable: APPPATH/config

設定

メインの設定は app/config/config.php にあります。好きに編集してください。

URL rewriting

Fuel comes with default rewrite rules for Apache (.htaccess) and IIS (web.config). You can find these files in the web application DOCROOT, by default this is the "public folder". If you use Nginx, please find an example here.

Please note that in some default webserver configuration, URL rewriting is disabled by default. To quickly check if this is the case, make a typo in your rewrite config (for example, in your .htaccess file). If your webserver can read and process the file, a typo should give you a 500 Server error. If the typo you introduced doesn't make a change, changes are rewriting or htaccess processing is disabled in the global config.

Install inside the document root

For security reasons, it is strongly advised NOT to install Fuel inside your webserver's document root.

しかしながらそうしたいケースもあります。例えば、Apache の大量の動的なバーチャルホストモジュールのある (ローカルの) 開発環境は、 Web サーバを再起動せずに新しい開発環境を素早く構築するために使用されます。

If you need this, install FuelPHP in the folder you have designated to be the installation root. After you have done that, go into the public folder, move everything in the public folder one level up, and remove the then empty public folder. The only purpose of that folder is to provide an anchor point for your webservers DocumentRoot. You don't need that anymore, since you have installed FuelPHP in the folder that is the DocumentRoot.

移動した後、index.php の中のアプリケーション、パッケージ、フレームワークコアの場所を変更します:

define('APPPATH', realpath(__DIR__.'/fuel/app/').DIRECTORY_SEPARATOR);
define('PKGPATH', realpath(__DIR__.'/fuel/packages/').DIRECTORY_SEPARATOR);
define('COREPATH', realpath(__DIR__.'/fuel/core/').DIRECTORY_SEPARATOR);

いくつかのフォルダをより深くするのはどうでしょう?

違いはありません。手順はまったく同じです。

しかしながら、この場合のアプリケーションへのアクセスは、フォルダ構成のため少々複雑になるかもしれません。同じフォルダ構成のまま移動したファイル群にそのままアクセスすることは、 従来の .htaccess ではできません。

FuelPHP がドキュメントルートの "/deep/sub/folder" にインストールされているとすると、通常ならば http://example.org/deep/sub/folder でアプリーケーションにアクセスする必要があります。

Apache

上位フォルダのどこかに以下の .htaccess を置くことで、存在しないファイルやディレクトリにアクセスがあった場合に、 あなたのアプリケーションにリダイレクトをさせることができます:

<IfModule mod_rewrite.c>
	RewriteEngine on

	# 存在するファイルやフォルダでなかったり、ルートへのリクエストの場合、リクエストをサブフォルダに送る
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d [OR]
	RewriteCond $1 ^$

	RewriteRule ^(.*)$ /deep/sub/folder [R=301,L]
</IfModule>

これはリダイレクトであることに注意してください。ユーザにサブフォルダを隠しません。もし、サブフォルダを隠したい場合は、代わりに以下を使ってください:

<IfModule mod_rewrite.c>
	RewriteEngine on

	# 存在するファイルやフォルダでなかったり、ルートへのリクエストの場合、リクエストをサブフォルダに送る
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d [OR]
	RewriteCond $1 ^$

	RewriteRule ^(.*)$ /deep/sub/folder [QSA,L]
</IfModule>

もちろん、もし "sub" フォルダに配置した場合は、URL から "sub/folder" を隠せますが、"deep" は隠せません...

.htaccess を有効にすると Apache はかなりスローダウンすることに注意してください。サーバ設定へのアクセス権を持っている場合は、 これを無効にし、バーチャルホストの定義に rewrite のルールを追加することを検討してください。

Nginx

Nginx はクライアントの設定ファイルをサポートしていませんので、Nginx の設定ファイルにバーチャルホストのための rewrite ルールを追加する必要があります。 ガイドラインとして以下を使用できます:

server {
	server_name fuelphp.local;

	# これらのファイルに Nginx が書き込めることを確認する
	access_log /var/www/fuelphp/nginxlogs/access.log;
	error_log /var/www/fuelphp/nginxlogs/error.log;
	root /var/www/fuelphp/public;

	location / {
		index index.php;
		try_files $uri $uri/ /index.php$is_args$args;
	}

	location ~ \.php$ {
		include /etc/nginx/fastcgi_params;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param FUEL_ENV "production";
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	}
}

環境を設定する

デフォルトでは、環境は開発モードにセットされています。Fuel は環境を使用して、使用するデータベース設定を定義します。しかし、他のことにも利用できます。

環境を設定するために、.htaccess ファイルに次の行を追加します。

SetEnv FUEL_ENV production

Nginx では、上の例にあるように "fastcgi_param" 文を使います。使用できるオプションの詳細は Fuel クラスの クラス定数 にあります。