Bedrock Valet Can’t connect to local MySQL server Error

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=bedrock
Don'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=bedrock
Don'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!

Bedrock Plugins Installation

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:

DISALLOW_FILE_MODS

This PHP rule prevents the installation of other new plugins while allowing the listing of them. You have to install plugins by other means which we will discuss shortly. Also see https://github.com/roots/bedrock/blob/master/config/environments/production.php#L6-L7

Why is standard installation Blocked?

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.

Composer

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:

{
 "name": "acme/brilliant-wordpress-site",
 "description": "My brilliant WordPress site",
 "repositories":[
 {
 "type":"composer",
 "url":"https://wpackagist.org"
 }
 ],
 "require": {
 "aws/aws-sdk-php":"*",
 "wpackagist-plugin/akismet":"dev-trunk",
 "wpackagist-plugin/captcha":">=3.9",
 "wpackagist-theme/hueman":"*"
 },
 "autoload": {
 "psr-0": {
 "Acme": "src/"
 }
 }
}

Another way would be:

composer require wpackagist-plugin/wordpress-seo
This grabs the file from packagist, composer repository and installs it for you.
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.”

Plugin Management ease

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:

{

"name": "roots/bedrock",
"type": "project",
"license": "MIT",
"description": "WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure",
"homepage": "https://roots.io/bedrock/",
"authors": [

{

"name": "Scott Walkinshaw",
"email": "scott.walkinshaw@gmail.com",
"homepage": "https://github.com/swalkinshaw"

},
{
"name": "Ben Word",
"email": "ben@benword.com",
"homepage": "https://github.com/retlehs"
}
],
"keywords": [
"bedrock", "roots", "wordpress", "stack", "composer", "vagrant", "wp"
],
"support": {
"issues": "https://github.com/roots/bedrock/issues",
"forum": "https://discourse.roots.io/category/bedrock"
},
"config": {
"preferred-install": "dist"
},
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"require": {

"php": ">=5.6",
"composer/installers": "^1.4",
"vlucas/phpdotenv": "^2.0.1",
"johnpbloch/wordpress": "4.8.2"
"oscarotero/env": "^1.1.0",
"roots/wp-password-bcrypt": "1.0.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0.2"
},
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"web/app/plugins/{$name}/": ["type:wordpress-plugin"],
"web/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "web/wp"
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"test": [
"vendor/bin/phpcs"
]
}
}
 As you can see hardly any plugins are installed yet, However there are a few other things installed such as:
  • Bcrypt
  • phpdotenv,
  • codesniffer

and other goodies for better development.

WPackagist Additions

As you saw earlier you can add WPackagist plugins or themes using the composer command or by simply adding a line to the composer.json file.

WordPres Packagist

For one setup we have for example this required block including multiple WordPress plugins using WPackagist:

"require": {
"php": ">=5.6",
"composer/installers": "~1.0.12",
"vlucas/phpdotenv": "^2.0.1",
"oscarotero/env": "^1.0",
"roots/wp-password-bcrypt": "1.0.0",
"wpackagist-plugin/antispam-bee": "*",
"wpackagist-plugin/autodescription": "*",
"wpackagist-plugin/imagify":"*",
"wpackagist-plugin/mailchimp":"*",
"wpackagist-plugin/popup-maker":"*",
"wpackagist-plugin/tawkto-live-chat":"*",
"wpackagist-plugin/wordpress-importer":"*",
"wpackagist-plugin/wp-basic-auth":"*",
"wpackagist-plugin/wp-subscribe": "*",
"wpackagist-plugin/yet-another-related-posts-plugin": "*",
"johnpbloch/wordpress": "4.8.2"
},

Deployment

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.

 

Modern WordPress Development with Roots

I have been working on and off as a web developer and mainly with WordPress for over 15 years. I worked with different frameworks such as Genesis, Thesis, Canvas and Divi. I also worked or dabbled in a few starters themes such as _s .  And often I have customized themes that customers found / bought on Themeforest. And as these options became less and less appealing to me I started to look for something else.  That choice has become Roots

Reasons why I am moving

The reasons why I am moving more and more of my projects to Roots with Bedrock as a modern WordPress stack, Ansible for provisioning and Sage as a starts theme are many. Allow me to go throught the most important ones.

Efficiency

To learn a new theme every time a client decides this is the theme for him or her is tiresome, tedious and NOT efficient.  It will require you to read new documentation, get familiar with different theme panels and coding techniques used by the developer in question.

Quality

Also there are many themes out there on Themeforest and other places that just have not been coded well.  Often themes inject CSS and javaScript in odd ways making it hard to override CSS using a child theme, lack options which require me to use lots of plugins, adding lots of files to the stack, making it hard to optimize the site. Sometimes pages are not even valid causing different displays in different browsers.

Something missing

Most of the time these starter themes or frameworks had something I liked, but they were always lacking something or were not rigid enough in the way they were set up to truly offer clients high end themes and get them these in the quickest way possible.

Support

When you create your own code, or know a starter theme inside out you can provide your own support. When you use a theme that is supported by WordPress experts you have people to fall back too. Roots is such a warm and fuzzy place.

Roots to the rescue

When you create a product for a client don’t do something half-assed. Deliver quality and know your product. Good quality products attract good quality clients. And that is something we all want right?

Modern WordPress Development with Roots to the rescue! Roots is a all encompassing framework. Not a WordPress framework, but a place where people help you build better WordPress sites, become a better programmer and build sites faster. This by providing you with a Modern WordPress Stack: Bedrock, efficient provisioning system with Ansible and a kick ass starters theme called Sage.

This does not mean this will be easy. Learning a new work structure takes time, but believe me this is worth it. I am only a beginner, but I have been convinced and as a new enthusiast I will do my best to bring you over to the dark side too 😉

Modern WordPress Development with Roots

So what is modern WordPress Development with Roots? Well it is a package that helps you set up your local, staging and production environments,  put together a modern WordPress Stack AND provides you with a very effcient WordPress Starters Theme to deliver awesome WordPress sites your clients will love!

Bedrock

• Bedrock Modern WordPress Stack- Better folder structure, Dependency management with Composer, Easy WordPress configuration with environment specific files,  Environment variables with Dotenv, …

Bedrock-Ansible

•  Bedrock-Ansible – Easy server provisioning with Ansible (Ubuntu 14.04, PHP 5.6 or HHVM, MariaDB), Local Vagrant Package, One-command deploys, WP CLI,..

Sage

• Sage Starters Theme – Roots Starters Theme managed with NPM asset builder, Bower for front end package management, Gulp for image optimization, concatenationan and minification and sass/less compiling and error checking, Browser Synch.

See next post(s) with more details on Bedrock, Bedrock Ansible and Sage:

  • Bedrock
  • Bedrock Ansible – To be added
  • Sage – To be added
  • Roots WordPress Stack Workshop