Search code examples
apachechef-infracookbook

Chef set DocumentRoot in httpd recipe


Using https://community.opscode.com/cookbooks/httpd/versions/0.1.5

Does anyone know how to set DocumentRoot ? Property ?

I'm currently using

httpd_service "default" do
  listen_ports ['81']
  action :create
end

which produces

ServerName centos65x64
ServerRoot /etc/httpd
PidFile /var/run/httpd/httpd.pid
User apache
Group apache
Timeout 400
ErrorLog /var/log/httpd/error_log
LogLevel warn
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
DefaultType None
HostnameLookups off

Listen 0.0.0.0:81
Include conf.d/*.conf
Include conf.d/*.load

In httpd.conf, but i'm not sure exactly how to set the DocRoot.


Solution

  • The httpd_config resource included in the cookbook will deploy a httpd config file from template to a httpd instance's config directory, to be included when httpd is run. You can configure your VirtualHosts or the main server from these templates as opposed to say, setting a node attribute that the cookbook picks up and generates a virtualhost for you.

    This means you can create an Erubis template for your VirtualHost config. There is an of such a config in the cookbook tests...

    <VirtualHost *:81>
        ServerAdmin mike@patel.net
    
        DocumentRoot /var/www
        CustomLog /var/log/apache/mike-patel-access.log combined
    
        <Directory />
            Options FollowSymLinks
            AllowOverride None
        </Directory>
    
        <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
    
        LogLevel warn
    </VirtualHost>