Missing step installing bedrock?

Hey, I just finished setting Bedrock up with Scotch Box. I’m looking to possibly run bedrock on my shared host (SiteGround), and I wanted to try setting up on something other than Trellis.

Here’s a fairly in depth step by step.

1) Clone Scotch Box to a project folder

git clone https://github.com/scotch-io/scotch-box.git myproject

2) CD to the project directory, then clone Bedrock

cd myproject
git clone https://github.com/roots/bedrock.git

3) Modify the Vagrantfile

Scotch Box uses ‘public’ for the site root, my host uses ‘public_html’, so I wanted that to be straightened out from the start. So I added this to the vagrant file -

    #change public to public_html
    config.vm.provision "shell", inline: <<-SHELL
        mv /var/www/public /var/www/public_html
        sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/000-default.conf
        sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/scotchbox.local.conf
        sudo service apache2 restart
    SHELL

Also, Scotch doesn’t ship with Xdebug, which I wanted, so I added -

    # install Xdebug
    config.vm.provision "shell", inline: <<-SHELL
        sudo apt-get install php5-xdebug
        sudo service apache2 restart
    SHELL

and it comes with Composer installed, but not added to the path, so I wanted that as well.

    # add composer to PATH
    config.vm.provision "shell", inline: <<-SHELL
        export PATH="~/.composer/vendor/bin:$PATH" 
    SHELL

All of those solutions I found here.

Finally, on my first attempt I ran into a load of notices and warnings in WP-Admin, I searched and found this thread, with this solution. So, from the Trellis Vagrantfile, I added:

    # Fix for slow external network connections
    config.vm.provider :virtualbox do |vb|
        vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
        vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
    end

Which took care of the errors and made the WP backend on Scotch Box much quicker. It really was quite slow prior to adding this.

Here’s my full, modified Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "192.168.33.10"
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
   
    #install Xdebug
    config.vm.provision "shell", inline: <<-SHELL
        sudo apt-get install php5-xdebug
        sudo service apache2 restart
    SHELL

    #change public to public_html
    config.vm.provision "shell", inline: <<-SHELL
        mv /var/www/public /var/www/public_html
        sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/000-default.conf
        sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/scotchbox.local.conf
        sudo service apache2 restart
    SHELL

    #add composer to PATH
    config.vm.provision "shell", inline: <<-SHELL
        export PATH="~/.composer/vendor/bin:$PATH" 
    SHELL

    # Fix for slow external network connections
    config.vm.provider :virtualbox do |vb|
        vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
        vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
    end

end

4) Set up the correct directory structure

Next I had to move stuff around in Bedrock where I wanted. Bedrock uses ‘web’ as its site root, so everything in web needed to move to public_html

Scotch comes with a handy index file with various helpful info, MySQL user and password, SSH info, etc. I wanted to keep that, so this command just renames it so it can live peacefully with the WP index.php I’m about to move in.

mv public_html/index.php public_html/info.php

This command moves the contents of /web into /public_html - * is a wildcard, it means grab everything. It won’t grab dot files though, so if you want them you also have to pass bedrock/.* in.

mv bedrock/web/* public_html 

This command deletes the (now empty) web directory. (note, I use trash, hence no rm -rf)

trash bedrock/web

Also, I removed the Scotch git stuff -

trash .git .gitignore

Next I needed to move the contents of the Bedrock directory up one level. Passing . in as the last argument just means to move the targets up one directory. Also, the only dot file I wanted was the .env.example, so I didn’t pass a wildcard there. So, move bedrock with a wildcard for all the files, and move the .env, all up one directory.

mv bedrock/* bedrock/.env.example .

Rename .env.example to .env (I kept a copy for reference)

cp .env.example .env

And, trash the Bedrock directory.

trash Bedrock

5. Update composer.json and application.php

Now that my directories were updated, I needed to let Bedrock know that I wanted to use /public_html as my web root, not /web - again, this whole experiment is in preparation for using this on my shared SiteGround hosting.

2 files needed updating, composer.json and config/application.php

In both files, every instance of web needed to be changed to public_html

I’m generally much quicker in my IDE, but I’ve also been trying to get more comfortable with Vim, because it’s easier to do quick stuff with when you’re already in the command line, and it’s kind of cool, and a good tool to know.

So, I believe there’s four occurrences that need to be changed in composer.json, at the bottom of the file, and one at the top of application.php - be careful if doing find/replace that you don’t mistakenly overwrite the $webroot_dir variables in application.php In Vim I used :%s/web/public_html/gc to confirm each change.

6. Setup the .env file

Finally, I just needed to fill out the .env file with the correct info. Here’s my .env for Scotch Box - (be sure to generate your own salts!)

DB_NAME='scotchbox'
DB_USER='root'
DB_PASSWORD='root'
DB_HOST='localhost'

WP_ENV='development'
WP_HOME='http://scotch.dev'
WP_SITEURL='http://scotch.dev/wp'

AUTH_KEY='salts are really long'
SECURE_AUTH_KEY='so I am not pasting them here'
LOGGED_IN_KEY='because they look so obnoxious'
NONCE_KEY='but go generate your own'
AUTH_SALT='at this URL'
SECURE_AUTH_SALT='http://api.wordpress.org/secret-key/1.1/salt/'
LOGGED_IN_SALT='And paste them here like this'
NONCE_SALT='between single quotes'

7. Composer install

Next, I ran composer install and everything was cool but I got a warning or something telling me to run composer update so I did that as well.

8. Edit hosts file
Oh, last thing - - I had to add 192.168.33.10 to my hosts file, to point at my URL, scotch.dev -
sudo vim /private/etc/hosts/

add: 192.168.33.10 scotch.dev

And flush the DNS cache -
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

8. Vagrant up

That’s everything, next I ran vagrant up, the box booted up, I went to scotch.dev in my browser, ran through the installer, and everything worked, and was awesome.

All told, it took me 2 attempts, and about 2, maybe 2 and a half hours to work my way through it. It was a good learning experience I’d guess I could do it again in about ten minutes now that I’ve done it once correctly.

Next time I’ll try to get it up and running on a subdomain, on my shared host, then I’ll start looking into deployment options.

Anyway, hope that helps a bit.

3 Likes