Skip to content

Instantly share code, notes, and snippets.

@zainengineer
Last active January 10, 2024 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zainengineer/e2ef50cbd09a2b0735abb90d922fa815 to your computer and use it in GitHub Desktop.
Save zainengineer/e2ef50cbd09a2b0735abb90d922fa815 to your computer and use it in GitHub Desktop.
valet-plus

Installation

Switching not working

vi ~/.bash_profile
#to find the file
#grep -s valet  ~/.* | grep -v ".bash_history" 


#and probably not do the following
echo 'export PATH="/usr/local/opt/valet-php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/valet-php@7.2/sbin:$PATH"' >> ~/.bash_profile
#opening new terminal shell helps

Switching failing due to extension

Module 'apcu' already loaded in Unknown on line

Remove all the extension lines on top except xdebug

/usr/local/etc/valet-php/7.2/php.ini

Unable to determine linked PHP

brew link valet-php@7.2 --force
#brew unlink valet-php@5.6 && brew link --force valet-php@5.6
#newer version --force is not always required

initial setup issues

cd my_project_folder
valet park

vi /usr/local/etc/nginx//nginx.conf
#comment line include valet/elasticsearch.conf; (as last resort can delete it)

version specific issues

brew install valet-php@7.1
valet use 7.1

php 7.4 problem

valet use 7.4

Valet doesn't support PHP version: 7.4 (try something like 'php@7.3' instead)

valet use php@7.4
Installing php@7.4...
.....
[php@7.4] is not installed, installing it now via Brew... 🍻
Error: php@7.4 has been disabled because it is a versioned formula!

HOMEBREW_NO_INSTALL_FROM_API=1 brew install php@7.4
Error: php@7.4 has been disabled because it is a versioned formula!

php 7.4 solution

brew install shivammathur/php/php@7.4
brew link php@7.4

install extension

pecl search sodium
pecl install libsodium

Extension installation issues

m4 --version
/usr/bin/m4 --version

if you get error message fix them.

APC issues

valet plus uses apc cache to cache configuration, but PHP 5.6 hard to install apcu_bc so easiet to use function_exists directly in valetplus code to work around it

exit and restarted the shell/console

dyld: Library not loaded

dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Abort trap: 6

to fix

brew remove valet-php@5.6
brew install valet-php@5.6
#if error Download failed: https://www.php.net/distributions/php-5.6.40.tar.xz
brew install valet-php@5.6 --build-from-source

Elastic Search No formulae found in taps

$ valet elasticsearch install
[libyaml] Installing
[elasticsearch@2.4] Installing
Warning: No available formula or cask with the name "elasticsearch@2.4". Did you mean elasticsearch or elasticsearch@6?
  ==> Searching for similarly named formulae...
  These similarly named formulae were found:
  elasticsearch
  elasticsearch@6
  To install one of them, run (for example):
    brew install elasticsearch
  ==> Searching for a previously deleted formula (in the last month)...
  Error: No previously deleted formula found.
  ==> Searching taps on GitHub...
  Error: No formulae found in taps.

to fix

brew tap github/bootstrap

In Brew.php line 108:

Brew was unable to install [elasticsearch@2.4].

mariadb / mysql

mariadbd
# to run server manually from command line to see errors
#log file
/Users/zain/.valet/Log/mysql.log
#data file
/usr/local/var/mysql
#delete following files if issue persist
ib_logfile0
ib_logfile1
#note in rare cases might be only one file

php-fpm socket issues

[crit] 97410#0: *5 connect() to unix:/Users/zain/.valet/valet.sock failed (2: No such file or directory)

#check if php-fpm running
ps aux | grep php

#change to anyother php version to see if that helps
valet use php 7.1

#try run fpm manually to see the behaviour
/usr/local/opt/valet-php@7.2/sbin/php-fpm --nodaemonize

#keep an eye on fpm log
less +F /usr/local/var/log/php-fpm.log

#list services
brew services list
#try running services manually
brew services start valet-php@7.1
brew services stop valet-php@7.1
brew services restart valet-php@7.2

#remove / fix brew
valet fix
sudo grm /usr/local/Cellar/valet-php@7.2/7.2.34_4 -rf 
ls -la /usr/local/var/homebrew/linked/ | grep -i php
rm /usr/local/var/homebrew/linked/valet-php@7.2
brew install valet-php@7.2 --build-from-source

nginx server variables

vi /usr/local/etc/nginx/valet/valet.conf

server {
    listen 127.0.0.1:80 default_server;
    #added this to make sure server_name is passed to phpstorm, as each server can have its own mapping etc
    server_name valet-nginx;
    
	 vi /usr/local/etc/nginx/fastcgi_params
 
 fastcgi_param SERVER_NAME  $server_name;

PHP 8.1 switching

Once PHP 8.1 is properly installed via valet

composer global remove laravel/valet

brew unlink php@7.1
brew unlink php@8.1
brew link php@8.1 --force --overwrite
php -v
composer global require laravel/valet:^3.0.0

# changing to PHP 7.1
composer global remove laravel/valet
composer global remove symfony/event-dispatcher

brew unlink php@8.1
brew unlink php@7.3
brew link php@7.3 --force --overwrite
php -v
composer global require laravel/valet:^2.0.0 

php -v
valet stop php
valet restart php

nginx timeout (during xdebug)

vi /opt/homebrew/etc/nginx/fastcgi_params && valet restart nginx

proxy_send_timeout 1800s;
proxy_read_timeout 1800s;
fastcgi_send_timeout 1800s;
fastcgi_read_timeout 1800s;

(editing other locations won't help)
If issues with valet plus, you can use valet standard.
Here are some of the issues
php@7.2 has been disabled because it is deprecated upstream!
use https://github.com/shivammathur/homebrew-php
brew tap shivammathur/php
brew install shivammathur/php/php@7.2
valet use php@7.2
Investigating why FPM is not working
/usr/local/opt/php@7.2/sbin/php-fpm --nodaemonize

Valet Use

#list which paths are being used as project root
valet paths
valet links

#to use current valet directory as an additional projects directory
valet park

#use a single project in a different directory
valet link buynow
#it will make buynow.test

#a custom test domain (multiple magento website pointing to a single store)
cd  ~/.valet/Sites/
ln -s /Volumes/sensetive/sites/mage3 uk-mage3

#alternatively go to the website folder
valet link uk-mage3
#newer versions of valet have folder 
~/.config/valet/Sites/


#index.php    
$domain = $_SERVER['HTTP_HOST'];
if (strpos($domain, 'uk-') === 0) {
    $_SERVER['MAGE_RUN_CODE'] = 'uk_website';
    $_SERVER['MAGE_RUN_TYPE'] = 'website';
}
#will need to clear cache, if still issues disable config cache entirely to test

# ngrok
# install ngrok first

valet share

#if magento or something which uses hardcoded or db base url
#change magento base url or ngrok url
#in index.php $_SERVER['HTTP_HOST'] ='642a5b5ef421.ngrok.io';
#cache flush

Valet files & directories

valet logs --help

~/.valet/Log/nginx-error.log
/usr/local/etc/nginx/valet/valet.conf

#php.ini and other php configs
/usr/local/etc/valet-php/7.2/
#php fatal errors 
~/.valet/Log/php.log
#fpm
/usr/local/var/log/php-fpm.log

ngrok

ngrok http https://local-custom-domain.com.au/ --host-header=local-custom-domain
# below seems to work better but need to understand it
ngrok http --domain=custom-domain.ngrok.io --host-header=rewrite local-custom-domain:443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment