问题
OK, so I'm running a Laravel installation using MAMP (mac) which was cloned using git via Bit Bucket. The site loads but all the CSS and JS files are broken. If you view source you can see the markup and the URL's like the image below.
However, if you click on any of the URL's then you get a chrome browser error saying: This site can't be reached, the connection was reset etc".
My MAMP installation URL is http://localhost:8000/login and here's the interesting thing, if I change the full path of the URL from:
BAD: http://nestdb.local/css/chosen.min.css (i.e. doesn't load) which is within the Laravel installation
but if I change the path to this then it does load:
GOOD: http://localhost:8000/css/chosen.min.css
So clearly there is a path problem, but I am not sure how to solve it. This is my .env file:
APP_ENV=localwg
APP_KEY=base64xXXXXXXXXX/hSpKzqI8= (remove this for security)
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://nestdb.local
APP_TIMEZONE = Asia/Hong_Kong
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=nestlaravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
MY_HOST=nestdb.local
PRODUCTION_SERVER=1
HOST_ROOT=http://nestdb.local/
And my etc file is like this:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 nest.test
127.0.0.1 nestdb.test
127.0.0.1 nestdb.local
127.0.0.1 test.test
I changed the APP_URL in the .env file to APP_URL=http://nestdb.local:8000
but no joy either.
Does anyone why or what I should be adjusting to get this installation to work?
Could it also be a MAMP Virtual Hosts Issue?
回答1:
"nestdb.local" points to your localhost on port 80 and your MAMP is running on port 8000. The following should work fine: http://nestdb.local:8000/css/chosen.min.css
So you have to modify you laravel .env and add the port to the APP_URL:
APP_URL=http://nestdb.local:8000
回答2:
well first of all I would give you the advice to not use mamp, xampp or lamp in combination with laravel because they don't really work well with each other. Instead use Valet or if you want use Homestead. This would make your life much easier.
What I do in my Setups is working with the solution you marked as Good so I use `https://localhost:8000/....
来源:https://stackoverflow.com/questions/57944168/trying-to-fix-a-broken-a-path-for-files-in-a-laravel-installation