Install and Configure PHP, MariaDB and Laravel Valet on MacOS
After using MAMP for years and never being really happy with it I’ve finally found a solution that is faster and, once configured properly, way more convenient than anything I’ve used before for local web development with PHP on a Mac.
These are some quick notes I took while figuring it all out, maybe they help somebody else, too.
Requirements
PHP
Install
brew install php
and/or
brew install php@version, e.g. php@7.3
Change versions
brew link php[@version]
follow instructions to unlink currently used keg first and use force if required
Increase Memory Limit
Loaded configuration file might have other limits than seen on the web.
These limits are configured in files listed under Additional .ini files parsed:
/usr/local/etc/php/7.3/conf.d/php-memory-limits.ini
After changes don’t forget to run:
valet restart
MariaDB
Install
brew install mariadb
Launch add login
To have launchd start mariadb now and restart at login:
brew services start mariadb
Launch manually
Or, if you don’t want/need a background service you can just run:
mysql.server start
mysql.server stop
Connect to DB:
mariadb comes without a root passsword yet I want to have a root password.
mysql -uroot
Use sudo if not permitted
Create Root Password for MariaDB
mysql -urootUSE mysql;ALTER USER 'root'@'localhost' IDENTIFIED BY 'root‘;
exit;
Despite this returning Query OK, 0 rows affected (0.000 sec)
it will set a root password to root
.
Valet
Docs: https://laravel.com/docs/6.x/valet
Avoid Dependency Conflicts with CGR
To avoid dependency conflicts with other global composer reqs you might consider using cgr to manage global composer requirements. If doing so, simply replace composer global require with the cgr command.
composer global require consolidation/cgr
Watch out for existing aliases to the cgr command (oh-my-zsh can provide those) and remove them to avoid conflict:
unalias cgr
Install
composer global require laravel/valet
# or using cgr
cgr laravel/valet
Configure
Avoid having to use sudo
valet trust
Run valet install if this tells you „Command trust is not defined“. It’s likely that you’ve once had an old version of Valet installed.
Go to the directory where your sites will live (here ~/www) and run valet park
mkdir ~/www && cd ~/www
valet park
Run a site a site on https
valet secure <site-name>valet unsecure <site-name
Firefox still needs you to add an exception for every site manually. Here’s how to change that
TL:DR import ~/.config/valet/CA/LaravelValetSelfSigend.pem
as a trusted Authority in Firefox Certificate Manager (Authorities tab)
Change the TLD
By default, *.test is used. To change to *.localhost (which is the safest option in my experience, local
will cause issues on MacOS, site
makes same-named the public TLD unavailable) run:
valet tld localhost
⚠️ Be careful using local
as a domain, it probably won’t work on MacOS
Show parked sites
valet parked
Change PHP Version used by Valet
Valet allows you to switch PHP versions using the valet use php@<version>
command. Valet will install the specified PHP version via Brew if it is not already installed:
valet use php@7.3
use php
Link a subfolder
cd ~/www/mysite/subfolder/xyz
valet link mysite
Avoid conflicts with MAMP
When running MAMP in parallel it’s best to set it to use MAMP’s the default ports.