Custom virtual host Apache configuration for CPanel/WHM

Here’s how I applied some custom virtual host configuration for a CPanel account. Note that you need to have root access to the box. (Or get your hosting company to do it for you)

Example user: foobar
Example domain:

Create the directory structure/usr/local/apache/conf/userdata/std/2/foobar/

std = standard config (ssl for secure hosts)
2 = major version number of apache
foobar = username of the account = domain of the account

Create a vhost.conf file. The file can be any name, but must have the .conf extension. In this file put the override config. For example:

  DocumentRoot /home/foobar/newrooot
  CustomLog /home/foobar/logs/foobar.log combined

Note the lack of the opening and closing directives.

SSL certificate generation with self signing CA

Steps completed on Ubuntu 10.04

Generate CA (CN should have CA suffix to prevent conflict)

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt

generate server key and request (CSR)

openssl genrsa -des3 -out server.key 4096
openssl req -new -key server.key -out server.csr

Generate CRT from CSR

openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt

Make server.key with no passphrase for Apache

openssl rsa -in server.key -out server.key.insecure
mv server.key
mv server.key.insecure server.key

Set permissions

chown root server.key
chmod 600 server.key

Enabling Apache mod_rewrite on Ubuntu 9.10

I assume you have Apache 2 installed and running on your server.

To list the loaded modules:

sudo apache2ctl -M

Enable mod_rewrite:

locate   // make a note of the location
cd /etc/apache2/mods-enabled
sudo touch rewrite.load
sudo vi rewrite.load

Add this line, using the path of the module found using locate:

LoadModule rewrite_module /usr/lib/apache2/modules/

Restart apache.