[TOP TIP] Virtual Hosting - without a control panel!

I'm sure it has happened to you, one day you realise that your hosting control panel is so bloated and complicated, you wish you had a nice clean system, without the bloat. Just you and a command-line shell. All done via ssh, from the office, from home, from the beach, or even your mom's basement. This magic is now possible, its at your fingertips!

The Hogwarts School of Linux Witchcraft and Shell-Wizardry is proud to present a magical PHP script that allows you to run a fully capable web/email hosting server, by using just a minimal CentOS 7 install.

Requirements

We assume that your brand new CentOS 7 is a minimal installation, so it should not have anything installed yet. So go ahead and install the required libraries. The installation of the Smarty library must be done as a second step, because it depends on the package epel-release to be installed first.

yum install php php-pdo php-mbstring php-pdo php-mbstring epel-release unzip wget
yum install php-Smarty

Download & install

Download the PHP script from here, decompress under /root/ and rename the folder for easier access.

wget -O /root/master.zip 'https://github.com/noumenia/aetolos/archive/master.zip'
unzip /root/master.zip -d /root/
mv /root/aetolos-master /root/aetolos

O beautiful Maria db!

Since we assume that this is a minimal clean install of CentOS 7, then Maria needs an extra step to get her to play with you, if you do not need an SQL database then skip this step.

systemctl enable mariadb
systemctl start mariadb
/usr/bin/mysql_secure_installation

You will set root's password and you will be asked to set a set of questions (answer yes to all of them). At this point you will want to create a /root/.my.cnf file with your permissions to access Maria with full privileges.

[client]
default-character-set="utf8"
user="root"
pass="your password as chosen in the previous step"

Advanced Daemons & Dragons

The script supports many server daemons and protocols but in most cases there is no need to use all of them. Each supported server daemon is a "module" so from now on we'll talk about modules. Currently, the supported modules are: apache, clamav, dehydrated, dovecot, haproxy, mariadb, nsd, opendkim, php, postfix, postgrey, roundcube, spamassassin, virtualhost.

Choose which ones you want and which ones you don't. For example, a typical stand-alone server won't need haproxy and a typical linode server that uses linode's DNS manager won't need nsd. Disable the modules you do not need like this:

/root/aetolos/aetolos --verbose --disable=haproxy
/root/aetolos/aetolos --verbose --disable=nsd

If you want to use SSL/TLS certificates from Let's Encrypt, then enable the dehydrated module. It is highly recommended to do this, the certificates are free and valid for all modern browsers. You will need to provide a registration email address.

/root/aetolos/aetolos --verbose --enable=dehydrated
/root/aetolos/aetolos --verbose --module=dehydrated --registration-email=admin@example.tld

The final command is to execute the system setup, which will download any required packages via yum and setup the initial configuration files.

/root/aetolos/aetolos --verbose --setup

Virtual hosts at the tip of your magic wand!

So how do you wave that wand to create virtual hosts? Pretty simple, just add water… erm… I mean the add command:

/root/aetolos/aetolos --verbose --module=virtualhost --add-virtualhost=mydomain.tld

Wait a minute! How about the Apache virtualhost? or how about postfix email domains? well they are automatically setup, magic right?

How about adding a new database for this virtual host?

/root/aetolos/aetolos --verbose --module=mariadb --virtualhost=mydomain.tld --add-db=mywordpress
/root/aetolos/aetolos --verbose --module=mariadb --virtualhost=mydomain.tld --add-dbuser=myuser --password="mypassword" --grant="@mywordpress"

In the above steps, we created a virtual host mydomain.tld, which will exist under /home/mydomaintld/ with a database named "mydomaintldmywordpress" (notice how our initial database name is now prefixed) and with a database user "mydomaintldmyuser" (also prefixed).

We may add email addresses, like this:

/root/aetolos/aetolos --verbose --module=dovecot --virtualhost=mydomain.tld --add-email=postmaster@mydomain.tld --password="mypassword" --quota=10240

Reconfigure and restart

If you have enabled the dehydrated module, you need to accept the terms and conditions of Let's Encrypt, otherwise skip this step:

/root/dehydrated/dehydrated --register --accept-terms

Now that everything has been setup properly, we may re-generate all the configuration files and enable/restart the relevant daemon services. Be sure to modify the systemctl commands with your own services.

/root/aetolos/aetolos --verbose --setup
systemctl enable clamd mariadb opendkim spamass-milter httpd postfix dovecot
systemctl restart clamd mariadb opendkim spamass-milter httpd postfix dovecot

If you want, you may take a look at the various command-line parameters of the script:

/root/aetolos/aetolos --help

1 Reply

Very nice script! Thanks for the great work

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct