Wordpress-install fails when using vagrant up

I am a noob to bedrock and ansible.

I was able to get wp up using vagrant up originally. However, when I vagrant destroy the vm and then try to vagrant up again, and then visit the site at example.dev, I keep getting a database connection error.

When looking at the vm output in terminal, I see the following:

    TASK: [wordpress-install | WP installed?] ************************************* 
failed: [default] => (item={'key': 'example.co', 'value': {'site_install': True, 'admin_user': 'admin', 'local_path': '../site', 'system_cron': True, 'repo': 'https://m33@bitbucket.org/example/a6-app.git', 'ssl': {'enabled': False}, 'multisite': {'enabled': True, 'subdomains': True}, 'site_title': 'exmaple Dev', 'admin_password': 'admin', 'env': {'db_name': 'a6_dev', 'wp_env': 'development', 'db_user': 'example_dbuser', 'db_password': 'example_dbpassword', 'wp_home': 'http://example.dev', 'wp_siteurl': 'http://example.dev/wp'}, 'site_hosts': ['example.dev'], 'admin_email': 'm33@example.dev'}}) => {"changed": true, "cmd": ["wp", "core", "is-installed", "--allow-root"], "delta": "0:00:00.924083", "end": "2015-05-14 16:41:02.733370", "item": {"key": "example.co", "value": {"admin_email": "m33@example.dev", "admin_password": "admin", "admin_user": "admin", "env": {"db_name": "a6_dev", "db_password": "example_dbpassword", "db_user": "example_dbuser", "wp_env": "development", "wp_home": "http://example.dev", "wp_siteurl": "http://example.dev/wp"}, "local_path": "../site", "multisite": {"enabled": true, "subdomains": true}, "repo": "https://m33@bitbucket.org/example/a6-app.git", "site_hosts": ["example.dev"], "site_install": true, "site_title": "example Dev", "ssl": {"enabled": false}, "system_cron": true}}, "rc": 1, "start": "2015-05-14 16:41:01.809287", "warnings": []}
stderr: PHP Warning:  Unterminated comment starting line 16 in phar:///usr/bin/wp/php/wp-cli.php(23) : eval()'d code on line 16

WordPress database error Table 'a6_dev.wp_blogs' doesn't exist for query SELECT * FROM wp_blogs WHERE domain = 'example.dev' AND path = '/' made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), require('wp-includes/ms-settings.php'), get_site_by_path
PHP Notice:  Undefined property: stdClass::$public in /srv/www/example.co/current/web/wp/wp-includes/ms-settings.php on line 184
Notice: Undefined property: stdClass::$public in /srv/www/example.co/current/web/wp/wp-includes/ms-settings.php on line 184

WordPress database error Table 'a6_dev.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'site_name' AND site_id = 1 made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), require('wp-includes/ms-settings.php'), get_site_option

WordPress database error Table 'a6_dev.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'siteurl' AND site_id = 1 made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), wp_cookie_constants, get_site_option
...ignoring

I read here that it may be related to using the same db user as I used on the original machine (I had changed all the db info originally) so I completely removed bedrock-ansible from my machine and recloned my bedrock git repository (just in case) and stuck with the default user for the db. However, that did not work either.

I assumed running vagrant destroy would completely obliterate the db as well as the vm but it looks like that could be wrong.

Sorry if this is bedrock 101. with such a new workflow, it’s hard to get to grips with the way everything works.

Let me know if you have any thoughts on the next step to take.

This is different than the db user issue some people have.

It looks like this could be an issue with WP-CLI and multisite. I’m guessing you wanted to have multisite enabled?

stderr: PHP Warning:  Unterminated comment starting line 16 in phar:///usr/bin/wp/php/wp-cli.php(23) : eval()'d code on line 16

This is an actual error and not good. Guessing that’s what the problem is. You could try upgrading WP-CLI on the VM.

Thanks for replying. You always come through and I want to you to know that I recognize that. I’m sure you don’t get paid for this!

Yes, I definitely want multisite for my project. I heard that there weren’t many issues with using it and bedrock but it’s given me nothing but trouble since I swtiched. I am new to bedrock so that could be it.

I ssh’d into the vm after getting vagrant up. I then followed the update instructions on http://wp-cli.org/

everything updated but I’m still getting “Error establishing a database connection” when visiting the site.

Been at figuring out ansible for a couple weeks now. Would ditching bedrock-ansible and just using desktop server and the rest of bedrock be a better solution?

Update: I tried a completely new install on another folder using all the default settings. The only thing I changed was following the instructions here: https://github.com/roots/bedrock-ansible/wiki/Multisite

before installing the roles and then vagranting up.

I got the same error:

TASK: [wordpress-install | WP installed?] ************************************* 
failed: [default] => (item={'key': 'example.com', 'value': {'site_install': True, 'admin_user': 'admin', 'local_path': '../site', 'system_cron': True, 'repo': 'git@github.com:roots/bedrock.git', 'ssl': {'enabled': False}, 'multisite': {'enabled': True, 'subdomains': True}, 'site_title': 'Example Site', 'admin_password': 'admin', 'env': {'db_name': 'example_dev', 'wp_env': 'development', 'domain_current_site': 'example.com', 'db_user': 'example_dbuser', 'db_password': 'example_dbpassword', 'wp_home': 'http://example.dev', 'wp_siteurl': 'http://example.dev/wp'}, 'site_hosts': ['example.dev'], 'admin_email': 'admin@example.dev'}}) => {"changed": true, "cmd": ["wp", "core", "is-installed", "--allow-root"], "delta": "0:00:00.328093", "end": "2015-05-15 15:16:52.381228", "item": {"key": "example.com", "value": {"admin_email": "admin@example.dev", "admin_password": "admin", "admin_user": "admin", "env": {"db_name": "example_dev", "db_password": "example_dbpassword", "db_user": "example_dbuser", "domain_current_site": "example.com", "wp_env": "development", "wp_home": "http://example.dev", "wp_siteurl": "http://example.dev/wp"}, "local_path": "../site", "multisite": {"enabled": true, "subdomains": true}, "repo": "git@github.com:roots/bedrock.git", "site_hosts": ["example.dev"], "site_install": true, "site_title": "Example Site", "ssl": {"enabled": false}, "system_cron": true}}, "rc": 1, "start": "2015-05-15 15:16:52.053135", "warnings": []}
stderr: PHP Notice:  Undefined index: HTTP_HOST in /srv/www/example.com/current/web/wp/wp-includes/ms-settings.php on line 30
Notice: Undefined index: HTTP_HOST in /srv/www/example.com/current/web/wp/wp-includes/ms-settings.php on line 30
WordPress database error Table 'example_dev.wp_blogs' doesn't exist for query SELECT * FROM wp_blogs WHERE domain = '' AND path = '/' made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), require('wp-includes/ms-settings.php'), get_site_by_path
PHP Notice:  Undefined property: stdClass::$public in /srv/www/example.com/current/web/wp/wp-includes/ms-settings.php on line 184
Notice: Undefined property: stdClass::$public in /srv/www/example.com/current/web/wp/wp-includes/ms-settings.php on line 184
WordPress database error Table 'example_dev.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'site_name' AND site_id = 1 made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), require('wp-includes/ms-settings.php'), get_site_option
WordPress database error Table 'example_dev.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'siteurl' AND site_id = 1 made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/php/wp-cli.php'), require('phar:///usr/bin/wp/php/wp-settings-cli.php'), wp_cookie_constants, get_site_option
...ignoring

I haven’t tried doing an install without the multisite fix instructions but I’ll try that next. From this point, it looks like I’m doing something wrong with the instructions on multisite or it’s causing the error.

Thanks for helping to debug this. There may be an actual bug in bedrock-ansible to do with this. Multisite is one of the least tested options unfortunately. Paging @ben since he worked on this most recently.

Of course you can always use Bedrock without the Ansible project.

NP. I’m glad I can help out. I really appreciate you trying to drag the wp dev community into 2015.

Update 2:

  • I deleted the last install from my machine and destroyed the vm.
  • I then cloned both repos again Cd into bedrock-ansible ran ansible-galaxy install -r requirements.yml -p vendor/roles
  • changed multisite and subdomains to true in the group_vars development file
    but left everything else as default. then ran vagrant up
  • Note that I didn’t follow the multisite instructions from the wiki this time.

Everything worked fine except getting an error at the same spot:

TASK: [wordpress-install | WP installed?] ************************************* 
failed: [default] => (item={'key': 'example.com', 'value': {'site_install': True, 'admin_user': 'admin', 'local_path': '../site', 'system_cron': True, 'repo': 'git@github.com:roots/bedrock.git', 'ssl': {'enabled': False}, 'multisite': {'enabled': True, 'subdomains': True}, 'site_title': 'Example Site', 'admin_password': 'admin', 'env': {'db_name': 'example_dev', 'wp_env': 'development', 'db_user': 'example_dbuser', 'db_password': 'example_dbpassword', 'wp_home': 'http://example.dev', 'wp_siteurl': 'http://example.dev/wp'}, 'site_hosts': ['example.dev'], 'admin_email': 'admin@example.dev'}}) => {"changed": true, "cmd": ["wp", "core", "is-installed", "--allow-root"], "delta": "0:00:00.303623", "end": "2015-05-15 19:43:28.788842", "item": {"key": "example.com", "value": {"admin_email": "admin@example.dev", "admin_password": "admin", "admin_user": "admin", "env": {"db_name": "example_dev", "db_password": "example_dbpassword", "db_user": "example_dbuser", "wp_env": "development", "wp_home": "http://example.dev", "wp_siteurl": "http://example.dev/wp"}, "local_path": "../site", "multisite": {"enabled": true, "subdomains": true}, "repo": "git@github.com:roots/bedrock.git", "site_hosts": ["example.dev"], "site_install": true, "site_title": "Example Site", "ssl": {"enabled": false}, "system_cron": true}}, "rc": 1, "start": "2015-05-15 19:43:28.485219", "warnings": []}
...ignoring

That error is expected. It’s why we ignore it. Basically WP-CLI returns 0 (error) if wp core is-installed returns false and Ansible treats it an error so we skip it. Seems like everything is working fine if that’s all you get (and the site works after).

I was running into the original error too during a vagrant provision - the WordPress database error Table 'sometable' doesn't exist error during the [wordpress-install | WP installed?] task.

It looks like my problem was an mu-plugin that was calling update_option() via the init action. Obviously, that’s not a good place to do that for a few reasons, one of which is that the options table won’t exist before core install… so the error makes perfect sense.

So for anybody else finding this, make sure you don’t have any code querying the db on init.

2 Likes