laravel-admin搭建後臺管理系統

最近有個搭建後臺管理系統的需求,這裏選用的是在laravel框架下的laravel-admin擴展,安裝步驟如下:

#安裝laravel,項目名稱temp
composer create-project --prefer-dist laravel/laravel temp "5.5.*"

執行該命令後需要一些時間,之後會在當前目錄下生產temp文件夾,進入該目錄後會看到一個.env文件,打開並編輯數據庫配置:

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=temp
DB_USERNAME=root
DB_PASSWORD=123456

然後再依次運行一下命令:

#安裝laravel-admin擴展
composer require encore/laravel-admin
#發佈資源
php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
#安裝
php artisan admin:install

在執行第三步安裝時候,碰到了如下問題:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; 
max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

,這時只需在如下文件中添加這麼一句:

use Illuminate\Support\Facades\Schema;//新添加

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Schema::defaultStringLength(191);//新添加
    }
    ...
}

然後刪掉temp庫下新建的兩張表migrations和user表,此時不刪除也沒關係,待重新執行php artisan admin:install命令時就會提示這兩張表已經存在了。

接下來既可以直接執行php artisan serve,也可以在nginx中配置,我是在nginx配置的,配置內容如下:

server {
        listen       8888;
        server_name  temp.com.cn;
        root         /usr/home/www/temp/public;
        index index.php index.html index.htm;
        client_max_body_size 8M;
        client_body_buffer_size 128k;
        fastcgi_intercept_errors on;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}

配置好後重新啓動nginx。補充一下,如果是在windows下搭建,應該不會遇到下面這個問題。由於我這裏是在測試服務器中搭建的,這時如果在瀏覽器中打開的話,會報404錯誤,如下:

這地方是因爲項目目錄下的storage文件夾不可寫造成的,這裏可以將該文件夾權限改成777即可。

至此,在瀏覽器充再次打開就跳出登錄頁,輸入admin:admin就可以啦!

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章