Virtualmin + Drupal 7.x on Ubuntu 12.04 HOWTO
Virtualmin is a powerful and flexible web hosting control panel for Linux and UNIX systems based on the well-known Open Source web-based systems management GUI, Webmin. By using Virtualmin we can simply create a virtual hosting environment for Drupal development/hosting within few clicks, including both Linux user account, Apache virtualhost, MySQL database, PHP5 in FCGI, FTP access, and even more.
This HOWTO will guide you though the Virtualmin installation on top of Ubuntu 12.04, then demonstrate the virtual hosting functionality by installing a Drupal 7.x website.
Before start I will assume you have a clean Ubuntu Server 12.04 installed with minimal packages requirement. It is strongly recommend to install Virtualmin for a new host, as it will modify a lot of default settings; from the other point of view, don't install Virtualmin on top of an online production that already well configured ;-)
Configure hostname
You should double confirm the system hostname if it looks good. For example if this host is www.example.com, the /etc/hostname can be:
host.example.com
The /etc/hosts should also be:
127.0.0.1 localhost.localdomain localhost
Now reboot your system, and check the system hostname with command:
hostname
Ensure all APT source enabled
By default some of your APT source may be disabled, so let's enable them with:
sed -i 's/^#\s*deb/deb/g' /etc/apt/sources.list
Install Virtualmin with GPL installation script (not available yet on 2012-04-30)
Just simply access http://www.virtualmin.com/download.html and download the Virtualmin installation script with wget:
sh <(curl -s http://software.virtualmin.com/gpl/scripts/install.sh)
Follow the console online help message and it will update your apt source list, download required packages, install Virtualmin + Webmin + Usermin, change some configuration files, especially replace Exim4 with Postfix, and so on.
Once it get ready you should able to access Virtualmin (i.e. Webmin) interface with HTTPS + port 10000, e.g. https://www.example.com:10000. Don't forget to reboot the system before next step.
Install Virtualmin manually
Still you should download the install.sh as reference:
wget http://software.virtualmin.com/gpl/scripts/install.sh
You may study its detail and clone most of the steps manually; but I will some how try to automate it here:
cat >> /etc/apt/sources.list.d/virtualmin.list <<-EOF
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
deb http://software.virtualmin.com/gpl/ubuntu/ virtualmin-precise main
deb http://software.virtualmin.com/gpl/ubuntu/ virtualmin-universal main
EOF
wget -q http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key add -
wget -q http://software.virtualmin.com/lib/RPM-GPG-KEY-virtualmin -O- | sudo apt-key add -
wget -q http://software.virtualmin.com/lib/RPM-GPG-KEY-webmin -O- | sudo apt-key add -
aptitude -y install ubuntu-extras-keyring && \
aptitude update && \
aptitude -y full-upgrade && \
tasksel install openssh-server && \
tasksel install server && \
tasksel install mail-server && \
aptitude -y install usermin webmin && \
aptitude update && aptitude -y full-upgrade && aptitude autoclean && aptitude clean
If you are using Ubuntu 12.04 LTS, I would recommend you to install the latest version of supported kernel:
aptitude -y install linux-generic-lts-saucy
If you are using Ubuntu 12.04 LTS on AWS EC2, I would recommend you to install Linux kernel extra modules for virtual machines:
aptitude -y install linux-image-extra-virtual
aptitude -y install apache2 apache2-doc apache2-mpm-prefork apache2-suexec-custom awstats bind9 clamav clamav-base clamav-daemon clamav-docs clamav-freshclam clamav-testfiles dovecot-common dovecot-imapd dovecot-pop3d iptables libapache2-mod-fcgid libapache2-mod-php5 libapache2-mod-ruby libapache2-svn libcrypt-ssleay-perl libdbd-mysql-perl libdbd-pg-perl libfcgi-dev libgd2-xpm libnet-ssleay-perl libpg-perl libsasl2-2 libsasl2-modules libxml-simple-perl mailman mysql-client mysql-common mysql-server openssl php-pear php5 php5-cgi php5-mysql postfix postfix-pcre postgresql postgresql-client procmail proftpd-basic python quota ri ruby sasl2-bin spamassassin spamc subversion unzip webalizer zip
aptitude -y install virtualmin-base usermin-virtual-server-mobile virtualmin-base webmin-virtual-server-mobile webmin-virtualmin-dav webmin-virtualmin-svn
Once it get ready you should able to access Virtualmin (i.e. Webmin) interface with HTTPS + port 10000, e.g. https://www.example.com:10000. Don't forget to reboot the system before next step.
Post-configure after initial installation
First of all, whatever install with GPL installation script or manually, we should install some additional packages so makes your Virtualmin Drupal/Gallery/VtigerCRM/etc friendly:
aptitude -y install bmon colordiff ffmpeg git htop libapache2-mod-rpaf libssh2-php lvm2 memcached mlocate nmap ntp openssh-server pbzip2 php-apc php-codesniffer php5-curl php5-ffmpeg php5-gd php5-gmp php5-imap php5-intl php5-mcrypt php5-memcache php5-pgsql php5-snmp php5-sqlite php5-tidy php5-xdebug php5-xmlrpc phpmyadmin pwgen resolvconf rsync varnish vim
Now access https://www.example.com:10000, login with root, and page should show up as below:
The Post-installation Wizard should now show up. Nothing special and just follow the guideline. My suggestion is to keep most unnecessary functionality NOT start up during system boot in order to save more memory.
Once post-installation wizard done, it will show the default landing page of Virtualmin. Note with the top system message, Virtualmin will suggest you to re-check configuration once again:
Well sounds good up to this point, BTW, don't trust the result yet! Remember to reboot your system and double/triple confirm with "System Settings -> Re-Check Configuration" and ensure that everything looks good even system reboot ;-)
Some recommended tweak on Virtualmin especially for Drupal virtual hosting
Next I would like tweak some setting which best suit as our Drupal R&D (which proofed by daily operation).
Install Drush, add Expires headers, entity tags (ETags) and APC support as below:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
sed -i '1i export PATH="$HOME/.composer/vendor/bin:$PATH"' $HOME/.bashrc
composer global require drush/drush:6.*
a2enmod expires
echo "FileETag none" > /etc/apache2/conf.d/fileetag
cat > /etc/php5/conf.d/apc.ini <<-EOF
apc.gc_ttl=3600
apc.max_file_size=8M
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.rfc1867=1
apc.rfc1867_ttl=600
apc.shm_size=256M
apc.ttl=600
apc.user_ttl=600
extension=apc.so
EOF
cd /etc/php5/
find . -type f -name php.ini | while read line; do
sed -i 's/^;*\(date\.timezone\) =.*$/\1 = "Asia\/Hong_Kong"/g' $line
sed -i 's/^;*\(display_errors\) =.*$/\1 = Off/g' $line
sed -i 's/^;*\(max_execution_time\) =.*$/\1 = 3600/g' $line
sed -i 's/^;*\(max_input_time\) =.*$/\1 = 7200/g' $line
sed -i 's/^;*\(memory_limit\) =.*$/\1 = 256M/g' $line
sed -i 's/^;*\(post_max_size\) =.*$/\1 = 32M/g' $line
sed -i 's/^;*\(short_open_tag\) =.*$/\1 = Off/g' $line
sed -i 's/^;*\(upload_max_filesize\) =.*$/\1 = 32M/g' $line
done
cat > /etc/apache2/mods-enabled/fcgid.conf <<-EOF
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
FcgidConnectTimeout 30
FcgidMaxProcesses 256
FcgidMaxProcessesPerClass 8
FcgidProcessLifeTime 300
</IfModule>
EOF
/etc/init.d/apache2 restart
First of all update default shells from "System Customization -> Custom Shells", choose "Custom shells below...", enable /bin/bash and replace as default (rather than /bin/sh):
Secondly updaet default quota value by accessing "System Settings -> Account Plans -> Default Plan", Update from default 1GB into whatever suitable for your cases (usually I will update it up to 4GB):
Go to "System Settings -> Virtualmin Configuration" and update as below:
- Networking settings
- Default virtual server IP address: 0.0.0.0
- Default IP address for DNS records: Other address (Remember to update as your external IP)
- Defaults for new domains
- Password field type: Randomly generated password
- Length of randomly generated password: 8
So now go to the most important about the server templates. Go to "System Settings -> Server Templates -> Default Settings" and update as below:
- Apache wesite
- Default PHP execution mode: FCGId (run as virtual server owner)
- MySQL database
- Default database name: ${USER}
- Prefix for additional database: ${USER}_
- Default database character set: utf8 (UTF-8 Unicode)
- Default database collation order: utf8_general_ci
Moreover go to "System Settings -> Server Templates -> Settings For Sub-Servers" and update as below:
- Apache wesite
- Directives and settings for new websites: From default settings
- MySQL database
- Default database name: ${USER}_${PREFIX}
- Prefix for additional database: ${USER}_${PREFIX}_
Go to "Webmin -> Servers -> Apache Webserver -> Global configuration -> Networking and Address" and update as below:
- Address for name virtual servers
- Include all addresses: unclick, 0.0.0.0:80
Go to "Webmin -> Servers -> MySQL Database Server -> MySQL Server Configuration" and update as below:
- Default table storage engine: InnoDB
- Separate file for each InnoDB table? Yes
Ok now Virtualmin should be good enough as a Drupal R&D platform ;-)
Create your first Virtualmin Top-level server for Drupal R&D
When everything get ready you can now create a new server by "Create Virtual Server". Let say we are now creating for domain example.com, so just key in as below:
- Domain name: example.com (NOTE: even we hope to virtual server serve for www.example.com, this alias will automatically create for us so we should provide our base domain name here)
- Administration password: your_own_secret_password
Every required setting for a virtual hosting should setup for you with a single click on-the-fly. Now SSH login to the server with account created above and execute follow command:
cat > /home/example/public_html/phpinfo.php <<-EOF
<?php phpinfo(); ?>
EOF
Access http://www.example.com/phpinfo.php and result should looks as like as below:
Ok looks good! Now fetch Drupal 7.x with GIT to /home/example/public_html:
cd /home/example
drush -y dl drupal --drupal-project-rename=public_html
cd /home/example/public_html
curl -s https://drupal.org/files/issues/drupal-7.x-symlinksifownermatch-2106057-5.patch | patch -p1
chown -Rf example:example /home/example/
Access http://www.example.com should now show up Drupal 7.x installer. Then operate as normal Drupal installation procedure which will not detail here:
How to create another subdomain under same user account, e.g. sub.example.com?
Subdomain management under Virtualmin is very simple: what you need to do is creating a "Sub-server" by accessing "example.com -> Create Virtual Server -> Sub-server" with:
- Domain name: sub.example.com
- Parent server: example.com (example)
Therefore another complete set of virtual hosting skeleton will be created on-the-fly under /home/example/domains/sub.example.com, including MySQL database with name example_sub, plus corresponding /home/example/domains/sub.example.com/public_html:
How to create an alias for existing domain, e.g. alias.example.com for example.com?
This would be especially useful for Drupal multi-site installation, so you can handle and manage numbers of alias by using Virtualmin handy UI. Go to "example.com -> Create Virtual Server -> Alias of example.com" and configure as below:
- Domain name: alias.example.com
- Real server: example.com
Ok that's it, really simple isn't it ;-)
Conclusion
Setting up R&D server, configure individual service, manage numbers of project R&D directory is always a nightmare for system administrator of small to medium size website development company. For sure that we can always apply for VPS or Amazon EC2 as R&D platform, but for sure that having your own server will always be the most flexible solution, especially your client may not only request for Drupal service or fancy 3rd party service integration (e.g. LDAP).
By using Virtualmin all complicated setup can simply handle by a friendly web interface. I am now managing my projects (30+ domain/subdomains/alias) with Virtualmin and save me a lot of time. It is also simple enough for Linux-dummy (e.g. our PM able to create new project folder with Virtualmin, where he even don't know much about console commands!).
In case if you can manage your client's server with VPS service, e.g. GoDaddy VDS or Amazon EC2, using Virtualmin and also keep both of your development server and production server configuration in sync, backup and migrate entire project simply, or redeploy website within few minutes.
Using Virtualmin as abstraction layer can also overcome the different of Linux distribution. Let's say you are using Debian as me for R&D, where client's website will host with GoDaddy VDS CentOS server, you can have a smooth backup -> transfer -> restore procedure for entire project redeployment, without understanding the different between deb-based or rpm-based Linux distribution: as long as Virtualmin (i.e. Webmin) able to handle its high-level backup information.
If you didn't try for Virtualmin yet but looking for a stable and powerful virtual hosting solution, you should give a try for it on today ;-)