<p>Rather then passing the database details in virtualhost. You should put the database server details in db.php file as below.</p>

<p>DB.php file below:</p>

<pre><code>&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',

);
</code></pre>

<p>Your VHost file should be like below:</p>

<pre><code>#
&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;
</code></pre>

<p>host file (C:\Windows\System32\drivers\etc) :</p>

<pre><code>127.0.0.1   crafty-coffee.local
::1 crafty-coffee.local
</code></pre>

<p>This works perfectly for me. After this restart your Sequel Pro.</p>

CC BY-SA 4.0
2019-05-03T20:10:56.063Z
Thanks for the reply. I had tried this before, but sadly it didn't work. I just tried again and still a no go. Makes me feel like I have the db creds wrong, but I don't think I do.
J. Ktz
CC BY-SA 4.0
2019-05-03T01:34:25.910Z
2019-05-03T01:34:25.910Z
Priti Rathod
<p>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 – </p>

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

<p>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. </p>

<p>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. </p>

<p>My db.php file is:</p>

<pre><code>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',
</code></pre>

<p>);</p>

<p>My VHOST is:</p>

<pre><code>&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;
</code></pre>

<p>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). </p>

<p>Does anyone have any ideas? </p>

CC BY-SA 4.0
2019-05-03T00:50:51.993Z
In db.php, before the `return array(` bit, if you put `die($_SERVER['DATABASE_HOST']);`, do you get the value you expect?
Brad Bell
CC BY-SA 4.0
2019-05-06T22:53:00.257Z
No I don't think so (unless I am doing something wrong). Doing that seems to loop me. I got: `This page isn’t working www.sitename.local redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS –`
J. Ktz
<mysql><craft2><apache>
Craft 2.X Local setup error – Craft not connecting to MySQL (via Sequel Pro)
# Craft 2.X Local setup error – Craft not connecting to MySQL (via Sequel Pro)

(Asked by: username_0 on 2019-05-02)

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' => $_SERVER['DATABASE_HOST'],

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

// The database username to connect with.
'user' => 'root',

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

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

);
My VHOST is:



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
  
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
  


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?

**Tags:** mysql, craft2, apache

> **Comments:**
> **username_1**: In db.php, before the `return array(` bit, if you put `die($_SERVER['DATABASE_HOST']);`, do you get the value you expect?  
> **username_0**: No I don't think so (unless I am doing something wrong). Doing that seems to loop me. I got: `This page isn’t working www.sitename.local redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS –`  

---

## 1 answers

### Answer by username_2 on 2019-05-03. Score: 1

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:
 '127.0.0.1',

    // The database username to connect with.
    'user' => 'root',

    // The database password to connect with.
    'password' => '',

    // The name of the database to select.
    'database' => 'db_name',

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

);

Your VHost file should be like below:
#

    ServerName crafty-coffee.local
    DocumentRoot "c:/wamp64/www/crafty-coffee/httpdocs"
    
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    


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.

> **Comments:**
> **username_0**: Thanks for the reply. I had tried this before, but sadly it didn't work. I just tried again and still a no go. Makes me feel like I have the db creds wrong, but I don't think I do.  

---

