Customize-everything

CustomBuild custom configuration

CustomBuild is an extremely progressive tool that manages software but also provides an elegant way to customize everything. Referencing to /usr/local/directadmin/custombuild as the working directory - the configure/ directory contains default configs:

ap2
clamav
curl
custombuild
dovecot
fastcgi
fpm
libxml2
libxslt
litespeed
modsecurity
nginx
nginx_reverse
opcache
openlitespeed
php
phpmyadmin
proftpd
pureftpd
rspamd
spamassassin
suhosin
systemd

To build a software with a custom flags or options, you have to create a custom/ directory (and structure), copy the existing software's config, and modify it in custom/ .

For example, rebuilding Nginx with "--with-http_sub_module" compilation flag:

cd /usr/local/directadmin/custombuild
mkdir -p custom/nginx/
cp -fp configure/nginx/configure.nginx custom/nginx/configure.nginx

Edit the custom/nginx/configure.nginx file, add --with-http_sub_module\, and build Nginx:

./build nginx

Regular configuration files have to be customized in the same way. For example, Apache MPM settings:

cd /usr/local/directadmin/custombuild
mkdir -p custom/ap2/conf/extra/
cp -fp configure/ap2/conf/extra/httpd-mpm.conf custom/ap2/conf/extra/httpd-mpm.conf

Edit the custom/ap2/conf/extra/httpd-mpm.conf file as desired and then apply changes with:

./build rewrite_confs

More in relevant sections for services you need.

Starting from version 2369, pre/post hooks were implemented.

CustomBuild lets you overwrite any call and execute pre/post hooks etc.

You can now:

  1. Create your own custom command or modify an already existing one with whatever you want by using a pre-call hook and 'exiting' at the end. Let's say you want to create a command named "examplecommand". Then you'd need to do the following:
mkdir -p /usr/local/directadmin/custombuild/custom/hooks/examplecommand/pre/
cd /usr/local/directadmin/custombuild/custom/hooks/examplecommand/pre

Add the following contents to examplescript.sh (name it whatever you prefer):

#!/bin/sh

echo "Testing if the pre hook script works" 
exit 4

Note the "exit" entry. Without it the build script would continue functioning as normal and give unnecessary output.

Run the build script to test if it works:

/usr/local/directadmin/custombuild/build examplecommand

You should get similar output:

Executing '/usr/local/directadmin/custombuild/custom/hooks/examplecommand/pre/examplescript.sh'...
Testing if the pre hook script works
Hook exited with error code: 4. Exiting...
  1. Execute anything before/after a ./build script command. For example, after update_versions, you could mail yourself/server-owner a message that updates have been applied.

All CustomBuild variables are reachable via 'hooks'. The structure is /usr/local/directadmin/custombuild/custom/hooks/command/pre/anything.sh (pre could be post as well). To modify an already existing command ("versions" in this example), try adding custom/hooks/versions/pre/test.sh with the following content:

#!/bin/sh
echo "Oh yeah! My PHP version is ${PHP1_RELEASE_OPT}, and I'm just exiting with a strange error code instead of listing the version updates...."
exit 4

If you'd like to just finish the function, "return" instead of "exit" could be used.

To run something after OpenLitespeed is built, you would need:

cd /usr/local/directadmin/custombuild/
mkdir -p custom/hooks/openlitespeed/post
vi custom/hooks/openlitespeed/post/myscript.sh

And add your code like:

#!/bin/sh
echo "This is a post openlitespeed script"

The pre-scripts are always executed while post-scripts depends on if build finished successfully or not.

I wish to add my own webapps Alias pointing to /var/www/html

If you have your own alias which you need to add, let's call it /billing, and you wish to point it to

/var/www/html/

then you can add it as a location Alias for all domains using the custom/webapps.list fileopen in new window.

  1. To set it up, run the following:
cd /usr/local/directadmin/custombuild
mkdir custom
  1. Then add the custom values to the file:
echo "billing=billing_system" >> custom/webapps.list
  1. Lastly, rewrite the configs for Apache or Nginx:
./build rewrite_confs

These changes should show up in one of these files, depending on if you're using Apache or Nginx:

/etc/httpd/conf/extra/httpd-alias.conf
/etc/nginx/webapps.conf

NOTE CustomBuild will always set the "webmail" Alias to the currently selected webmail_linkopen in new window from the directadmin.conf (possibly an internal default), so if you wish to change where /webmail goes, use the webmail_link featureopen in new window to change it, and issue the config rewrite demonstrated in step 3.

Custom items value in virtualhost template

The custom_domain_items feature lets you set custom per-domain variables.

This change allows those variables which are set in the domain's config file: /usr/local/directadmin/data/users/username/domains/domain.com.conf

to be available as a token in the User's httpd.conf templates with the token syntax:

|CUSTOM_DOMAIN_ITEM_%s|

where %s is swapped with the custom item name, and that whole token, when used in the templates, will be swapped with the value from the domain.com.conf.

For example, if you have this file /usr/local/directadmin/data/admin/custom_domain_items.conf, loaded with:

banana=type=checkbox&string=Custom 1&desc=Yellow&checked1=yes

Then you can use the token:

|CUSTOM_DOMAIN_ITEM_banana|

in the virtual_host2.conf templates (and subdomains, and pointers).

Note that this token will only be available if:

banana=anything

is actually set in the domain.com.conf file.

If it's unset (name does not exist), then the token will not be set.

An sample (invalid) example usage of the token might be:

|*if CUSTOM_DOMAIN_ITEM_banana="ON"|
	Options +banana
|*endif|

The Custom Package Items is also available in the templates.

Token will be |PACKAGE| which might be the package name, 'custom' or possibly blank in rare cases.

Subdomain DocumentRoot override

To change a document root for a subdomain, you can log into DirectAdmin as the user that owns the subdomain, and then navigate as follows:

Dashboard > Sub-Domains Setup > Document Root Override

Upon clicking Sub-Domains Setup, you should see an option to edit the document root (an edit icon that resembles a pencil), and upon clicking this option, will be taken to the Document Root Override path noted above.

You will also have the option within this interface to change the subdomain's PHP version, too (feature implemented in DirectAdmin Version Version 1.60.4).

The new optional file was implemented in DirectAdmin Version 1.59.5 (the aforementioned GUI implemented in DirectAdmin Version 1.61.0):

/usr/local/directadmin/data/users/USERNAME/domains/DOMAIN.COM.subdomains.docroot.override

where the file might show this for sub.DOMAIN.COM :

sub=public_html=/domains/DOMAIN.COM/public_html&private_html=/domains/DOMAIN.COM/private_html

where "sub" is the index on the left, matching up with the subdomain in question.

While writing the VirtualHost for a subdomain, if the file exist, "sub" exist, and the given public_html or private_html variable exist for that VH, DA will use the listed path as an override, relative to the User's home directory.

In the above example, the DocumentRoot would end up being:

  • ServerName www.sub.DOMAIN.COM
  • DocumentRoot /home/USERNAME/domains/DOMAIN.COM/public_html

The one of the public_html and private_html values are optional, in case you wanted to override one part, but not the other.

Last Updated: