最近有小夥伴私信我說安裝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技術社區).。