Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel valet not working

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!

like image 425
metylbk Avatar asked May 10 '16 10:05

metylbk


2 Answers

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.

like image 99
rjb Avatar answered Oct 10 '22 10:10

rjb


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

like image 39
Ben Swinburne Avatar answered Oct 10 '22 11:10

Ben Swinburne