學習足跡

2013年7月4日 星期四

在Laravel 4使用artisan建立app key

清除檔案中的key

app/config/app.php檔案中你會找到一組key的位置,這個key是一組32個字元的key,我們可以自己輸入想要的key,或者使用Laravel 4提供的Artisan命令列去自動亂數產生一組key



使用artisan指令產生key

在命令列輸入php artisan可以看到所有artisan支援的指令,你可以找到key:generate可以產生一組亂數的key。

$ php artisan
Laravel Framework version 4.0.0
Usage:
  [options] command [arguments]
Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for                                                                  more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --env               The environment the command should run under.
Available commands:
  clear-compiled     Remove the compiled class file
  down               Put the application into maintenance mode
  dump-autoload      Regenerate framework autoload files
  help               Displays help for a command
  list               Lists commands
  migrate            Run the database migrations
  optimize           Optimize the framework for better performance
  routes             List all registered routes
  serve              Serve the application on the PHP development server
  tinker             Interact with your application
  up                 Bring the application out of maintenance mode
  workbench          Create a new package workbench
asset
  asset:publish      Publish a package's assets to the public directory
auth
  auth:reminders     Create a migration for the password reminders table
cache
  cache:clear        Flush the application cache
command
  command:make       Create a new Artisan command
config
  config:publish     Publish a package's configuration to the application
controller
  controller:make    Create a new resourceful controller
db
  db:seed            Seed the database with records
key
  key:generate       Set the application key

migrate
  migrate:install    Create the migration repository
  migrate:make       Create a new migration file
  migrate:refresh    Reset and re-run all migrations
  migrate:reset      Rollback all database migrations
  migrate:rollback   Rollback the last database migration
queue
  queue:listen       Listen to a given queue
  queue:subscribe    Subscribe a URL to an Iron.io push queue
  queue:work         Process the next job on a queue
session
  session:table      Create a migration for the session database table

所以我們輸入php artisan key:generate即可產生我們需要的key了
php artisan key:generate
Application key [2wgjsIpDDIJvc4AgMV6VV1QybWznB6nY] set successfully.

檢查key產生狀況

接下來回到app/config/app.php檔案中,找到key資料的位置,確認key是否以正確的產生即可。


同步發表於

沒有留言:

張貼留言