又有一段時間沒有學習了!迷茫,除了迷茫還是在迷茫!最近,公司接了一個laravel的項目,可惜沒有phper,于是開始學習laravel,現在的情況就是還沒學會走路就要開始跑了,所以遇到坑會摔得很痛!安裝出現的問題
安裝步驟(5.3.*)
composer global require "laravel/installer" composer create-project --prefer-dist laravel/laravel blog "5.3.*"
出現的問題
①無法安裝composer依賴報錯: php.ini 缺少mbstring
laravel/framework v5.4.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
解決: 放開注釋extension=php_mbstring.dll
②php artisan ser能運行但頁面報錯報錯: The only supported ciphers are AES-128-CBC and AES-256-CBC
解決: 先運行這個命令
php artisan key:generate
再運行
php artisan config:clear③同事安裝php出現的問題:php.ini啟用openssl時報錯openssl.dll找不到
錯誤顯示他的配置默認去C:/php/ext/下去找openssl.dll文件
解決: 他開的是虛擬機,修改extension_dir = "./" 路徑為絕對路徑
報錯:
TokenMismatchException in VerifyCsrfToken.php line 68: in VerifyCsrfToken.php line 68 at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in StartSession.php line 64 at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 104 at Pipeline->then(object(Closure)) in Router.php line 655 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629 at Router->dispatchToRoute(object(Request)) in Router.php line 607 at Router->dispatch(object(Request)) in Kernel.php line 268 at Kernel->IlluminateFoundationHttp{closure}(object(Request)) in Pipeline.php line 53 at Pipeline->IlluminateRouting{closure}(object(Request)) in EnableCrossRequestMiddleware.php line 19 at EnableCrossRequestMiddleware->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in CheckForMaintenanceMode.php line 46 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137 at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33 at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 104 at Pipeline->then(object(Closure)) in Kernel.php line 150 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117 at Kernel->handle(object(Request)) in index.php line 54 at require_once("E:phpStudyWWWmylaravellogpublicindex.php") in server.php line 21
原因:laravel為了防止跨站腳本攻擊(CSRF),會自動為每個活躍用戶的會話生成一個 CSRF「令牌」。該令牌用于驗證經過身份驗證的用戶是否是向應用程序發出請求的用戶。
解決:在app/Http/Middleware/VerifyCsrfToken中放行需要訪問的地址。如
protected $except = [ // /*, /wechat, ];⑤遇到跨域問題(laravel跨域))
運行命令
php artisan make:middleware EnableCrossRequestMiddleware
自動在app/Http/Middleware下生成一個EnableCrossRequestMiddleware.php
}增加中間件內容
server("HTTP_ORIGIN") ? $request->server ("HTTP_ORIGIN") : ""; $allow_origin = [ "http://localhost:8000", // 允許跨域的列表了,可自行修改 ]; if (in_array($origin, $allow_origin)) { $response->header("Access-Control-Allow-Origin", $origin); $response->header("Access-Control-Allow-Headers", "Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN"); $response->header("Access-Control-Expose-Headers", "Authorization, authenticated"); $response->header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, OPTIONS"); $response->header("Access-Control-Allow-Credentials", "true"); } return $response; } } 在內核文件注冊該中間件(在 AppHttpKernel 類的 $middleware 屬性添加,這里注冊的中間件屬于全局中間件) protected $middleware = [ // more AppHttpMiddlewareEnableCrossRequestMiddleware::class, ];⑥composer安裝報錯報錯:win7下使用命令行安裝的composer使用時莫名其妙報錯
[JsonSchemaExceptionResourceNotFoundException] file_get_contents(file://): failed to open stream: No such file or directory解決:下載Composer-Setup.exe,重新安裝composer
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/28917.html
摘要:再次打開包內源碼,發現了如下的細節敲黑板注意看路徑,此時是包內知道原理之后,于是在配置文件中做了如下修改至此,,收工 項目中使用了mongoDB,所以就到最大的同性交友網站找到了星星最多的jenssegers/laravel-mongodb 包安裝 1、根據README,找到本地laravel對應的包版本showImg(https://segmentfault.com/img/bVbr...
摘要:再次打開包內源碼,發現了如下的細節敲黑板注意看路徑,此時是包內知道原理之后,于是在配置文件中做了如下修改至此,,收工 項目中使用了mongoDB,所以就到最大的同性交友網站找到了星星最多的jenssegers/laravel-mongodb 包安裝 1、根據README,找到本地laravel對應的包版本showImg(https://segmentfault.com/img/bVbr...
摘要:如何實現持久化持久化,將在內存中的的狀態保存到硬盤中,相當于備份數據庫狀態。相當于備份數據庫接收到的命令,所有被寫入的命令都是以的協議格式來保存的。 最近社區里面有一篇文章引起了最多程序猿的關注,Laravel、PHPer 面試可能會遇到的問題,看評論區不少小伙伴們被難倒,對于一些問題同樣難倒了我(其實有很多啦),趁著周末有空,又總結梳理了一遍,順便來答一波題。由于個人技術水平有限,答...
閱讀 1816·2019-08-30 15:55
閱讀 1007·2019-08-26 11:57
閱讀 509·2019-08-26 11:29
閱讀 3358·2019-08-26 10:49
閱讀 1910·2019-08-23 18:40
閱讀 1749·2019-08-23 16:04
閱讀 3104·2019-08-23 11:01
閱讀 2271·2019-08-23 10:56