LoginSignup
11
9

More than 5 years have passed since last update.

Laravel5.1をHerokuのPHP7でとりあえず動かす

Last updated at Posted at 2015-12-12

HerokuでPHP7が使えるようになったらしいので動かしてみました

前提

git, composer, herokuの各コマンドが使える状態からスタートします。

ローカルでインストール

$ composer create-project laravel/laravel --prefer-dist
$ cd laravel
$ php artisan serve
#=> Laravel development server started on http://localhost:8000/

http://localhost:8000 で動作します。

gitの初期化

# apache用のProcfileを作成
echo 'web: vendor/bin/heroku-php-apache2 public' > Procfile

# gitします
$ git init
$ git add .
$ git commit -m "first commit for heroku"

heroku アプリを作ってデプロイ

# アプリ作成 特に指定しなければPHP7になるようですが、この時Cedar-14と表示されないとPHP7で動かせません
# @see https://devcenter.heroku.com/articles/php-support#supported-versions
$ heroku create

# herokuにPHPだと認識させる
# composer.jsonとpackage.jsonが共存しているのでそのままだとnode.jsアプリとして認識されてしまう
$ heroku buildpacks:set heroku/php

# herokuの環境変数APP_KEYをセットします
$ heroku config:set APP_KEY=$(php artisan key:generate --show)


# デプロイ!
$ git push heroku master

#remote: -----> Using set buildpack heroku/php
#remote: -----> PHP app detected
#remote: -----> Bootstrapping...
#remote: -----> Installing system packages...
#remote:        - php (7.0.0)
#remote:        - Apache (2.4.16)
#(略)

# 確認します(ブラウザでアプリが開きます)
$ heroku open

Laravel5と大きく表示されていれば成功です。
レスポンスヘッダでも確認してみましょう。

# 作成されたURLに置換してください
$ curl -I https://xxxxx-xxx-xxx.herokuapp.com

HTTP/1.1 200 OK
Connection: keep-alive
Date: Sat, 12 Dec 2015 10:28:50 GMT
Server: Apache/2.4.16 (Unix) OpenSSL/1.0.1f
X-Powered-By: PHP/7.0.0

それっぽい感じで動いているようです。
一行も直さずに動かせるのは素晴らしいですね。

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9