Laravel經驗
希望這篇文章可以幫助你快速通過我在開發Laravel時所遇到的各種坑(如果有遇到新的我會持續更新)
為什麼總是要 composer dump-autoload ?
剛開始接觸用 composer 的時候一直被這個問題蠱惑。很不理解為什麼總是要打這句命令才能不報錯,現在終於知道根結了。
因為 database 文件夾使用 classmap 來做加載的。所以只有在打了 composer dumpautoload 之後 composer 才會更新 autoload_classmap 的內容。
遇到無法composer可用這個
sudo apt-get install php-mbstringsudo apt-get install php-xml
如果遇到log讀寫權限不足
vim /etc/nginx/nginx.conf
去看nginx的權限user www-data;
Laravel的資料夾權限需要跟nginx一樣
chown -R www-data.www-data device-apisudo chgrp -R www-data storage bootstrap/cachesudo chmod -R ug+rwx storage bootstrap/cache
php-fpm錯誤: WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
https://blog.csdn.net/encircles/article/details/80503756
timeout相關(包含nginx, php-fpm)
https://blog.goodjack.tw/2018/08/increase-php-fpm-script-execution-time-with-nginx.html
composer 版本太舊無法更新問題
nginx 出现504 Gateway Time-out的解决方法
sudo vi /etc/nginx/nginx.conf
系統有超過 300~500mb的影片,这了,超時時間調整為30分鐘;這裡有更詳細的說明
proxy_connect_timeout 1800s;#nginx跟後端服務器連接超時時間(代理連接超時)proxy_send_timeout 1800s;#後端服務器數據回傳時間(代理發送超時)proxy_read_timeout 1800s;#連接成功後,後端服務器響應時間(代理接收超時)fastcgi_connect_timeout 1800s;#指定nginx與後端fastcgi server連接超時時間fastcgi_send_timeout 1800s;#指定nginx向後端傳送請求超時時間(指已完成兩次握手後向fastcgi傳送請求超時時間)fastcgi_read_timeout 1800s;#指定nginx向後端傳送響應超時時間(指已完成兩次握手後向fastcgi傳送請求超時時間)
Laravel 同時間大量update會有數據對不上的問題(transaction issue)
https://blog.scottchayaa.com/post/2019/01/09/how-to-handle-the-high-concurrency-on-laravel/
Php的mysql沒有安裝完整的錯誤
PHP Warning: PHP Startup: Unable to load dynamic library ‘pdo_mysql’ (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
sudo apt-get install php-common php-mysql php-cli
如果出現php版本跑掉的狀況,不要擔心
sudo update-alternatives — config php
確認現在php支援databsae的相容性
php artisan tinker
DB::availableDrivers()
只想要讓某個 function 可以執行長時間的任務(ex:上傳檔案)
在 function 裡面加上 ini_set('mac_excution_time','600')
,其中「600」的單位是秒數。
▶︎ 如果這篇文章有幫助到你1. 可以點擊下方「Follow」來追蹤我~
2. 可以對文章拍手讓我知道 👏🏻你們的追蹤與鼓勵是我繼續寫作的動力 🙏🏼▶︎ 如果你對工程師的職涯感到迷茫1. 也許我在iT邦幫忙發表的系列文可以給你不一樣的觀點 💡
2. 也歡迎您到書局選購支持,透過豐富的案例來重新檢視自己的職涯