前提:已安装好laravel(5.5以上版本),并且能够运行,设置好数据库连接并且能成功连接
进入项目目录,使用composer安装报如下错误:
$ composer require encore/laravel-admin Using version ^1.6 for encore/laravel-admin ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) VirtualAlloc() failed: [0x00000008] ▒洢▒▒▒㣬▒▒▒▒▒▒▒▒▒▒ VirtualFree() failed: [0x000001e7] ▒▒ͼ▒▒▒▒▒▒Ч▒ĵ▒ַ▒▒ VirtualAlloc() failed: [0x00000008] ▒洢▒▒▒㣬▒▒▒▒▒▒▒▒▒▒ VirtualFree() failed: [0x000001e7] ▒▒ͼ▒▒▒▒▒▒Ч▒ĵ▒ַ▒▒ PHP Fatal error: Out of memory (allocated 511705088) (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220 Fatal error: Out of memory (allocated 511705088) (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
看错误内容为内存不足,于是修改php.ini中内存限制参数为-1,即不限制PHP内存
memory_limit = -1
重启服务器,再次安装,还是报相同错误,于是经过一番谷歌百度,无非就是增大内存限制、更新composer等等。具体可以参考以下两篇文章How to solve Composer install/update error: VirtualAlloc() failed: [0x00000008] 和 Composer: PHP Fatal error: Out of memory || Setting memory_limit doesn't work
但是最终的结果都是没有效果,还是一如既往地报内存不足,无奈只能重启电脑再试,结果重启后运行安装命令laravel-admin成功安装
$ composer require encore/laravel-admin Using version ^1.6 for encore/laravel-admin ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi Discovered Package: beyondcode/laravel-dump-server Discovered Package: encore/laravel-admin Discovered Package: fideloper/proxy Discovered Package: laravel/tinker Discovered Package: nesbot/carbon Discovered Package: nunomaduro/collision Package manifest generated successfully.
接下来按照laravel-admin进行资源发布:
$ composer require encore/laravel-admin Using version ^1.6 for encore/laravel-admin ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi Discovered Package: beyondcode/laravel-dump-server Discovered Package: encore/laravel-admin Discovered Package: fideloper/proxy Discovered Package: laravel/tinker Discovered Package: nesbot/carbon Discovered Package: nunomaduro/collision Package manifest generated successfully.
然后运行安装命令,报出如下错误:
$ php artisan admin:install Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `tb_users` add unique `tb_users_email_unique`(`email`)) at D:\bd\treasure_box\vendor\laravel\framework\src\Illuminate\Database\Connect ion.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make th is exception a 662| // lot more helpful to the developer instead of just the databa se's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or acce ss violation: 1071 Specified key was too long; max key length is 1000 bytes") D:\bd\treasure_box\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatem ent.php:119 2 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Sp ecified key was too long; max key length is 1000 bytes") D:\bd\treasure_box\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatem ent.php:117 Please use the argument -v to see more details.
查询资料发现需要修改数据库连接设置config/databases.php如下:
'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => 'InnoDB',
设置好后再次运行,成功安装:
$ php artisan admin:install Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table Migrating: 2014_10_12_100000_create_password_resets_table Migrated: 2014_10_12_100000_create_password_resets_table Migrating: 2016_01_04_173148_create_admin_tables Migrated: 2016_01_04_173148_create_admin_tables Database seeding completed successfully. Admin directory was created: \app\Admin HomeController file was created: \app\Admin/Controllers/HomeController.php AuthController file was created: \app\Admin/Controllers/AuthController.php ExampleController file was created: \app\Admin/Controllers/ExampleController.php Bootstrap file was created: \app\Admin/bootstrap.php Routes file was created: \app\Admin/routes.php
运行服务:
$ php artisan serve Laravel development server started: <http://127.0.0.1:8000>