PHPフレームワーク「Laravel」のバージョン5.3を使用した「Josh Admin template」Version 4.3.2 をenvatomarketから購入しました。Josh Admin templateは、Laravel5.3に対応し、bootstrap3.3.5をベースにしたadmin templateです。

Josh Admin template

xamppがインストールされたWindows7上に、購入したJosh Admin templateをインストールします。

Laravel5.3の動作環境設定

PHP バージョンの確認

Laravel5.3を動作させるためには、PHP バージョン5.4以上が必要となります。コマンドプロンプトで次のコマンドで確認します。

> php -v
PHP 5.6.28 (cli) (built: Nov  9 2016 06:40:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

PHP バージョンが5.4以下の場合、PHP のバージョンが5.4以上のxamppを再インストールします。

再インストールしたxamppのDBは、MySQLからMariaDBに変更されていました。MariaDBは、MySQL派生のデータベースで、MySQLとして現状そのまま利用できます。

再インストールしてもPHP バージョンが変わらない場合、次の手順で、インストールしたXAMPPに、PHPへパスを通します。

  1. 「システムのプロパティ」の詳細設定タブから「環境変数」をクリックします。
  2. 「システム環境変数」から「Path」を選択し、「編集」をクリックします。

    PHPのパス設定
  3. 「変数値」の末尾に「;\xampp\php」(PHPをインストールしたディレクトリを指定)を追加し、「OK」をクリックします。

Composerのインストール

Laravelは、依存パッケージの管理にComposerを使用します。次の手順でWindowsにComposerをインストールします。

  1. Installation – Windows」から「Composer-Setup.exe」をダウンロードします。
  2. 「Composer-Setup.exe」を実行します。画面の指示に従います
  3. コマンドプロンプトを起動して「composer」を入力します。次の画面が表示されれば、正常にインストールされています。
    Windowsへコンポ―サーのインストール

Josh Admin templateのインストール

ドキュメントルートにJosh Admin templateのコピー

Apacheのドキュメントルートにディレクトリ「myjosh」を作成して、Josh Admin templateをコピーします。これによりJosh Admin templateは、次のURLでアクセスできます。

http://localhost/myjosh1/public/

Laravelファイルのinstall

実際にURLにアクセスすると次のエラー「autoload.php): failed to open stream」が発生します。

Warning: require(F:\AnimalflyUpdate\htdocs\myjosh1\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in F:\AnimalflyUpdate\htdocs\myjosh1\bootstrap\autoload.php on line 17

このエラーは、購入したJosh Admin templateには、すべてのLaravelファイルが入っていないために発生します。Josh Admin templateをインストールしたディレクトリに移動して、Composerを使ってLaravelファイルをinstallします。

>cd myjosh1
>composer install --no-dev
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 98 installs, 0 updates, 0 removals
  - Installing vlucas/phpdotenv (v2.4.0) Loading from cache
  - Installing symfony/polyfill-mbstring (v1.3.0) Loading from cache
  - Installing symfony/var-dumper (v3.1.9) Downloading: 100%
  - Installing symfony/translation (v3.1.9) Downloading: 100%
  - Installing symfony/routing (v3.1.9) Downloading: 100%
  - Installing symfony/process (v3.1.9) Downloading: 100%
    ...
    ...
barryvdh/reflection-docblock suggests installing dflydev/markdown (~1.0)
barryvdh/reflection-docblock suggests installing erusev/parsedown (~1.0)
maximebf/debugbar suggests installing kriswallsmith/assetic (The best way to manage assets)
maximebf/debugbar suggests installing predis/predis (Redis storage)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
Compiling common classes

データベースの設定

再度、「http://localhost/myjosh1/public/」にアクセスすると、次のように「Whoops, looks like something went wrong.」が表示されます。

インストールエラー

これは、データベースが設定されていないためです。「.env.example」をコピーして「.env」を作成し、次のようにデータベース名等を設定します。同時にデータベース名「myjosh」、照合順序「utf8_unicode_ci」でデータベースを生成します。
【.env】

   …
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myjosh
DB_USERNAME=root
DB_PASSWORD=
   …

アプリケーションキーの設定

再度、「http://localhost/myjosh1/public/」にアクセスすると、次のように「RuntimeException in compiled.php line 13510: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.」が表示されます。

アプリケーションキーの設定エラー

これは、アプリケーションキーが設定されていないため、つまり、「.env」のAPP_KEYがデフォルト値のためです。「.env.example」をコピーして「.env」を作成したので、APP_KEYには何も設定されておらず、このため、「.env」と同じディレクトリで次のコマンドを実行し、「.env」のAPP_KEYにアプリケーションキーを設定します。

>php artisan key:generate
Application key [base64:xxxxxS04VNG4OVwMNVMZhtT31wCauehQ1kB2AfNxg8=] set successfully.

再度、「http://localhost/myjosh1/public/」にアクセスすると、次のようにJosh Admin templateの画面が表示されます。

Josh Admin templateの画面

Josh Admin templateの認証設定

データベースのテーブルの設定

メインメニューの「REGISTER」を選択すると。次の画面が表示されます。

アカウントの作成

ここで、アカウントを作成すると、次のように画面にエラーメッセージ「QueryException in Connection.php line 770: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘myjosh.users’ doesn’t exist 」が表示されます。

データベースのテーブルエラー

また、管理者のログイン「http://localhost/myjosh1/public/admin」を行うと次の画面が表示されます。

管理者のログイン画面

この画面でログインしようとしても、上記と同様なエラーメッセージが表示されます。このエラーは、データベースにテーブルが作成されていないために表示されています。Josh Admin templateをインストールしたディレクトリに移動して、次のコマンドを実行します。これで必要なテーブルが生成されます。

>php artisan migrate
Migration table created successfully.
Migrated: 2014_07_02_230147_migration_cartalyst_sentinel
Migrated: 2014_10_04_174350_soft_delete_users
Migrated: 2014_12_10_011106_add_fields_to_user_table
Migrated: 2015_08_09_200015_create_blog_module_table
Migrated: 2015_08_11_064636_add_slug_to_blogs_table
Migrated: 2015_08_19_073929_create_taggable_table
Migrated: 2015_11_10_140011_create_files_table
Migrated: 2016_01_02_062647_create_tasks_table
Migrated: 2016_04_26_054601_create_datatables_table
Migrated: 2016_10_04_103149_add_fields_datatables_table

次のコマンドで、管理者のアカウント「admin@admin.com」、パスワード「admin」が作成されます。なお、管理者のアカウントを自分のメールアドレスにしたい場合は、「database/seeds/AdminSeeder.php」を編集してメールアドレスを設定します。

>php artisan db:seed --class=AdminSeeder
Admin User created with username admin@admin.com and password admin

データベースのテーブルは次のようになっています。

データベースのテーブル

ユーザとしてログインすると次の画面が表示されます。

ユーザとしてログイン

管理者としてログイン「http://localhost/myjosh1/public/admin」すると次の画面が表示されます。

管理者としてログイン

メールの設定

ログイン画面で「Forgot Password」を選択すると次の画面が表示されます。

Forgot Password画面

ここで先ほど登録したメールアドレス「admin@admin.com」(実際には実在するメールアドレス)を設定して「Reset Your Password」ボタンを押すと、次に示すようにエラーメッセージ「Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code “530”, with message “530 5.7.1 Authentication required」が表示されます。

メール設定エラー

このエラーメッセージは、メール設定ができていない場合に表示され、次の.envファイルとmail.phpファイルにメール設定を行います。

[.env]

MAIL_DRIVER=smtp
MAIL_HOST=xxx    // xxx:SMTPサーバ
MAIL_PORT=587
MAIL_USERNAME=info@tomosoft.jp
MAIL_PASSWORD=yyy    // yyySMTPサーバのパスワード
MAIL_ENCRYPTION=null

[config/mail.php]

‘driver’ => env(‘MAIL_DRIVER’, ‘smtp’),
‘host’ => env(‘MAIL_HOST’, ‘xxx’), xxx:SMTPサーバ
‘port’ => env(‘MAIL_PORT’, 586),
‘from’ => [
 ’address’ => ‘info@tomosoft.jp’,
 ’name’ => ‘TomoSoft’,
],
‘encryption’ => env(‘MAIL_ENCRYPTION’, ‘tls’),
‘username’ => env(‘MAIL_USERNAME’),
‘password’ => env(‘MAIL_PASSWORD’),
‘sendmail’ => ‘/usr/sbin/sendmail -bs’,

再度、実行すると次の画面が表示され、次のメールが送信されます。

パスワード問い合わせ

Hello Tomo Soft,
Please click on the following link to updated your password:
http://localhost/myjosh1/public/forgot-password/2/N1Jr0oxxxMEnB7FeZGxry1jJfDMF3X
Best regards,
SiteName Team

メールで指定されたURLをアクセスすると、次の画面が表示され、再度パスワードが設定できます。

パスワード再設定