Provision with a non-WordPress site

I’ve inherited a server with 6 sites on, only two of them are WordPress based, the others are simple one page HTML builds.

I’ve setup Trellis and Bedrock for the two WP sites. I’m now trying to find out what I need to add/change to provision the other site directories, which will not contain a WordPress site.

WordPress Sites config:

wordpress_sites:
  mywpsite.co.uk:
    site_hosts:
      - canonical: mywpsite.test
        redirects:
          - www.mywpsite.test
    local_path: ../mywpsite # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: admin@example.test
    multisite:
      enabled: false
    ssl:
      enabled: true
      provider: self-signed
    cache:
      enabled: false

local_path: ../mywpsite has the bedrock setup as normal.

HTML sites
I suspect I still need to add an entry here for the non-wp site still, therefore I would have:

wordpress_sites:
  mywpsite.co.uk:
    site_hosts:
      - canonical: mywpsite.test
        redirects:
          - www.mywpsite.test
    local_path: ../mywpsite # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: admin@example.test
    multisite:
      enabled: false
    ssl:
      enabled: true
      provider: self-signed
    cache:
      enabled: false
  myhtmlsite.co.uk:
    site_hosts:
      - canonical: myhtmlsite.test
        redirects:
          - www.myhtmlsite.test
    local_path: ../myhtmlsite # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: admin@example.test
    multisite:
      enabled: false
    ssl:
      enabled: true
      provider: self-signed
    cache:
      enabled: false

Inside the ../myhtmlsite directory, I suspect I should keep the /web directory and then simply drop in the HTML files there. Not needing to include any of the other regular files added by composer-bedrock?

Normally, I would also be setting passwords inside: trellis/group_vars/development/vault.yml - the HTML sites need no database or passwords.

I made the above changes, tried a vagrant provision on my local and got the following:

Invalid WordPress sites configuration: site names in wordpress_sites must

have matching entry in vault_wordpress_sites.

Sites without a matching vault entry:

  • myhtmlsite.co.uk

Update group_vars/development/vault.yml to continue.

Docs: WordPress Sites | Trellis Docs | Roots

fatal: [default]: FAILED! => {“changed”: false}

If it creates a database but doesn’t use it, that is fine, just not sure if there is a way to simply ignore the database/wordpress creation steps for this scenario?

I may be wrong but I think a couple of the trellis deploy steps will fail if it’s not a wordpress site - ie. if it can’t connect to the database. + it seems like it may overcomplicate things in the longterm.

You may be better off rolling your own deploy script using git, perhaps something like this - http://nicolasgallagher.com/simple-git-deployment-strategy-for-static-sites/

Or (what I’d do) is move the static sites to their own repo’s and use a serverless host like Netlify (free) https://www.netlify.com/ to manage all that stuff for you!

1 Like

:thinking: I never thought of creating “fake” sites entries but like @slowrush said I’d be very surprised if it could deploy since there’s many tasks which make a lot of hardcoded assumptions that it’s a WP site.

I think these sites will eventually be converted into WordPress sites, and based on a few other factors/restrictions. I had an idea for now:

Provision as a WordPress site like normal, then inside its /site directory, create a /static folder which contains the static site. Then, what I ideally want to do is the following:

/trellis/nginx-includes/mynewsite.co.uk/root.conf.j2

# {{ ansible_managed }}

server {
  root  /srv/www/mynewsite.co.uk/current/web/static;
}

Tell NGINX to direct all traffic for this domain to the /static directory inside /web.

I’ve attempted this but it failed because I am trying to use the server directive.

non-zero return code

nginx: [emerg] "server" directive is not allowed here in

/etc/nginx/includes.d/mynewsite.co.uk/root.conf:3

nginx: configuration file /etc/nginx/nginx.conf test failed

fatal: [default]: FAILED! => {"changed": true, "cmd": ["nginx", "-t"], "delta": "0:00:00.057815", "end": "2020-05-23 10:00:04.661198", "rc": 1, "start": "2020-05-23 10:00:04.603383", "stderr_lines": ["nginx: [emerg] \"server\" directive is not allowed here in /etc/nginx/includes.d/mynewsite.co.uk/root.conf:3", "nginx: configuration file /etc/nginx/nginx.conf test failed"], "stdout": "", "stdout_lines": []}

[“nginx: [emerg] "server" directive is not allowed here in /etc/nginx/includes.d/mynewsite.co.uk/root.conf:3”

This all means there is a WP site sitting in the background not being used, but that’s fine with me currently. It won’t be accessible anyway if I can get the above to work.

I’ve tried following the nginx child templates guide, still no luck:

/trellis/nginx-includes/mysite.co.uk.conf.child

{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}

{% block change_nginx_root_path %}

# Change NGINX root path
server {
  root /srv/www/mysite.co.uk/current/web/static;
}

{% endblock -%}

/trellis/group_vars/development/wordpress_sites.yml

mysite.co.uk:
site_hosts:
- canonical: mysite.test
redirects:
- www.mysite.test
local_path: …/mysite # path targeting local Bedrock site directory (relative to Ansible root)
nginx_wordpress_site_conf: nginx-includes/mysite.co.uk.conf.child

Loaded the domain: mysite.test - Still displaying the WordPress site as normal, not loading content from the /static directory instead.

Update - SOLVED!
I had a formatting error which was stopping the above from running, this is why no changes were seen. When I managed to pass that, I again got the server directive not allowed. So I updated the following:

/trellis/nginx-includes/mysite.co.uk.conf.child

{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}

{% block change_nginx_root_path %}

# Change NGINX root path
root /srv/www/mysite.co.uk/current/web/static;

{% endblock -%}

I removed server { because the output of all this is already output inside of the server directive. I was doubling up.

I now see my static site directory being loaded under the domain!

1 Like

That’s really interesting! So, to recap:

You create bedrock-based WP sites as usual but basically just to satisfy Trellis’ requirements. Then you put the entire static site contents in a static directory (at the root of the WP repo in - site). Finally you create a new Nginx include which just sets the root to the static dir and it all works as a normal WP site would :smile:

Yep haha.

Two of the sites are WordPress builds. The rest are static builds, however, these are likely to be converted to WP eventually.

I wanted to keep just the one server and get it ready for both types of sites for now.

I’m sure there was a better way, this worked for now, and I’m going to try this again without having to install WP etc too. Will update later on that progress.

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.

@JordanC26 I used this method for a quick-and-dirty subdomain redirect. Thanks for the tip!

1 Like