Craft 2.X Local setup error – Craft not connecting to MySQL (via Sequel Pro) Novice dev here, really struggling to get my local setup functioning. After a couple of days of wrestling with Apache config settings, I finally have Craft connecting via a VHOST setup. The problem – 

Craft can’t connect to the database with the credentials in craft/config/db.php.


This should all be tried and tested as it came from my lead dev on this project and had been working, so it is likely something silly I have done in the set up. I just can't figure out what. 

Thus far, I have downloaded the repo, installed all dependencies and have successfully got the local server running with npm run start. I've configured a Virtual Host and that's all running fine. I downloaded a copy of the production db from the live site and uploaded it to my local db (connect via Sequel Pro). Both db's have the same name. 

My db.php file is:

return array(

// The database server name or IP address. Usually this is 'localhost' or '127.0.0.1'.
'server' =&gt; $_SERVER['DATABASE_HOST'],

// The name of the database to select.
'database' =&gt; $_SERVER['DB_NAME'],

// The database username to connect with.
'user' =&gt; 'root',

// The database password to connect with.
'password' =&gt; $_SERVER['DB_PASSWORD'],

// The prefix to use when naming tables. This can be no more than 5 characters.
'tablePrefix' =&gt; 'craft',


);

My VHOST is:

&lt;VirtualHost *:80&gt;


SetEnv DATABASE_HOST localhost
  SetEnv DB_NAME dbName
  SetEnv DB_PASSWORD dbPassword
  SetEnv DEV_MODE true
  SetEnv SITE_URL sitename.local
  SetEnv DB_PORT 3306
  DocumentRoot "/Users/username/Sites/sitename/public"
  ServerName www.sitename.local
  ServerAlias www.sitename.local
  ErrorLog "/Users/username/Sites/sitename/error_log"
  CustomLog "/Users/username/Sites/sitename/access_log" common
  &lt;Directory "/Users/username/Sites/sitename/public"&gt;
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
  &lt;/Directory&gt;
&lt;/VirtualHost&gt;


I'm stumped. The only think I have been able to find on similar threads seems to point to db version issues (which might be the case but I don't know how to check). 

Does anyone have any ideas?
Rather then passing the database details in virtualhost. You should put the database server details in db.php file as below.

DB.php file below:

&lt;?php

/**
 * Database Configuration
 *
 * All of your system's database configuration settings go in here.
 * You can see a list of the default settings in craft/app/etc/config/defaults/db.php
 */

return array(

    // The database server name or IP address. Usually this is 'localhost' or '127.0.0.1'.
    'server' =&gt; '127.0.0.1',

    // The database username to connect with.
    'user' =&gt; 'root',

    // The database password to connect with.
    'password' =&gt; '',

    // The name of the database to select.
    'database' =&gt; 'db_name',

    // The prefix to use when naming tables. This can be no more than 5 characters.
    'tablePrefix' =&gt; 'craft',

);


Your VHost file should be like below:

#
&lt;VirtualHost *:80&gt;
    ServerName crafty-coffee.local
    DocumentRoot "c:/wamp64/www/crafty-coffee/httpdocs"
    &lt;Directory  "c:/wamp64/www/crafty-coffee/"&gt;
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;


host file (C:\Windows\System32\drivers\etc) :

127.0.0.1   crafty-coffee.local
::1 crafty-coffee.local


This works perfectly for me. After this restart your Sequel Pro.