We often prefer working with Laravel Valet over working with Trellis. This as Trellis runs Vagrant which runs VirtualBox. Very heavy all that while you could use Laravel Valet which uses the resources your Mac has and only needs some extras using Homebrew.
Trellis Valet Driver
Now, there is a package you can use to keep the site and trellis directories and run your Bedrock based site in Laravel. It is called the Trellis Valet Driver . You simply download the driver and add it to ~/.config/valet/Drivers . Then you do a valet restart and link the site directory.
Issues
Once I added this driver I did a valet restart and then I had some issues. I did a
valet link in root project
and then removed it as that did not work and should not. So I did it in the site folder where the site files and Bedrock reside. But I only got a timeout
This site can’t be reached
and no Nginx Users/jasper/.config/valet/Log/nginx-error.log"; or PHP FPM logs at /usr/local/var/log/php-fpm.log referring to it. Then I started wondering if vagrant suspend did remove the hosts file data too. It did not so I commented it
Once I did that I started having a database connection issue
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in /Users/jasper/code/site.com/site/web/wp/wp-includes/wp-db.php on line 1531
So I knew it was working. Just hadn’t added the database to the Homebrew MariaDB SQL server.
If you want to set up a Valet Bedrock based WordPress website and you run into this Valet Can’t connect to local MySQL server error. It will block you from generating a Bedrock WordPress website. It is however easy to remedy.
Valet Can’t connect to local MySQL server Error
The error you get will pop up this way on creating a Bedrock WordPress site:
wp valet new woo-guteberg --project=bedrockDon't go anywhere, this should only take a second...Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
MariaDB not running
This Valet Can’t connect to local MySQL server Error happens to us all every now and then. Either because we shut down MariaDB or because it did not start properly when we started our Mac.
You probably need to restart MariaDB:
brew services start mariadb
Afterwards you will be able to set up the site without issues:
wp valet new woo-guteberg --project=bedrockDon't go anywhere, this should only take a second...Success: woo-guteberg ready! https://woo-guteberg.dev
It is so easy with Laravel Valet. Love it very much!
The Bedrock Plugins Installation is set up differently. More efficiently too I daresay. That is why often beginners with Bedrock bump into the fact that they cannot install plugins from the Dashboard. In this post I will get into the reasons and benefits behind it. For a general overview of Bedrock see the post Bedrock Modern WordPress Stack.
Dashboard Installation Deactivated
Bedrock disables Installation of Plugins from the Dashboard with:
The standard installation of plugins – and themes by the way – is blocked so all installed themes and plugins stay in version control. Once you start adding plugins or themes on the production server they are no longer in version control. And every time you do a Trellis deployment you run the risk of losing plugins and themes as they are nog part of version control.
Plugin Installation with Composer
You can install plugins with Bedrock using Composer. You can also activate and deactivate them using Composer or WP CLI. You can also manage commercial plugins with composer with a custom composer serve. Either that or you can do it by adding them manually to your site and version control. You will need to remove them from the .gitignore list to get them versioned. You do this by using an exclamation mark like so for example:
!public/uploads/.gitkeep
Composer in practise
Composer allows you to download and install WordPress plugins from packages registered with Composer and also from WPackagist, which syncs with the WordPress plugins repository.
Just run a command to install the plugin like so:
composer install
This install all the plugins in your composer.json file in your Bedrock directory. At WPackagist they show you an example of themes and plugins added from their repo:
NBB It is possible with WP CLI, but not recommended as this way things are not kept in version control.
Code Parity
This method of managing plugins is way better for keeping solid installations that are equal locally (Vagrant) on staging (Trellis server (recommended)) and on production (Trellis) . So this allows for code parity. No more “But it works on my computer”. All changes added with composer will be part of Git version control.
Therefore they will be the same in all environments. Even the plugins not added with composer will be added to version control. All installations that are not done with composer or not committed will be lost to our version control.
As the Roots theme stated:
“Manage your WordPress install and plugins with Composer, a PHP dependency manager. Composer will make development more reliable, help with team collaboration, and it helps maintain a better Git repository.”
On top of that the plugin and theme version can be managed easily. You can enforce a version to make sure the site does not break. Then locally on development you can test a new version by a small composer.json tweak and commit once you are satisfied it works
Composer Bedrock Example
Here the current composer.json as an example. It is one you will find with a standard Bedrock WordPress setup:
For each installed plugin or WordPress installation a version is set. And for every update this has to be adjusted. Then you can commit it to version control and deploy it using Trellis’ deployment script ./bin/deploy.sh production domain.com . During deployment this file is checked and updates will be made. The latter fully automatically.
Bypassing Limitations
If customers do want to install plugin you can comment out the
DISALLOW_FILE_MODS
at bedrock-site/config/production. We sometimes use something like
<?php
/** Production */
ini_set('display_errors', 0);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
define( 'WP_MEMORY_LIMIT', '128M' );
/** Disable all file modifications including updates and update notifications */
//define('DISALLOW_FILE_MODS', true);
As you can see the DISALLOW_FILE_MODS has been commented out to allow the adding of plugins and themes.
Do however remember to exclude the plugins and themes you add from the .gitignore and to add them to the repository. Otherwise you run the risk of removing elements. Also make sure you enforce some parity by syncing from production another way. Either that or forget about version control altogether.