Something I find really useful in development, and that isn't unique to Yii2, is migrations.  These are blocks of code that explain what should be done to a database in order to add new schema elements or change them is some way.  Sometimes there's an issue with a migration and this post looks to cover the "no such file or directory" error I received today.

On running my migration to kick off my project I received this message:

Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] No such file or directory'

That's not altogether helpful as I know all the files are correct and there's definitely a database server (MariaDB) on this system.  I checked my configuration, all seemed to be in order, and resorted to searching the web.  This post on Stackoverflow had the solution - change my database host from localhost to 127.0.0.1.  I've not had to do this before but I gave it a go.  Problem solved!

My config now looks like this:

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=127.0.0.1;dbname=devdb',
    'username' => 'development',
    'password' => 'HiddenFromYou',
    'charset' => 'utf8',
    ]