laravel-admin搭建后台管理系统
2022-10-28 15:19:56
170
{{single.collect_count}}

最近有个搭建后台管理系统的需求,这里选用的是在laravel框架下的laravel-admin扩展,安装步骤如下:

#安装laravel,项目名称tempcomposer create-project --prefer-dist laravel/laravel temp "5.5.*"

如果提示没安装composer,可执行下述命令,并将其移到指定目录下即可。

# 下载composer.phar curl -sS https://getcomposer.org/installer | php# 移动composer.phar到环境变量,可直接运行 mv composer.phar /usr/bin/composer

再重新执行composer安装命令,执行该命令后需要一些时间,之后会在当前目录下生产temp文件夹,进入该目录后会看到一个.env文件,打开并编辑数据库配置:

DB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=tempDB_USERNAME=rootDB_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_nametemp.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就可以啦!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}