各位大大好,本人是剛學幾個月的程式小小小菜鳥,第一次發文,如有不周,請見諒,謝謝
小弟最近剛做了一份使用MVC簡易購物網站,有使用Composer的psr-4自動載入(Composer只有使用這個)
但是最近在上傳bluehost的cpanel虛擬主機時出現抓不到Class的問題(Uncaught Class)(在本地載入都正常)
在cpanel,我只有把檔案丟上去,再設定資料庫都參數而已
由於第一次使用虛擬和雲端主機,對這塊還不太熟
找了很多資料,但小弟對英文文章比較苦手,沒有找到
所以想說試試看heroku,有沒有機會成功
也有使用在上傳時.gitignore也有忽略vender
但也是與cpanel有同樣的問題,Uncaught Class
cpanel和heroku我都有測試如果沒有使用autoload都是可以有畫面
所以有幾個問題想問各位大大
1.cpanel原本就有支援Composer嗎?如果沒有是要使用SSH連到cpanel載嗎?
2.正常使用autoload會有這類問題嗎?如果不會那與composer.json問題比較有關係嗎?
這邊附上heroku的log,謝謝
2021-05-08T07:09:04.050374+00:00 app[web.1]: [08-May-2021 07:09:04 UTC] PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/app/.env]. in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
2021-05-08T07:09:04.050394+00:00 app[web.1]: Stack trace:
2021-05-08T07:09:04.050563+00:00 app[web.1]: #0 /app/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
2021-05-08T07:09:04.053945+00:00 app[web.1]: #1 /app/config.php(4): Dotenv\Dotenv->load()
2021-05-08T07:09:04.053966+00:00 heroku[router]: at=info method=GET path="/" host=ecom-cart-20210508.herokuapp.com request_id=2e241588-767e-4194-b16a-04faa14e2701 fwd="111.83.91.197" dyno=web.1 connect=0ms service=50ms status=500 bytes=279 protocol=https
2021-05-08T07:09:04.054059+00:00 app[web.1]: #2 /app/Bootstrap.php(5): require('...')
2021-05-08T07:09:04.054187+00:00 app[web.1]: #3 /app/public/index.php(6): require_once('...')
2021-05-08T07:09:04.054229+00:00 app[web.1]: #4 {main}
2021-05-08T07:09:04.054426+00:00 app[web.1]: thrown in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
2021-05-08T07:09:04.055955+00:00 app[web.1]: 10.69.225.154 - - [08/May/2021:07:09:04 +0000] "GET / HTTP/1.1" 500 - "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
2021-05-08T07:14:37.000000+00:00 app[api]: Build started by user rray12tw346@gmail.com
2021-05-08T07:14:47.146623+00:00 heroku[web.1]: Restarting
2021-05-08T07:14:47.151252+00:00 heroku[web.1]: State changed from up to starting
2021-05-08T07:14:46.651601+00:00 app[api]: Release v11 created by user rray12tw346@gmail.com
2021-05-08T07:14:46.651601+00:00 app[api]: Deploy b65e7961 by user rray12tw346@gmail.com
2021-05-08T07:14:46.000000+00:00 app[api]: Build succeeded
2021-05-08T07:14:48.365959+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-05-08T07:14:48.629076+00:00 heroku[web.1]: Process exited with status 143
2021-05-08T07:14:49.153071+00:00 heroku[web.1]: Starting process with command `vendor/bin/heroku-php-apache2 public/`
2021-05-08T07:14:48.454370+00:00 app[web.1]: SIGTERM received, attempting graceful shutdown...
2021-05-08T07:14:48.455305+00:00 app[web.1]: Stopping php-fpm...
2021-05-08T07:14:48.457881+00:00 app[web.1]: Stopping httpd gracefully...
2021-05-08T07:14:48.458222+00:00 app[web.1]: Stopping httpd...
2021-05-08T07:14:48.552978+00:00 app[web.1]: Shutdown complete.
2021-05-08T07:14:54.710972+00:00 app[web.1]: DOCUMENT_ROOT changed to 'public/'
2021-05-08T07:14:54.861284+00:00 app[web.1]: Detected 536870912 Bytes of RAM
2021-05-08T07:14:54.939084+00:00 app[web.1]: PHP memory_limit is 128M Bytes
2021-05-08T07:14:54.959685+00:00 app[web.1]: Starting php-fpm with 4 workers...
2021-05-08T07:14:55.244521+00:00 app[web.1]: Starting httpd...
2021-05-08T07:14:56.083250+00:00 heroku[web.1]: State changed from starting to up
2021-05-08T07:14:57.127566+00:00 heroku[router]: at=info method=GET path="/" host=ecom-cart-20210508.herokuapp.com request_id=b12ba00c-4494-4deb-998f-ea77df092034 fwd="111.83.91.197" dyno=web.1 connect=0ms service=29ms status=500 bytes=279 protocol=https
2021-05-08T07:14:57.129200+00:00 app[web.1]: [08-May-2021 07:14:57 UTC] PHP Fatal error: Uncaught Error: Class "App\Controllers\PagesController" not found in /app/core/Router.php:58
2021-05-08T07:14:57.129294+00:00 app[web.1]: Stack trace:
2021-05-08T07:14:57.129484+00:00 app[web.1]: #0 /app/core/Router.php(49): Core\Router->callAction()
2021-05-08T07:14:57.129661+00:00 app[web.1]: #1 /app/app/routes.php(30): Core\Router->direct()
2021-05-08T07:14:57.129824+00:00 app[web.1]: #2 /app/public/index.php(20): require('...')
2021-05-08T07:14:57.129882+00:00 app[web.1]: #3 {main}
2021-05-08T07:14:57.129989+00:00 app[web.1]: thrown in /app/core/Router.php on line 58
2021-05-08T07:14:57.130433+00:00 app[web.1]: 10.69.85.146 - - [08/May/2021:07:14:57 +0000] "GET / HTTP/1.1" 500 - "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
你是要在Server上執行Composer指令嗎?
其實這個你應該要問你的主機商,
CPanel只是一個介面而已(另一個我沒用過),
關鍵還是系統的PHP版本跟其他的,
(不過如果是使用CPanel, 有些東西是看不到的)
CPanel是可以改PHP版本的,
有些CPanel在改PHP版本的時候會讓你自己選要載入哪些,
(就是php.ini中的extension)
你可以先跟主機商聯絡看看.
如果你想要能夠完全控制,
或許可以考慮租可以SSH連進去處理的主機.
(但是那種通常會比較貴一些)