Skip to content

Instantly share code, notes, and snippets.

@Tjitse-E
Created April 14, 2022 09:20
Show Gist options
  • Save Tjitse-E/49745ed4fbf9fa03f84010ae21655886 to your computer and use it in GitHub Desktop.
Save Tjitse-E/49745ed4fbf9fa03f84010ae21655886 to your computer and use it in GitHub Desktop.
Valet+ install on M1 Mac's.

Install Valet+

Install brew

First we need to install Brew, the dependency for the Mac:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install PHP

MacOS Monterney comes without PHP. Valet+ uses a special version of PHP that you can install like this:

# Install regular PHP first to invoid crashing when running the valet install command
brew install php

# Now install the version 
PHP_VERSION=7.4
brew tap henkrehorst/homebrew-php
brew install valet-php@$PHP_VERSION
brew link valet-php@$PHP_VERSION

Now verify if the php command works: php -v should output PHP 7.4.

Install composer

Install composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Next move composer to the local bin folder:

sudo mkdir -p /usr/local/bin
sudo mv composer.phar /usr/local/bin/composer

And verify that the composer command works:

composer -v

It should output the current composer version. More information can be found here.

Install Valet+ via composer

My preferred way of installing Valet+ is via composer:

composer global require weprovide/valet-plus.

Next verify that valet is working by running valet. You should see the current Valet+ version and the available commands.

Disable GeoIP

Currently there are problems with installing the GeoIP extension with valet-php@7.4 on M1 macs. I've disabled Geoip by editing:

vim ~/.composer/vendor/weprovide/valet-plus/cli/Valet/Pecl.php
``
Find this section and set PHP 7.4 to false.
```text
        self::GEOIP_EXTENSION => [
            '8.0' => false
            '7.4' => '1.1.1', // Set this to false to skip GeoIP installation
            '7.3' => '1.1.1',
            '7.2' => '1.1.1',
            '7.1' => '1.1.1',
            '7.0' => '1.1.1',
            'extension_type' => self::NORMAL_EXTENSION_TYPE,
            'brew_dependency' => 'geoip'
        ],

Run the install command:

Next run the install command:

export LDFLAGS="-L/opt/homebrew/opt/pcre2/lib"
export CPPFLAGS="-I/opt/homebrew/opt/pcre2/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/pcre2/lib/pkgconfig"
ln -s /opt/homebrew/include/pcre2.h $(brew --prefix)/Cellar/valet-php@$PHP_VERSION/$(php -i | grep -Eo -m 1 "$PHP_VERSION.*$")/include/php/ext/pcre/pcre2.h
valet install --with-mysql-8

Output:

PECL] Updating PECL channel: pecl.php.net
[PECL] Installing extensions
	apcu is already installed, skipping...
	apcu is already enabled, skipping...
	yaml is already installed, skipping...
	yaml is already enabled, skipping...
[PECL-CUSTOM] Installing extensions
[valet-php@7.4] Restarting
ARM Mac detected
[dnsmasq] Restarting
ARM Mac detected
[mysql] Installing
[mysql] Stopping
[mysql] Configuring
[mysql] Restarting
[redis] already installed
ARM Mac detected
[redis] Restarting
[mailhog] already installed
[mailhog] Restarting
ARM Mac detected
[nginx] Restarting
ARM Mac detected
ARM Mac detected
Valet installed successfully!

Great, Valet+ is now installed!

Manual tests

Check that dnsmasq is working correctly by pinging a .test domain:

ping random-domain.test

Also check your mysql connection by executing the command mysql. This should open up the mysql CLI.

Install Elasticsearch

Initially I had some problems after installing Elasticsearch on the M1 macbook. It turns out you need Rosetta to run the Elasticsearch version that's installed when you install it with Brew.

softwareupdate --install-rosetta
brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
brew services start elasticsearch-full
curl localhost:9200

Setup Valet+

mkdir ~/sites
cd ~/sites
valet park

Test

mkdir hello
echo "<?php echo 'Valet+ at your service';" > index.php
@wpoortman
Copy link

For those running MacOS Ventura: elastic/elasticsearch#91159

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