Laravel valet not working

2019-03-29 19:58发布

问题:

I use OSX El Capitan and PHP 7. I followed the installation guide so I install Laravel Valet version v1.1.3 successfully. I ping foo.dev or any.dev then the terminal prints

"64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.116 ms"

Everything is ok. My directory /User/mickey/Sites is added to Valet's paths. I created a Laravel 5.2 project named blog, then run the project with php artisan serve ok but when i accessed url blog.dev on the browser, the browser said

This site can’t be reached, blog.dev refused to connect. ERR_CONNECTION_REFUSED.

I don't know what is the problem with my installation. Thanks in advance!

回答1:

You needn't run php artisan serve as Valet runs Caddy in the background.

Here're a few troubleshooting points.

  • Ensure that you don't have Apache (or anything else running on port 80)

    sudo apachectl stop

  • Ensure that Valet is running

    valet start

  • Ensure that PHP was installed with FPM

    brew uninstall homebrew/php/php70

    brew install homebrew/php/php70 --with-fpm



回答2:

After trying everything I found on the internet (including this one which worth to try) for me the solution was to change valet's domain to test.

valet domain test

So I have no idea if the mentioned reinstall was needed or not but I know that I could ping or even curl my .dev sites but could not open them in any browser (Chrome nor Safari). Then I tried to set domain to .app but that did not work either. In the browsers I was redirected all the time to https even after running valet unsecure.

But then changed domain to .test and suddenly it started to work. I'm not sure what is the real issue here and why is this but I'm okay with it since it works again.

I've also read that .dev is not good any more because it's an official TLD and so reserved. (wikipedia)



回答3:

Hopefully I can now solve this one for you. The Self Control fix worked as a temp fix for me so you may be in luck as I've found a permanent solution for me!

I once had a httpd setup which I followed a guide to install. This came with some baggage as the guide got you to forward 127.0.0.1 port 80 to port 8080.

Try this anyway Go > Go to folder...

/Library/LaunchDaemons/

The file in my case was called co.echo.httpdfwd.plist which I just needed to delete and then restart my Mac. See my question for more info Laravel Valet not working. 127.0.0.1 Connection Refused.

Let me know how you get on!



回答4:

The problem was solved by starting self-control app. I don't know the reason but you can try to download and start this app to resolve this problem.



回答5:

I had nearly the same issue of Laravel Valet not working after installing via Homebrew on macOS 10.13 "High Sierra".

The problem I encountered was that DNSMasq would respond to queries, but Nginx would not handle the responses on port 80.

Attempting to connect to the site in a Terminal session would result in the following error:

$ curl -IL http://example.test/
curl: (7) Failed to connect to example.test port 80: Connection refused

I had recently upgraded from macOS 10.2 "Sierra" to 10.13 "High Sierra", so I suspected my Homebrew environment and configuration that was brought by the Migration Assistant could be at fault.

While following the troubleshooting advice here and elsewhere, what eventually solved my problem was to completely uninstall and remove Valet along with its dependencies (PHP, Nginx, DNSMasq, etc):

$ rm -rf ~/.valet
$ brew unlink nginx && brew remove nginx
$ brew unlink php56 && brew remove php56 && brew uninstall --ignore-dependencies php56
$ brew unlink php72 && brew remove php72
$ brew unlink dnsmasq && brew remove dnsmasq

With a clean slate, I was able to successfully install Valet:

$ brew update
$ brew install homebrew/core/php
$ composer global require laravel/valet
$ valet install

I then setup a new development domain:

$ valet domain test
$ valet park ~/Sites
$ mkdir ~/Sites/example && cd "$_"
$ valet link
$ echo "Hello, world" > ~/Sites/example/index.html

With Valet installed, I verified everything was working:

$ valet --version
$ sudo nginx -t
$ ping -c 4 example.test
$ curl -IL http://example.test/
$ valet open example

After doing all of this, I had a 100% successful working Laravel Valet environment.