轻松搞定Laravel安装过程中的遇到常见异常问题?

最近有小伙伴私信我说安装Laravel老是出现奇怪的报错,而且都是英文的,看不懂,为了帮助小伙伴们解决这些报错问题,也是非常耽搁时间,现在我专门发一篇文章总结一下Laravel安装常规错误详解,如果大家有这样的问题,请详细查看问题,帮助大家及时解决,本文安装laravel版本为Larave 7。

前言:Laravel的安装方式有好几种,常用的安装方式:直接下载压缩文件安装、composer安装、github安装等,现在我用composer安装,composer安装需要注意,你的机器上必须安装有composer软件。

1、首先根据官网执行composer安装

// 最好设置一个国内源,用阿里云的 
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 

// 开始安装项目 
composer create-project --prefer-dist laravel/laravel blog

2、设置一个唯一秘钥

php artisan key:generate

3、访问:

http://www.xxx.com/index.php

常见问题:

那么我们的问题来了哈!上面的安装很简单,但运行的时候到处都是问题。

1、安装要求:

  • PHP >= 7.2.5

  • BCMath PHP 拓展

  • Ctype PHP 拓展

  • Fileinfo PHP 拓展

  • JSON PHP 拓展

  • Mbstring PHP 拓展

  • OpenSSL PHP 拓展

  • PDO PHP 拓展

  • Tokenizer PHP 拓展

  • XML PHP 拓展

解决:首先你的开发环境就必须要满足以上的条件,差一个都要报错,如果不知道从哪里看扩展是否安装成功,在环境下新建一个phpinfo.php文件,访问:http://localhost/phpinfo.php,看到如下界面就是访问正常,再找到相应的扩展。

 

2、扩展也安装完成,却出现不能访问出现403情况,那是什么问题呢?

解决:php内部有禁用函数,需要把禁用函数释放掉。(我的是本地开发,全部去掉了,线上运行不要全部释放,需要禁用的还是要禁用)

liunx环境下:/usr/local/nginx/conf fastpram.conf 注释最后一行

 

3、访问目录不存在

解决:

// 执行 composer install 或者 composer update

 

4、以下代码错误。

Fate:In Connection.php line 664: SQLSTATE[HY000]: General error:PDO::ATTR_STATEMENT_CLASS requires format array(classname,array(ctor_args)); 
the classname must be a string specif ying an existing class(SQL: select *from information_schema.tables where table_schema = blog and table_name = xxx_migrations)In PDOConnection.php line 50: SQLSTATE[HY000]: General error:PDO::ATTR_STATEMENT_CLASS requires format array(classname,array(ctor_args));
 the classname must be a string specif ying an existing classIn PDOConnection.php line 47: SQLSTATE[HY000]: General error:PDO::ATTR_STATEMENT_CLASS requires format array(classname,array(ctor_args)); 
the classname must be a string specif ying an existing classIn PDOStatement.php line 40: syntax error, unexpected const(T_CONST), expecting variable(T_VARIABLE)

解决:把版本升级到7.2.5以上,就直接解决。

 

5、以下代码错误。

composer installLoading composer repositories withpackage informationInstalling dependencies(including require-dev)from lock fileYour requirements could not be resolved to an installable setof packages. 
Problem 1 - This package requires php >=7.0.0 but your PHPversion(5.6.27) does not satisfy that requirement. 
Problem 2 - Installation request for doctrine/annotations v1.6.0-> satisfiable by doctrine/annotations[v1.6.0]. 
- doctrine/annotations v1.6.0 requires php ^7.1-> your PHPversion(5.6.27) does not satisfy that requirement. 
Problem 3 - Installation request for doctrine/cache v1.7.1-> satisfiable by doctrine/cache[v1.7.1]. 
- doctrine/cache v1.7.1 requires php ~7.1-> your PHPversion(5.6.27) does not satisfy that requirement.

解决:把版本升级到7.1以上,就直接解决。

 

6、缓存问题。

解决:上面的四个文件夹必须存在,如果没有需要手动创建,执行php artisan cache:clear清理缓存

 

7、以下所示:

解决如下,取消禁用函数。

 

8、页面不能访问(liunx环境下)

解决:由于strong没有写入权限导致的 进入项目根目录

chmod 777 strong -R

 

9、执行php artisan migrate报错

PHP Warning:require(/server/web/test_api/vendor/autoload.php): 
failed to open stream: No such file or directory in/server/web/test_api/artisan on line 18

PHP Fatal error:require(): Failed opening required '/server/web/test_api/vendor/autoload.php'(include_path='.:/usr/local/php/lib/php')in/server/web/test_api/artisan on line 18

解决:先执行composer install 在执行 php artisan migrate

 

10、内存不足报错

解决:只能加硬件了,没有其他办法

以上总结了部分常规问题,如果你遇到了,那么很快就能解决,后期遇到的问题,我都会记录下来,后面发文更新,记得随时关注哟!公众号(Laravel技术社区).。

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