やりたいこと
さくらのレンタルサーバーでLaravelをとりあえず使いたい。
環境
さくらのレンタルサーバ スタンダード
PHP 5.4
Laravel 4.2
前提
「さくらのレンタルサーバにComposerをインストールする方法」でComposerをインストールしておくこと。
「さくらのレンタルサーバのシェルをbashに変更する方法」で「~/.bash_profile」が有効になっていること。
やり方
1. Laravelインストーラ経由でLaravelをインストールする。
2. $PATHを追加する。
3. 「laravel new」コマンドを実行する。
4. 「.htaccess」ファイルを変更する。
5. サイトを確認する。
1.Laravelインストーラ経由でLaravelをインストールする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ cd ~ $ composer global require "laravel/installer=~1.1" Changed current directory to /home/hoge/.composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing symfony/console (v2.5.3) Downloading: 100% - Installing guzzlehttp/streams (1.5.1) Downloading: 100% - Installing guzzlehttp/guzzle (4.1.8) Downloading: 100% - Installing laravel/installer (v1.1.2) Downloading: 100% symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing psr/log (For using the console logger) Writing lock file Generating autoload files |
2.$PATHを追加する。
「$ laravel」で実行できるように「.bash_profile」のPATHに「$HOME/.composer/vendor/bin」を追加する。
1 2 3 |
$ vi ~/.bash_profile PATH=$PATH:$HOME/bin:$HOME/usr/local/bin:$HOME/.composer/vendor/bin |
3.「laravel new」コマンドを実行する。
「http://XXXX.sakura.ne.jp/laravel_test/public/」でアクセスできるようにする。
とりあえず使用なので「/laravel_test/public/」で我慢する。
「app/storage」ディレクトリはApacheが書き込めるようにパーミッションを変更すること。
1 2 3 |
$ cd ~/www/ $ laravel new laravel_test $ chmod 707 laravel_test/app/storage/ |
4.「.htaccess」ファイルを変更する。
「.htaccessによるアクセス制御」(さくらのサポート情報ページ)の注意事項に「ファイル中にOptionsの指定は出来ません。」とあるので、「.htaccess」ファイルを変更する。
これを忘れると「Internal Server Error」になる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ vi ~/www/laravel/public/.htaccess <IfModule mod_rewrite.c> <span class="comment">以下3行をコメントアウトする</span> # <IfModule mod_negotiation.c> # Options -MultiViews # </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> |
5.サイトを確認する。
こんな感じになれば成功。