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

Warning: require_once(./cli/includes/require-drivers.php): Failed to open stream with custom driver for Symfony project #1436

Closed
lolsokje opened this issue Aug 17, 2023 · 7 comments
Assignees

Comments

@lolsokje
Copy link

Description

I've created the following custom driver in ~/.config/valet/Drivers, as I need to handle static files in a specific manner;

<?php

namespace Valet\Drivers\Custom;

use Valet\Drivers\LaravelValetDriver;

class CustomValetDriver extends LaravelValetDriver
{
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
	    return $siteName === '[project]';
    }

    public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
    {
        // TODO: implement
        if (file_exists($staticFilePath = $sitePath.'/public/'.$uri)) {
            return $staticFilePath;
        }

        return false;
    }
}

I'm extending the LaravelValetDriver as the frontControllerPath method is the same for Symfony as it is for Laravel and can thus be omitted.

The driver is picked up correctly, but gives me the following error;
image

Without the custom driver, or even when extending the base ValetDriver class, the site loads fine but assets don't work (which is why I need the custom driver in the first place).

Steps To Reproduce

  1. Create a new Symfony project with symfony new [project] --webapp
  2. Link the site with valet link
  3. Create the custom driver above

Diagnosis

sw_vers
ProductName:		macOS
ProductVersion:		13.2.1
BuildVersion:		22D68
valet --version
Laravel Valet 4.0.0
cat ~/.config/valet/config.json
{
    "tld": "test",
    "loopback": "127.0.0.1",
    "paths": [
        "/Users/alex/.config/valet/Sites"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^4.0",
        "laravel/installer": "^4.2"
    }
}
composer global diagnose
Changed current directory to /Users/alex/.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.1
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: You are not running the latest stable version, run `composer self-update` to update (2.5.4 => 2.5.8)
Composer version: 2.5.4
PHP version: 8.2.7
PHP binary path: /opt/homebrew/Cellar/php/8.2.7_1/bin/php
OpenSSL version: OpenSSL 1.1.1u  30 May 2023
cURL version: 8.1.2 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1u
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/alex/.composer
laravel/installer                  v4.3.0 Legend:
! patch or minor release available - update recommended
~ major release available - update possible

Direct dependencies required in composer.json:
~ v5.0.3 Laravel application in...
laravel/valet v4.0.0 ! v4.1.4 A more enjoyable local...
guzzlehttp/guzzle 7.5.0 ! 7.7.0 Guzzle is a PHP HTTP c...
guzzlehttp/promises 1.5.2 ~ 2.0.1 Guzzle promises library
guzzlehttp/psr7 2.4.3 ! 2.6.0 PSR-7 message implemen...
illuminate/collections v9.52.4 ~ v10.19.0 The Illuminate Collect...
illuminate/conditionable v9.52.4 ~ v10.19.0 The Illuminate Conditi...
illuminate/container v9.51.0 ~ v10.19.0 The Illuminate Contain...
illuminate/contracts v9.51.0 ~ v10.19.0 The Illuminate Contrac...
illuminate/macroable v9.52.4 ~ v10.19.0 The Illuminate Macroab...
mnapoli/silly 1.8.1 ! 1.8.3 Silly CLI micro-framew...
psr/http-client 1.0.1 ! 1.0.2 Common interface for H...
psr/http-factory 1.0.1 ! 1.0.2 Common interfaces for ...
psr/http-message 1.0.1 ~ 2.0 Common interface for H...
symfony/console v6.2.5 ! v6.3.2 Eases the creation of ...
symfony/deprecation-contracts v3.2.0 ! v3.3.0 A generic function and...
symfony/event-dispatcher v6.2.5 ! v6.3.2 Provides tools that al...
symfony/event-dispatcher-contracts v3.2.0 ! v3.3.0 Generic abstractions r...
symfony/process v6.2.5 ! v6.3.2 Executes commands in s...
symfony/service-contracts v3.2.0 ! v3.3.0 Generic abstractions r...
symfony/string v6.2.5 ! v6.3.2 Provides an object-ori...

Transitive dependencies not required in composer.json:

ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Feb  9  2023 .
drwxr-xr-x  80 root  wheel  2560 Jul 12 10:18 ..
brew config
HOMEBREW_VERSION: 4.1.5
ORIGIN: https://github.com/Homebrew/brew
HEAD: b8b46501e4caa1cad75b30627c123127ab09a6a7
Last commit: 3 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 055ae78415b61ecf1fa3de32b76b8a149855f903
Core tap last commit: 79 minutes ago
Core tap branch: master
Core tap JSON: 17 Aug 07:08 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_firestorm_icestorm
Clang: 14.0.3 build 1403
Git: 2.39.1 => /opt/homebrew/bin/git
Curl: 7.86.0 => /usr/bin/curl
macOS: 13.2.1-arm64
CLT: 14.3.0.0.1.1679647830
Xcode: N/A
Rosetta 2: false
brew services list
Name        Status User File
dnsmasq     none            root 
mailhog     none                 
nginx       none            root 
php         started         root ~/Library/LaunchAgents/homebrew.mxcl.php.plist
[email protected]     none            root 
[email protected]     none            root 
symfony-cli none
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.86
mailhog 1.0.1
nginx 1.25.1
[email protected] 1.1.1u
php 8.2.7_1
[email protected] 7.4.30
[email protected] 8.1.20_1
brew outdated
apr-util
curl
dnsmasq
freetds
freetype
git
highway
jpeg-turbo
krb5
libevent
libnghttp2
libpng
libpq
libssh2
libuv
libvterm
libzip
luajit
luv
msgpack
neovim
nginx
node
nvm
openexr
openldap
[email protected]
shivammathur/php/php
[email protected]
[email protected]
[email protected]
rtmpdump
symfony-cli/tap/symfony-cli
tree-sitter
unixodbc
webp
xz
brew tap
homebrew/cask
homebrew/core
homebrew/services
shivammathur/php
symfony-cli/tap
php -v
PHP 8.2.7 (cli) (built: Jun 17 2023 07:09:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
which -a php
/opt/homebrew/bin/php
php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2
Loaded Configuration File:         /opt/homebrew/etc/php/8.2/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/8.2/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.25.1
curl --version
curl 7.86.0 (x86_64-apple-darwin22.0) libcurl/7.86.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.47.0
Release-Date: 2022-10-26
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.1.2
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 => 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
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-darwin22.4.0
SSL Version => (SecureTransport) OpenSSL/1.1.1u
ZLib Version => 1.2.11
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/alex/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.25.2 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.25.1 (26 files, 2.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-06-17 at 18:26:29
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: 15,483 (30 days), 58,119 (90 days), 88,930 (365 days)
install-on-request: 15,454 (30 days), 58,026 (90 days), 88,800 (365 days)
build-error: 6 (30 days)

brew info php
==> php: stable 8.2.9 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/opt/homebrew/Cellar/php/8.2.7_1 (529 files, 84MB) *
  Poured from bottle on 2023-06-17 at 18:26:36
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
<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:
/opt/homebrew/etc/php/8.2/

To restart php after an upgrade:
brew services restart 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: 42,676 (30 days), 150,535 (90 days), 248,957 (365 days)
install-on-request: 39,949 (30 days), 139,747 (90 days), 230,777 (365 days)
build-error: 44 (30 days)

brew info openssl
==> openssl@3: stable 3.1.2 (bottled)
Cryptography and SSL/TLS Toolkit
https://openssl.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/[email protected]
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: 441,978 (30 days), 963,949 (90 days), 1,228,061 (365 days)
install-on-request: 44,353 (30 days), 196,290 (90 days), 267,166 (365 days)
build-error: 1,758 (30 days)

openssl version -a
LibreSSL 3.3.6
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
AEAD-CHACHA20-POLY1305-SHA256:AEAD-AES256-GCM-SHA384:AEAD-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305: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: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
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.2.7 (fpm-fcgi) (built: Jun 17 2023 07:09:29)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.2/php-fpm.conf --test
[17-Aug-2023 09:09:02] NOTICE: configuration file /opt/homebrew/etc/php/8.2/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--   1 alex  staff   781 Jan 22  2023 homebrew.mxcl.php.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   602 Aug 16 20:38 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   685 Aug 16 20:38 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   781 Aug 16 20:38 homebrew.mxcl.php.plist
-rw-r--r--   1 root  admin   789 Aug 16 20:38 [email protected]
-rw-r--r--   1 root  admin   789 Aug 16 20:38 [email protected]
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Feb  9  2023 /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 home
nameserver 2a02:f68:0:6e:6e73::1
nameserver 2a02:f68:0:cf3:6e73::2
nameserver 2a02:f68:0:cf4:6e73::3
nameserver 62.238.255.69
nameserver 212.115.192.193
nameserver 62.45.70.104
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/*
---

cat: /Users/alex/.config/valet/nginx/*: No such file or directory

------

@drbyte
Copy link
Contributor

drbyte commented Aug 17, 2023

Your post shows that you're running Valet 4.0.0.
The latest is 4.1.4, and a few PRs have been merged to handle a few glitches with custom drivers, including #1414

I suggest running composer global update laravel/valet or just composer global update to get the latest Valet updates. That will help rule out whether the problem has already been addressed.

@lolsokje
Copy link
Author

Updated to 4.1.4 but the issue persists.

@drbyte
Copy link
Contributor

drbyte commented Aug 18, 2023

You wrote:

I'm extending the LaravelValetDriver as the frontControllerPath method is the same for Symfony as it is for Laravel and can thus be omitted.

While half of that is true, extending the Symfony driver solves the problem.

The following works for me.

-use Valet\Drivers\LaravelValetDriver;
+use Valet\Drivers\Specific\SymfonyValetDriver;

-class CustomValetDriver extends LaravelValetDriver
+class CustomValetDriver extends SymfonyValetDriver

Edit: I would recommend renaming from CustomValetDriver to something more context-specific. Or use the LocalValetDriver approach mentioned below...

@drbyte
Copy link
Contributor

drbyte commented Aug 18, 2023

FURTHER ...

Since this driver is highly specific to a certain project (referring to your serves() method customizations), why not just call it LocalValetDriver and stick it directly in your project's root directory? That way Valet will look at that first.

-namespace Valet\Drivers\Custom;
+//namespace Valet\Drivers\Custom;

use Valet\Drivers\Specific\SymfonyValetDriver;

-class CustomValetDriver extends SymfonyValetDriver
+class LocalValetDriver extends SymfonyValetDriver

@drbyte
Copy link
Contributor

drbyte commented Aug 18, 2023

As for serving static assets, you might find some ideas from this post I made responding to someone else's desire for serving static files: #1430 (comment)

@lolsokje
Copy link
Author

You wrote:

I'm extending the LaravelValetDriver as the frontControllerPath method is the same for Symfony as it is for Laravel and can thus be omitted.

While half of that is true, extending the Symfony driver solves the problem.

The following works for me.

-use Valet\Drivers\LaravelValetDriver;
+use Valet\Drivers\Specific\SymfonyValetDriver;

-class CustomValetDriver extends LaravelValetDriver
+class CustomValetDriver extends SymfonyValetDriver

Edit: I would recommend renaming from CustomValetDriver to something more context-specific. Or use the LocalValetDriver approach mentioned below...

Using Valet\Drivers\Specific\SymfonyValetDriver indeed fixed the issue! I tried using Valet\Drivers\SymfonyValetDriver already but the class couldn't be found, I forgot to check what namespace the framework specific drivers have though, that's my bad. Although maybe it could be mentioned more clearly in the documentation.

The driver already has a specific name, I simply chose CustomValetDriver for anonymity sake.

FURTHER ...

Since this driver is highly specific to a certain project (referring to your serves() method customizations), why not just call it LocalValetDriver and stick it directly in your project's root directory? That way Valet will look at that first.

-namespace Valet\Drivers\Custom;
+//namespace Valet\Drivers\Custom;

use Valet\Drivers\Specific\SymfonyValetDriver;

-class CustomValetDriver extends SymfonyValetDriver
+class LocalValetDriver extends SymfonyValetDriver

Right now it's only one project using this custom driver, but in the future I'll need to re-use it for others, so I'm not using a local driver for that reason. I'll simply rewrite the serves method when necessary.

@drbyte
Copy link
Contributor

drbyte commented Aug 20, 2023

Right now it's only one project using this custom driver, but in the future I'll need to re-use it for others, so I'm not using a local driver for that reason. I'll simply rewrite the serves method when necessary.

Fair. You might be able to simply have the serves() method return true if it's a LocalValetDriver file, since it looks at that file first. Then even fewer rewrites required between projects ;)

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

No branches or pull requests

4 participants