Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx cannot start; please check your nginx.conf [1: sudo: nginx: command not found ]. #1038

Closed
neilgee opened this issue Feb 17, 2021 · 5 comments

Comments

@neilgee
Copy link

neilgee commented Feb 17, 2021

I upgraded from macos Catalina to Big Sur and had a number of issues, so I removed everything and reinstalled homebrew, php and mariadb - then went to install Valet.

Expected behavior

nginx should install ok

Current behavior

I get an error:

Installing nginx configuration...
Installing nginx directory...
Updating PHP configuration...
Restarting php@7.4...
Updating Dnsmasq configuration...
Restarting dnsmasq...
Valet is configured to serve for TLD [.test]

In Nginx.php line 121:

  Nginx cannot start; please check your nginx.conf [1: sudo: nginx: command not found
  ].

Brew services list:

 ~/Sites ▓▒░ brew services list                                                                   ░▒▓ ✔  10:25:29
Name         Status  User  Plist
httpd        stopped
mariadb@10.3 started neilg /Users/neilg/Library/LaunchAgents/homebrew.mxcl.mariadb@10.3.plist
php@7.4      unknown root  /Library/LaunchDaemons/homebrew.mxcl.php@7.4.plist

Interestingly it says httpd

Output of these steps

Diagnosis

sw_vers
ProductName:	macOS
ProductVersion:	11.2.1
BuildVersion:	20D74
valet --version
Laravel Valet 2.13.19
cat ~/.config/valet/config.json
{
    "tld": "test",
    "paths": [
        "/Users/neilg/Sites"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "squizlabs/php_codesniffer": "*",
        "laravel/valet": "^2.13",
        "laravel/installer": "^2.0"
    }
}
composer global diagnose
Changed current directory to /Users/neilg/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
require.squizlabs/php_codesniffer : unbound version constraints (*) should be avoided
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.0.9
PHP version: 7.4.15
PHP binary path: /usr/local/Cellar/php@7.4/7.4.15/bin/php
OpenSSL version: OpenSSL 1.1.1i  8 Dec 2020
cURL version: 7.75.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1i
zip: extension present, unzip present
composer global outdated
Changed current directory to /Users/neilg/.composer
guzzlehttp/guzzle  6.5.5   ~ 7.2.0  Guzzle is a PHP HTTP client library
laravel/installer  v2.3.0  ~ v4.1.1 Laravel application installer.
symfony/console    v4.4.19 ~ v5.2.3 Eases the creation of beautiful and testable command line interfaces
symfony/filesystem v4.4.19 ~ v5.2.3 Provides basic utilities for the filesystem
symfony/process    v4.4.19 ~ v5.2.3 Executes commands in sub-processes
ls -al /etc/sudoers.d/
total 16
drwxr-xr-x    4 root  wheel   128 14 Feb 06:59 .
drwxr-xr-x  119 root  wheel  3808 18 Feb 10:14 ..
-rw-r--r--    1 root  wheel    80 26 Oct  2019 brew
-rw-r--r--    1 root  wheel    83 26 Oct  2019 valet
brew config
HOMEBREW_VERSION: 3.0.1
ORIGIN: https://github.com/Homebrew/brew
HEAD: c951be8d3c7b339c7e759b7c40aec859e09a70a5
Last commit: 7 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 703451fe242d959d029d867909ffd92f0d522ffd
Core tap last commit: 73 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
CPU: quad-core 64-bit skylake
Clang: 12.0 build 1200
Git: 2.24.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.2.1-x86_64
CLT: 12.4.0.0.1.1610135815
Xcode: 12.4
brew services list
Name         Status  User  Plist
httpd        stopped       
mariadb@10.3 started neilg /Users/neilg/Library/LaunchAgents/homebrew.mxcl.mariadb@10.3.plist
php@7.4      unknown root  /Library/LaunchDaemons/homebrew.mxcl.php@7.4.plist
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.84
nginx 1.19.7
openssl@1.1 1.1.1i
php@7.2 7.2.34_1 7.2.28
php@7.3 7.3.15 7.3.27
php@7.4 7.4.15
brew outdated

brew tap
homebrew/core
homebrew/services
shivammathur/php
php -v
PHP 7.4.15 (cli) (built: Feb 18 2021 09:58:40) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
which -a php
/usr/local/opt/php@7.4/bin/php
/usr/local/bin/php
/usr/bin/php
/usr/local/bin/php
/usr/bin/php
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/error_log.ini,
/usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
nginx -v
sudo: nginx: command not found
curl --version
curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 7.75.0
Age => 8
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => Yes
GSSAPI => Yes
KERBEROS5 => Yes
UNIX_SOCKETS => Yes
PSL => No
HTTPS_PROXY => Yes
MULTI_SSL => Yes
BROTLI => Yes
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin20.2.0
SSL Version => (SecureTransport) OpenSSL/1.1.1i
ZLib Version => 1.2.11
libSSH Version => libssh2/1.9.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value

~/.composer/vendor/laravel/valet/bin/ngrok version
ngrok version 2.3.35
ls -al ~/.ngrok2
ls: /Users/neilg/.ngrok2: No such file or directory
brew info nginx
nginx: stable 1.19.7 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.7 (1.2MB)
  Built from source
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1, pcre
==> Options
--HEAD
	Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Analytics
install: 33,676 (30 days), 120,632 (90 days), 453,177 (365 days)
install-on-request: 33,621 (30 days), 120,131 (90 days), 444,731 (365 days)
build-error: 0 (30 days)

brew info php
php: stable 8.0.2 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/php.rb
License: PHP-3.01
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl, freetds, gd, gettext, glib, gmp, icu4c, krb5, libffi, libpq, libsodium, libzip, oniguruma, openldap, openssl@1.1, pcre2, sqlite, tidy-html5, unixodbc
==> Options
--HEAD
	Install HEAD version
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/8.0/

To have launchd start php now and restart at login:
brew services start php
Or, if you don't want/need a background service you can just run:
php-fpm
==> Analytics
install: 51,047 (30 days), 161,159 (90 days), 624,134 (365 days)
install-on-request: 50,128 (30 days), 157,865 (90 days), 602,554 (365 days)
build-error: 0 (30 days)

brew info openssl
openssl@1.1: stable 1.1.1i (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@1.1/1.1.1i (8,067 files, 18.5MB)
  Poured from bottle on 2021-02-18 at 09:46:03
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Analytics
install: 679,668 (30 days), 2,208,423 (90 days), 8,264,350 (365 days)
install-on-request: 102,881 (30 days), 348,401 (90 days), 1,197,879 (365 days)
build-error: 0 (30 days)

openssl version -a
LibreSSL 2.8.3
built on: date not available
platform: information not available
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:GOST2012256-GOST89-GOST89:DHE-RSA-CAMELLIA256-SHA256:DHE-RSA-CAMELLIA256-SHA:GOST2001-GOST89-GOST89:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:CAMELLIA256-SHA256:CAMELLIA256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:CAMELLIA128-SHA256:CAMELLIA128-SHA:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:RC4-MD5:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:DES-CBC3-SHA
sudo nginx -t
sudo: nginx: command not found
which -a php-fpm
/usr/local/sbin/php-fpm
/usr/sbin/php-fpm
/usr/local/opt/php/sbin/php-fpm -v
sudo: /usr/local/opt/php/sbin/php-fpm: command not found
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/7.4/php-fpm.conf --test
sudo: /usr/local/opt/php/sbin/php-fpm: command not found
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--    1 neilg  staff   581 17 Feb 22:08 homebrew.mxcl.mailhog.plist
-rw-r--r--    1 neilg  staff   551 18 Feb 10:25 homebrew.mxcl.mariadb@10.3.plist
-rw-r--r--    1 neilg  staff   628 17 Feb 22:08 homebrew.mxcl.php.plist
-rw-r--r--    1 neilg  staff   636 17 Feb 22:08 homebrew.mxcl.php@7.3.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   628 18 Feb 09:10 homebrew.mxcl.php.plist
-rw-r--r--   1 root  admin   636 17 Feb 22:23 homebrew.mxcl.php@7.2.plist
-rw-r--r--   1 root  admin   636 18 Feb 09:16 homebrew.mxcl.php@7.3.plist
-rw-r--r--   1 root  admin   636 18 Feb 10:26 homebrew.mxcl.php@7.4.plist
ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22  1 Jan  2020 /etc/resolv.conf -> ../var/run/resolv.conf
cat /etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 192.168.1.1
nameserver 0.0.0.0
@drbyte
Copy link
Contributor

drbyte commented Feb 18, 2021

Several observations:

  1. You should remove the outdated laravel installer from your global composer by running:
composer global remove laravel/installer

If you still want it, re-install it again afterward using composer global require laravel/installer (AFTER first removing it, because you have outdated dependencies installed.)

  1. You have some valet services set up in homebrew to compete against each other by running some as root and some as non-root.
    Do the following to stop the non-root ones from running at boot, and then use valet use php@X.Y when you want to switch:
brew services stop php
brew services stop php@7.3

When Valet is being used to manage PHP, Valet will run those services as root (using sudo), so anytime you start those services without sudo you set yourself up to compete against valet.

  1. According to brew info nginx your nginx appears to have been compiled manually from source. Not sure why you did that. Seems the install/compile failed, which is the root cause of your present issue.

Try: brew remove nginx --force
Then valet install so it can re-install it cleanly.

@neilgee
Copy link
Author

neilgee commented Feb 18, 2021

Thanks @drbyte , that has nginx now configured by Valet ( I must have had a manual older version from wayback ).

One other issue arose though - dnsmasq is not running in brew services list eventhough valet install says it has restarted it

~/Sites ▓▒░ valet use php@7.4 --force                                                        ░▒▓ ✔  3s  12:48:16
Unlinking current version: php@7.4
Linking new version: php@7.4
Updating PHP configuration...
Restarting php@7.4...
Restarting nginx...
Valet is now using php@7.4.

Note that you might need to run composer global update if your PHP version change affects the dependencies of global packages required by Composer.
 ~/Sites ▓▒░ valet install                                                                   ░▒▓ ✔  23s  12:48:49
Stopping nginx...
Installing nginx configuration...
Installing nginx directory...
Updating PHP configuration...
Restarting php@7.4...
Updating Dnsmasq configuration...
Restarting dnsmasq...
Valet is configured to serve for TLD [.test]
Restarting nginx...

Valet installed successfully!
 ~/Sites ▓▒░ brew services list                                                              ░▒▓ ✔  23s  12:49:28
Name         Status  User  Plist
httpd        stopped
mariadb      started neilg /Users/neilg/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
mariadb@10.3 stopped
nginx        unknown root  /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php@7.4      unknown root  /Library/LaunchDaemons/homebrew.mxcl.php@7.4.plist

@drbyte
Copy link
Contributor

drbyte commented Feb 18, 2021

Does it report any errors if you run sudo brew services start dnsmasq ?

Or maybe remove it and let valet install it?

brew services remove dnsmasq
valet install

@neilgee
Copy link
Author

neilgee commented Feb 18, 2021

Had to manually remove

~/Sites ▓▒░ sudo rm -rf /usr/local/Cellar/dnsmasq/2.84

Then reinstalling valet valet install has added dnsmasq

 ~/Sites ▓▒░ valet install                                                                    ░▒▓ ✔  9s  14:37:01
Stopping nginx...
Installing nginx configuration...
Installing nginx directory...
Updating PHP configuration...
Restarting php@7.4...
Installing dnsmasq...
[dnsmasq] is not installed, installing it now via Brew... 🍻
Updating Dnsmasq configuration...
Restarting dnsmasq...
Valet is configured to serve for TLD [.test]
Restarting nginx...

Valet installed successfully!

So somehow both nginx and dnsmasq became disassociated from valet when I reinstalled all the things - but all good now, thanks for your help @drbyte

@neilgee neilgee closed this as completed Feb 18, 2021
@aimahdi
Copy link

aimahdi commented Sep 20, 2022

brew remove nginx --force

Worked perfectly for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants