Skip to content

Instantly share code, notes, and snippets.

@CNanninga
Last active February 13, 2019 22:26
Show Gist options
  • Save CNanninga/22b54ec72bd52b11812ded871823308b to your computer and use it in GitHub Desktop.
Save CNanninga/22b54ec72bd52b11812ded871823308b to your computer and use it in GitHub Desktop.

Valet+ Configuration

Before Valet Install

Kill Native PHP and MySQL

brew services stop php
brew services stop mysql

Global/One-time Configuration After Valet Install

Link PHP and MySQL commands

If /usr/local/bin/php and /usr/local/bin/mysql don't exist or aren't symlinked to versions 7.1 and 5.7 respectively after Valet install, explicitly link them. (Hasn't been tested with the valet-php services.)

Set Root Password for MySQL

If Valet complained about not being able to set a root password, set it via the below. It's possible to connect to MySQL with a blank password, but Valet's built-in commands for working with database and auto-generating configuration assume the password is "root".

mysql_secure_installation
  • VALIDATE PASSWORD PLUGIN: No
  • Change the password for root? Yes ("root")
  • Remove anonymous users? No
  • Disallow root login remotely? Yes
  • Remove test database and access to it? No
  • Reload privilege tables now? Yes

park

valet park in sites directory

Configuration Tuning

Improve timeouts and concurrency in /usr/local/etc/php/7.1/php-fpm.d/www.conf:

pm.max_children = 200
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.process_idle_timeout = 10s
pm.max_requests = 500

Make sure timeouts and memory limis are sufficient in /usr/local/etc/php/7.1/conf.d/z-performance.ini

max_execution_time = 300
memory_limit = 2G

Increase timeouts in /usr/local/etc/nginx/nginx.conf

http {
	client_header_timeout 3000;
	client_body_timeout 3000;
	fastcgi_read_timeout 3000;
	fastcgi_buffers 8 128k;
	fastcgi_buffer_size 128k;
}

Restart PHP and Nginx with valet restart php nginx

Configure Valet+ to Not Require a Password for Sudo

echo "%admin ALL = NOPASSWD: /usr/local/bin/valet" | sudo tee /etc/sudoers.d/valet-nopasswd

Per Site

Make secure

{domain_name} should not include ".test"

valet secure {domain_name}

Improve timeouts

Improve timeout in ~/.valet/Nginx/{domain_name}

    location ~ \.php$ {
        fastcgi_read_timeout 600;
    }

Restart Nginx with valet restart nginx

Handle multi-site if necessary

In project directory ({domain_name} should not include ".test"):

valet link {domain_name}
valet secure {domain_name}

Create .env.valet in the project root w/ env variables:

<?php

return [
    '{domain_name}' => [
        'MAGE_RUN_CODE' => '{website_code}',
        'MAGE_RUN_TYPE' => 'website',
    ],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment