laravel 安装及基本设置

安装

推荐使用 composer 安装:composer create-project laravel/laravel=5.4.23 lar.com

权限修改

chmod -R 777 lar.com/storage
chmod -R 777 lar.com/bootstrap/cache

配置及读取

  • laravel 的入口目录为 appname/public , 所以在服务器上应该将入口指向 lar.com/public
  • laravel 所有配置文件均放置在 appname/config 目录下,读取配置:$value = config( 'app.name' )

配置优雅URL

所谓优雅URL,就是去掉 index.php 这一层级,针对于不同 web 服务器有不同处理方法

  • Apache 确保 mod_rewrite 模块开启,且允许项目中的 .htaccess 发挥作用,即保证 AllowOverride All;
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All
.htaccess 文件内容为:
   Options +FollowSymLinks
   RewriteEngine On

   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
  • Nginx 则相对简单很多:
location / {
    try_files $uri $uri/ /index.php?$query_string;
}

维护模式

当应用程序处于维护模式时,所有传递至应用程序的请求都会显示出一个自定义视图。该视图模板为resources/views/errors/503.blade.php

开启维护模式:php artisan down

关闭维护模式:php artisan up

results matching ""

    No results matching ""