Search code examples
phplaravel-5laravel-5.3laravel-valet

Laravel Valet not working- as if it's missing a web server


I followed the instructions to install Valet and it worked fine the first 2 days with no problems at all. Then out of nowhere it stopped working and only seemed to get worse with time. First there were 404 errors on all laravel projects beyond their homepage and eventually the sites stopped working altogether as if there isn't a web server running.

Here are some details about my environment:

  • Running macOS Sierra, PHP 7.1, MariaDB

  • Composer works fine and is in path

  • Valet 2.0.3 (latest at the time of writing this)

  • Changed MAMP to default ports to free up ports 80 and 3306 before installing and running Valet the first time

  • Pinging something.dev returns 127.0.0.1 as it should

  • Running something.dev in browser does not work D if there is no web server running

After hours of searching, fiddling, uninstalling and reinstalling everything I am now at a very bizarre point. If MAMP is running on ports 80 and 3306 Valet will serve something.dev although I still get 404 beyond the homepage. How can this be? Isn't MAMP supposed to be on other ports to free up 80 and 3306 for Valet or not running at all? The other strange thing is that something.dev will return my webroot which is Valet parked and not the site something.dev which is under the webroot. I have searched high and low and I am at a loss as to how I can get things running the way they should be


Solution

  • Follow this steps to solve it: You have to troubleshoot your nginx installation/configuration, as this is the server behind Valet.

    I've got through "valet not serving" issue with the first restart that came after valet installation.

    1st check you're using the latest version

    $ brew update $ brew upgrade (if you're using brew)

    2nd Test configuration of nginx, there could be some permission issues:

    $ nginx -t - this return the "error" paths that can't be read. For eg. will return the path to your valet error.log or conf file. eg:

    2017/02/04 16:32:31 [emerg] 17285#0: open() "/Users/username/.valet/Log/nginx-error.log" failed (13: Permission denied)

    Checking the file: $ ls -l ~/.valet/Log/nginx-error.log

    -rw-r--r-- 1 root staff 7842 Feb 4 15:54 ~/.valet/Log/nginx-error.log

    The reason why my nginx wasn't started to serve all the valet sites was that in my home directory the error log was owned by the root. Change permissions as fitted for this file and maybe others, using chown command (replace with actual username):

    $ sudo chown username:staff ~/.valet/Log/nginx-error.log

    after changing permissions, restart nginx: $ sudo nginx -s stop && sudo nginx

    If the command will return nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx.pid", thats because nginx is not running and have no PID, just start nginx again using: $ sudo nginx

    Now test your valet sites. (while MAMP is stopped) Next. Decide upon ports and configure Valet and MAMP to work without conflicts.

    Hope this helped.

    Note: The user:group that must own your error log file can be found in nginx.conf at the user directive.