Help us understand the problem. What is going on with this article?

Laravel 4のインストール

More than 5 years have passed since last update.

環境
OS:Ubuntu14.04
php 5.6.0
Apache 2.4.10
thinkpad T440p

composerのインストール

~/work$ curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /home/user/work/composer.phar
Use it: php composer.phar

パスが通った場所にコピー

~/work$ sudo mv composer.phar /usr/local/bin/composer

Laravel installerでインストール

~$ composer global require "laravel/installer=~1.1"
Changed current directory to /home/k/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing symfony/console (v2.5.4)
    Downloading: 100%         

  - Installing guzzlehttp/streams (2.1.0)
    Downloading: 100%         

  - Installing guzzlehttp/guzzle (4.2.2)
    Downloading: 100%         

  - Installing laravel/installer (v1.1.3)
    Downloading: 100%         

~/.composer/vendor/binをパスに追加してlaravelコマンドを使用しやすくしておく

export PATH=$PATH:$HOME/.composer/vendor/bin
~$ . .bashrc

プロジェクト作成

~$ laravel new laravel_test
Crafting application...
Application ready! Build something amazing.

これでlaravel_testというプロジェクトが作成される

確認

artisan serveコマンドで組み込みサーバを立ち上げることが出来る

cd laravel_test
php artisan serve

http://localhost:8000/
にアクセス出来てればok

Apacheの使用

apacheの設定でvirtual hostのconfファイルを読み込むようにする

/usr/local/apache2/conf/httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/laravel-vhosts.conf  ##追加

apache2/conf/extra/にはhttpd-vhosts.confが置いてあるのでこれをコピーしてlaravel-vhosts.confとして編集する

/usr/local/apache2/conf/extra/laravel-vhosts.conf
<VirtualHost *:8080>
    ServerName laravel.dev
    ServerAlias myapp.laravel
    DocumentRoot "/home/user/laravel_test/public"
    <Directory "/home/user/laravel_test/public">
      AllowOverride all
      Require all granted
    </Directory>
</VirtualHost>

Apache2.4ではRequire all grantedを書いてないと.htaccessの許可でハマる

laravel_test/app/storageのパーミッションを変更する

cd ~/laravel_test/app
chmod -R 777 storage/

laravel_test/public/.htaccessを編集する
http://blog.ridvanbaluyos.com/2014/02/laravel-4-getting-403-forbidden-access.html
http://stackoverflow.com/questions/18272557/laravel-forbidden-you-dont-have-permission-to-access-on-this-server

<IfModule mod_rewrite.c>
    <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>

以下のように直す

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On

    # Redirect Trailing Slashes...
    # RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

apacheの再起動

apache_restart

laravel.dev:8080/index.php
にアクセスできればok

routeについて

http://laravel4.kore1server.com/docs
app/routes.phpにルーティングを記述する,ここに

Route::get('users','UserController@getIndex');

と記述すると/usrにアクセスした時にapp/controllers/UserControllerのgetIndexメソッドを呼び出す。
UserController.phpのUserControllerクラスに以下のメソッドを追加すると

UserController.php
 <?php

class UserController extends BaseController {

      public function getIndex()
      {
         return View::make('user');
      }
}

viewsにあるuser.blade.phpを読み込む

appのconfig

app/config/app.config

keyの設定はlaravel_test/で
php artisan key:generateで設定される

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away