Database connection & 404 errors

Hi there

I’m trying to setup bedrock & sage on my localhost WAMP server runnung php 5.5.12, apache 2.4.9 and mysql 5.6.17. All my .env variables are configured, db and user setup and vhost set to site-path/web but when I try to run the wordpress install script i get a database connection erro with the following warnings:

Warning: mysqli_real_connect(): in C:\wamp\www\bedrock-boilerplate\web\wp\wp-includes\wp-db.php on line 1386.

My .env file:

DB_NAME=bedrock_wp
DB_USER=admin_bedrock
DB_PASSWORD=P_>my-password
DB_HOST=localhost

WP_ENV=development
WP_HOME=http://localhost/bedrock-boilerplate
WP_SITEURL=http://localhost/bedrock-boilerplate/wp

vhost:

    <VirtualHost *:80>
        DocumentRoot "c:/wamp/www"
        ServerName localhost
        ServerAlias localhost
        <Directory  "c:/wamp/www">
            AllowOverride All
            Require local
        </Directory>
    </VirtualHost>
        
    
    <VirtualHost *:80>
            DocumentRoot "c:/wamp/www/bedrock-boilerplate/web/"
            ServerName bedrock-boilerplate
            <Directory  "c:/wamp/www/bedrock-boilerplate/web/">
                Options FollowSymlinks
                AllowOverride All
                Require local
            </Directory>
        </VirtualHost>

My manifest.json file:

    {
      "dependencies": {
        "main.js": {
          "files": [
            "scripts/main.js"
          ],
          "main": true
        },
        "main.css": {
          "files": [
            "styles/main.less"
          ],
          "main": true
        },
        "editor-style.css": {
          "files": [
            "styles/editor-style.less"
          ]
        },
        "jquery.js": {
          "bower": ["jquery"]
        },
        "modernizr.js": {
          "bower": ["modernizr"]
        }
      },
      "config": {
        "devUrl": "http://localhost/bedrock-boilerplate"
      }
    }

Has anybody else experienced this issue? All my other sites run fine on the latest wampserver but i can’t seem to get my Bedrock install running.

Any help would be great

Many thanks in advance

Make sure you can connect to MySQL manually with those credentials:

mysql -uadmin_bedrock -p bedrock_wp

Enter your password when prompted. If that doesn’t work then you’ll at least need to fix that first.

I get a 1064 syntax error when running

mysql -u admin_bedrock -pXXXX -h localhost bedrock_wp;

or

mysql -u admin_bedrock -p -h localhost bedrock_wp;

Without the semicolon it just goes to the next line without any password prompt

Like i said before I can connect a wordpress db so its something in my config which is not allowing me to run the install script so the database has no tables. Is there anything else I can check?

Hard to help without more information.

Warning: mysqli_real_connect(): in C:\wamp\www\bedrock-boilerplate\web\wp\wp-includes\wp-db.php on line 1386.

This isn’t really a full error message. It doesn’t say anything else?

I get a bunch of warnings:

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'admin-bedrock'@'localhost' (using password: YES) in C:\wamp\www\bedrock-boilerplate\web\wp\wp-includes\wp-db.php on line 1386

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\bedrock-boilerplate\web\wp\wp-includes\wp-db.php on line 1416

Warning: mysql_connect(): Access denied for user 'admin-bedrock'@'localhost' (using password: YES) in C:\wamp\www\bedrock-boilerplate\web\wp\wp-includes\wp-db.php on line 1416

But the main thing is the database connection error. I know that mysql is working though i seem to get Error 1064 syntax error when trying your suggestion above. I tried revoking privileges and the granting them all privileges to the db use on the bedrock database via the mysql console (not sure whether this confirms the connection exists or not?). When i check the mysql log I get this warning (note - I created a new user ‘admin-bedrock’ and db ‘bedrock’):

2015-03-18 11:17:09 7924 [Warning] Did not write failed 'REVOKE ALL PRIVILEGES ON `bedrock`.* FROM 'admin-bedrock'@'localhost'' into binary log while granting/revoking privileges in databases.

I’m at a real loss here, I’ve followed all the setup instructions but can’t seem to get this up and running. Is there a way to refresh the setup via composer since I’ve changed the .env vars?

Ok, things are getting weird. I can run the install script via the web directory ie http://localhost/bedrock/web/wp-admin/install.php

I got an unstyled wordpress registration page it loads and then redirects to an unstyled login page. Then if i try to login it redirects to http://localhost/bedrock/wp/wp-login.php with a 404 error

Something is definitely not correct with your Apache/htaccess configuration then. I’m pretty sure it’s because you have your site in a subdirectory of localhost. I know this has come up before but I don’t remember the solution off the top of my head so you could try searching this forum.

Alternatively, you could just give your bedrock Vhost a hostname like bedrock.dev and define in your hosts file. Then your URLs would just be like http://bedrock.dev and http://bedrock.dev/wp

Ok, so what you’re suggesting is:

  1. create directory outside wamp/www e.g. c:/web/bedrock.dev - run install process

  2. In vhosts create virtualhosts:

    <VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory “c:/wamp/www”>
    AllowOverride All
    Require local

    <VirtualHost *:80>
    DocumentRoot "c:/web/bedrock.dev"
    ServerName bedrock.dev
    ServerAlias bedrock.dev
    <Directory “c:/web/bedrock.dev/wp/”>
    Options FollowSymlinks
    AllowOverride All
    Require all granted

.env file should read:

DB_NAME=bedrock_wp
DB_USER=admin_bedrock
DB_PASSWORD=xxxxxxxx
DB_HOST=localhost

WP_ENV=development
WP_HOME=http://bedrock.dev
WP_SITEURL=http://bedrock.dev/wp

Is DB_HOST still ‘localhost’ in this case??

in my hosts file:

 127.0.0.1 localhost
 ::1 localhost

 127.0.0.1 bedrock.dev
 ::1 bedrock.dev

Do I have to add anything to my httpd.conf file? At present it reads:

<Directory "c:/wamp/www/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
</Directory>

Then, once I’ve flushed the dns cache and restarted wamp I can run

http://bedrock.dev/wp/wp-admin/install.php 

And this should run the wordpress install?

Having done all the above - if I navigate to http://bedrock.dev I get:

Forbidden - Apache/2.4.9 (Win32) PHP/5.5.12 Server at bedrock.dev Port 80

When I check the apache error log I get:

[Thu Mar 19 11:25:11.089800 2015] [autoindex:error] [pid 10960:tid 848] [client ::1:56472] AH01276: Cannot serve directory C:/web/bedrock.dev/: No matching DirectoryIndex (index.php,index.php3,index.html,index.htm) found, and server-generated directory index forbidden by Options directive

When running http://bedrock.dev/wp/wp-admin/install.php

I get 404

When checking the mysql log there’s a warning:

2015-03-19 11:10:18 320 [Warning] Did not write failed 'REVOKE ALL PRIVILEGES ON `bedrock\_wp`.* FROM 'admin_bedrock'@'localhost'' into binary log while granting/revoking privileges in databases.

Not sure if this is important or not. When creating the db and user in phpmyadmin all looks fine

You mentioned htaccess file config - I created one manually with the following:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /bedrock.dev/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /bedrock.dev/index.php [L]
</IfModule>

# END WordPress

Still get the same messages when trying to run the install. I’ll have a look for the forum post you mentioned and hopefully something will come up but if you could have a look at my setup and confirm I’m doing it correctly that would be great

Ok, so i got it working by editing the documentroot in to:

DocumentRoot "c:/web/bedrock.dev/web

Not sure if this is standard practice or not. From alot of the examples on wamp and from looking at how others had set this up on this forum? Anyhoo, the issue i now have is that upon activating the sage theme I get 404 errors with unstyled pages:

Dev console:

//bedrock.dev/app/themes/sage/dist/scripts/main.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://bedrock.dev/app/themes/sage/dist/scripts/modernizr.js Failed to load resource: the server responded with a status of 404 (Not Found)
2http://bedrock.dev/app/themes/sage/dist/styles/main.css Failed to load resource: the server responded with a status of 404 

I cloned the theme via git to the app/themes directory.

Your DocumentRoot should always point to web/ for Bedrock so that’s correct. I think the only thing you have wrong now is your .htaccess file.

Try just the standard one:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

edit: there’s now no need for that RewriteBase since you have a VHost just for Bedrock pointing to the proper web root.

Ok so I removed the .htaccess file. New one had been generated in the web directory already with the appropriate RewriteBase - so this was already in place at the time I activated Sage. Is there anythign else i can check or define in composer? Current composer.json file reads:

{
  "name": "roots/bedrock",
  "type": "project",
  "license": "MIT",
  "description": "A modern WordPress stack",
  "homepage": "http://roots.io/wordpress-stack/",
  "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": [
    "wordpress", "stack", "capistrano", "composer", "vagrant", "wp"
  ],
  "support": {
    "issues": "https://github.com/roots/bedrock/issues",
    "forum": "http://discourse.roots.io/category/bedrock"
  },
  "config": {
    "preferred-install": "dist",
    "generate-salts": true
  },
  "autoload": {
    "psr-0": {"Roots\\Bedrock\\Installer": "scripts"}
  },
  "scripts": {
    "post-root-package-install": ["Roots\\Bedrock\\Installer::addSalts"]
  },
  "repositories": [
    {
      "type": "composer",
      "url": "http://wpackagist.org"
    }
  ],
  "require": {
    "php": ">=5.4",
    "composer/installers": "v1.0.12",
    "vlucas/phpdotenv": "1.0.9",
    "johnpbloch/wordpress": "4.1.1"
  },
  "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"
  }
}

UPDATE: Got it working after running gulp command. All working as it should. Many thanks for your help. This ticket can be closed now