laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.49k stars 691 forks source link

When using valet, sys_get_temp_dir() does return /var/tmp instead of /var/folders/7s/jq24sk81665c1j4y3v9l3vth0000gn/T #1468

Closed ahoiroman closed 5 months ago

ahoiroman commented 5 months ago

Description

When using valet's NGINX, I am getting a wrong temp directory (/var/tmp) instead of /var/folders/7s/jq24sk81665c1j4y3v9l3vth0000gn/T.

If I use php-cli/tinker to invoke a class, the correct temp directory is returned.

Even if I send a HTTP request to the built-in webserver laravel provides, the path /var/folders/7s/jq24sk81665c1j4y3v9l3vth0000gn/T is returned.

Steps To Reproduce

public function __invoke()
{
    ray(sys_get_temp_dir(), getenv())->label('invoke');
    ray()->phpinfo();
}

Add this to an API-endpoint and call it via valet/nginx or invoke it directly using tinker(well).

Diagnosis

sw_vers
ProductName:       macOS
ProductVersion:     14.2.1
BuildVersion:       23C71
valet --version
Laravel Valet 4.5.0
cat ~/.config/valet/config.json
{
    "tld": "test",
    "loopback": "127.0.0.1",
    "paths": [
        "/Users/ahoi/.config/valet/Sites",
        "/Users/ahoi/Entwicklung/Laravel"
    ],
    "share-tool": "expose"
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^4.5",
        "beyondcode/expose": "^2.6"
    }
}
composer global diagnose
Changed current directory to /Users/ahoi/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK git version 2.39.3
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: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: OK
Composer version: 2.6.6
PHP version: 8.3.2
PHP binary path: /opt/homebrew/Cellar/php/8.3.2/bin/php
OpenSSL version: OpenSSL 3.2.0 23 Nov 2023
cURL version: 8.5.0 libz 1.2.12 ssl (SecureTransport) OpenSSL/3.2.0
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/ahoi/.composer
Legend:
! patch or minor release available - update recommended
~ major release available - update possible

Direct dependencies required in composer.json:
laravel/valet             v4.5.0   ! v4.6.1   A more enjoyable local develop...

Transitive dependencies not required in composer.json:
illuminate/collections    v10.37.3 ! v10.41.0 The Illuminate Collections pac...
illuminate/conditionable  v10.37.3 ! v10.41.0 The Illuminate Conditionable p...
illuminate/container      v10.37.3 ! v10.41.0 The Illuminate Container package.
illuminate/contracts      v10.37.3 ! v10.41.0 The Illuminate Contracts package.
illuminate/macroable      v10.37.3 ! v10.41.0 The Illuminate Macroable package.
mnapoli/silly             1.8.3    ! 1.9.0    Silly CLI micro-framework base...
symfony/console           v6.4.1   ~ v7.0.2   Eases the creation of beautifu...
symfony/event-dispatcher  v6.4.0   ~ v7.0.2   Provides tools that allow your...
symfony/process           v6.4.0   ~ v7.0.2   Executes commands in sub-proce...
symfony/service-contracts v3.4.0   ! v3.4.1   Generic abstractions related t...
symfony/string            v7.0.0   ! v7.0.2   Provides an object-oriented AP...
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Dec 15 15:43 .
drwxr-xr-x  80 root  wheel  2560 Jan 19 10:13 ..
brew config
HOMEBREW_VERSION: 4.2.4
ORIGIN: https://github.com/Homebrew/brew
HEAD: 1c612baa096c69f2fcb221c74e6f5b9979efdcee
Last commit: 4 days ago
Core tap JSON: 19 Jan 09:19 UTC
Core cask tap JSON: 19 Jan 09:19 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 14
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: 14-core 64-bit arm_palma
Clang: 15.0.0 build 1500
Git: 2.39.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.2.1-arm64
CLT: 15.1.0.0.1.1700200546
Xcode: N/A
Rosetta 2: false
brew services list
Warning: running through sudo, using user/* instead of gui/* domain!
Hide this warning by setting HOMEBREW_SERVICES_NO_DOMAIN_WARNING.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Name    Status User File
dnsmasq none            root 
mariadb started         ahoi ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
nginx   none            root 
php     none            root 
redis   started         ahoi ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.89
mariadb 11.2.2
nginx 1.25.3
php 8.3.2 8.3.0 8.3.1
brew outdated

brew tap
homebrew/services
oven-sh/bun
php -v
PHP 8.3.2 (cli) (built: Jan 16 2024 13:46:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.2, Copyright (c), by Zend Technologies
which -a php
/opt/homebrew/bin/php
php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.3
Loaded Configuration File:         /opt/homebrew/etc/php/8.3/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.3/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/8.3/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.3/conf.d/ext-opcache.ini,
/opt/homebrew/etc/php/8.3/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.25.3
curl --version
curl 8.4.0 (x86_64-apple-darwin23.0) libcurl/8.4.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.55.1
Release-Date: 2023-10-11
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 8.5.0
Age => 10
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => No
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
ALTSVC => Yes
HTTP3 => No
UNICODE => No
ZSTD => Yes
HSTS => Yes
GSASL => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => aarch64-apple-darwin23.0.0
SSL Version => (SecureTransport) OpenSSL/3.2.0
ZLib Version => 1.2.12
libSSH Version => libssh2/1.11.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value
/opt/homebrew/bin/ngrok version
sudo: /opt/homebrew/bin/ngrok: command not found
ls -al ~/.ngrok2
ls: /Users/ahoi/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.25.3 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.25.3 (26 files, 2.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-12-14 at 14:21:35
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/n/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@3, pcre2
==> Options
--HEAD
    Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www

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

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To 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:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;
==> Analytics
install: 9,843 (30 days), 35,804 (90 days), 155,051 (365 days)
install-on-request: 9,803 (30 days), 35,685 (90 days), 154,745 (365 days)
build-error: 17 (30 days)
brew info php
==> php: stable 8.3.2 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/opt/homebrew/Cellar/php/8.3.0 (520 files, 88.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.3.1 (520 files, 88.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.3.2 (523 files, 88.6MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-01-19 at 09:47:52
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/php.rb
License: PHP-3.01
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl, freetds, gd, gettext, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, openldap, openssl@3, 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 /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

    
        SetHandler application/x-httpd-php
    

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

The php.ini and php-fpm.ini file can be found in:
    /opt/homebrew/etc/php/8.3/

To 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:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
==> Analytics
install: 56,564 (30 days), 178,001 (90 days), 559,214 (365 days)
install-on-request: 52,781 (30 days), 166,442 (90 days), 520,770 (365 days)
build-error: 110 (30 days)
brew info openssl
==> openssl@3: stable 3.2.0 (bottled)
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@3/3.2.0_1 (6,805 files, 31.9MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-12-14 at 14:13:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openssl@3.rb
License: Apache-2.0
==> Dependencies
Required: ca-certificates
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@3/certs

and run
  /opt/homebrew/opt/openssl@3/bin/c_rehash
==> Analytics
install: 344,683 (30 days), 1,275,397 (90 days), 3,365,176 (365 days)
install-on-request: 39,684 (30 days), 178,512 (90 days), 541,534 (365 days)
build-error: 4,921 (30 days)
openssl version -a
OpenSSL 3.2.0 23 Nov 2023 (Library: OpenSSL 3.2.0 23 Nov 2023)
built on: Thu Nov 23 13:20:19 2023 UTC
platform: darwin64-arm64-cc
options:  bn(64,64)
compiler: clang -fPIC -arch arm64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
OPENSSLDIR: "/opt/homebrew/etc/openssl@3"
ENGINESDIR: "/opt/homebrew/Cellar/openssl@3/3.2.0_1/lib/engines-3"
MODULESDIR: "/opt/homebrew/Cellar/openssl@3/3.2.0_1/lib/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_armcap=0x87d
openssl ciphers
TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:RSA-PSK-AES256-GCM-SHA384:DHE-PSK-AES256-GCM-SHA384:RSA-PSK-CHACHA20-POLY1305:DHE-PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:AES256-GCM-SHA384:PSK-AES256-GCM-SHA384:PSK-CHACHA20-POLY1305:RSA-PSK-AES128-GCM-SHA256:DHE-PSK-AES128-GCM-SHA256:AES128-GCM-SHA256:PSK-AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:ECDHE-PSK-AES256-CBC-SHA384:ECDHE-PSK-AES256-CBC-SHA:SRP-RSA-AES-256-CBC-SHA:SRP-AES-256-CBC-SHA:RSA-PSK-AES256-CBC-SHA384:DHE-PSK-AES256-CBC-SHA384:RSA-PSK-AES256-CBC-SHA:DHE-PSK-AES256-CBC-SHA:AES256-SHA:PSK-AES256-CBC-SHA384:PSK-AES256-CBC-SHA:ECDHE-PSK-AES128-CBC-SHA256:ECDHE-PSK-AES128-CBC-SHA:SRP-RSA-AES-128-CBC-SHA:SRP-AES-128-CBC-SHA:RSA-PSK-AES128-CBC-SHA256:DHE-PSK-AES128-CBC-SHA256:RSA-PSK-AES128-CBC-SHA:DHE-PSK-AES128-CBC-SHA:AES128-SHA:PSK-AES128-CBC-SHA256:PSK-AES128-CBC-SHA
sudo nginx -t
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
which -a php-fpm
/opt/homebrew/sbin/php-fpm
/opt/homebrew/opt/php/sbin/php-fpm -v
PHP 8.3.2 (fpm-fcgi) (built: Jan 16 2024 13:46:41)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.2, Copyright (c), by Zend Technologies
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.3/php-fpm.conf --test
[19-Jan-2024 10:19:47] NOTICE: configuration file /opt/homebrew/etc/php/8.3/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--   1 ahoi  staff   730 Dec 18 23:37 homebrew.mxcl.mariadb.plist
-rw-r--r--   1 ahoi  staff   880 Dec 20 16:50 homebrew.mxcl.redis.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   797 Jan 19 09:49 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   685 Jan 19 09:50 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   781 Jan 19 09:49 homebrew.mxcl.php.plist
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Dec 15 15:43 /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.
#
search fritz.box
nameserver 192.168.178.1
nameserver fd00::9a9b:cbff:fe00:5bea
nameserver 2003:a:42f:2d00:9a9b:cbff:fe00:5bea
ifconfig lo0
lo0: flags=8049 mtu 16384
    options=1203
    inet 127.0.0.1 netmask 0xff000000
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    nd6 options=201
sh -c 'echo "------\n/opt/homebrew/etc/nginx/valet/valet.conf\n---\n"; cat /opt/homebrew/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"'
------
/opt/homebrew/etc/nginx/valet/valet.conf
---

3:    #listen VALET_LOOPBACK:80; # valet loopback

------
sh -c 'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done'
------
~/.config/valet/dnsmasq.d/tld-test.conf
---

address=/.test/127.0.0.1
listen-address=127.0.0.1

------
sh -c 'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done'
------
~/.config/valet/nginx/web.example-2.test
---

5:    #listen 127.0.0.1:80; # valet loopback
50:    #listen 127.0.0.1:60; # valet loopback

------

------
~/.config/valet/nginx/web.example-1.test
---

5:    #listen 127.0.0.1:80; # valet loopback
50:    #listen 127.0.0.1:60; # valet loopback

------
drbyte commented 5 months ago

Appears to be a difference between PHP's CLI and FPM implementations. Not sure if it's indirectly impacted by Nginx.

While you can override and specify your own directory via sys_temp_dir in php.ini, there doesn't appear to be an option to make it passthru the MacOS actual directory name.

There's a comment in the php docs site that suggests Linux (which MacOS takes from) has a private mode where it doesn't passthrough the actual directory path. I imagine that Apple's escalation of insulating us from access to the underlying OS probably is blocking that.

driesvints commented 5 months ago

@drbyte should we add something to the docs about this?

drbyte commented 5 months ago

It kinda depends on why sys_get_temp_dir() is even being called. It is certainly more preferable for temp files to be created in a directory that's automatically cleaned up by the OS, rather than relying on PHP to do garbage-collection.

@ahoiroman Can you explain what you were trying to do in your app that exposed this? What is this "preventing" you from doing? Was it because you were calling the function directly? Or was something else calling it behind-the-scenes?

driesvints commented 5 months ago

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.