JOMYUT.NET Software Engineering Blog

14Apr/110

Limitation of DirectAdmin on Amazon EC2

This is some limitation of DirectAdmin when deploy in Amazon EC2.

Experience with outbound packet from DirectAdmin. Every features that needs outbound connection in DirectAdmin will not work. This is because the DirectAdmin configuration will automatically use interfaces in DirectAdmin configuration (also present as DirectAdmin License). The known functions that not working properly such as

  • Automatic grab the license
    Workaround: You have to use /usr/local/directadmin/scripts/getLicense.sh to manually grab your license.
  • Auto DirectAdmin Update
    Workaround: You have to use /usr/local/directadmin/scripts/getDA.sh to manually upgrade your DirectAdmin.
  • Multi Server for DNS Service
    Workaround: None

You cannot bind more than 1 ip address to each instance. You can have only 1 IP Address each instance.

  • You cannot specific IP address to specific domain name. (Because you have only 1 IP Address).
  • You cannot use SSL with specific IP Address. You may use Shared SSL as normally.

 

12Apr/115

DirectAdmin in the Amazon EC2

Everything is now pointing to the cloud, how about Shared web hosting service? Nowadays, Cloud computing had been talking wildly in the topic of IaaS (Infrastructure as a service) which reduce costs in the machines resources and maintenance costs. This tutorial provide guideline to make Shared web hosting service based on Amazon EC2.

Assume that you already have Amazon AWS account. (If not, create one)

Reserve one of the Elastic IP address

In the most first step, you should reserved one elastic ip address. This ip address use to request for DirectAdmin license. You may wait for DirectAdmin license confirmation before continue in next step to save your EC2 instance costs.

Setup Security Group

Now, it is turn that you going to Amazon AWS Management Console, you have enable some ports to make your instance access from the Outside. You must add DNS, 21 (FTP), 2222, SSH, SMTP, SMTPS, IMAP, IMAPS, HTTP, HTTPS to your instance security policy. 2222 is known as DirectAdmin control panel default port.

Create Amazon EC2 Instance

When create an Amazon EC2 instance, I preferred to use Large -- an instance type. that take you benefits from high-memory and compute units. If you willing to use small or tiny, you will experience with very slow during compile step. You may use Large instance and then change to Tiny/Small later when system has completed installation and it is ready to be use.

Preferred : Large Amazon EC2 Instance

in the reference topic, they use CentOS x64. I have use Ubuntu 10.04 LTS x86 and it work well.

Running Amazon Instance

Once you created, run it and login to your instance. If you use Ubuntu 10.04 LTS x86 AMI from Amazon Community, you must use 'ubuntu' as username, and use authorized key when you created the instance. Now is step-by-step to install DirectAdmin

  • Following DirectAdmin Pre-requirement guideline to install package that required by DirectAdmin. You also following the DirectAdmin installation guide here.
yum install gcc gcc-c++ flex bison make bind bind-libs bind-utils openssl openssl-devel perl quota
apt-get install gcc g++ make flex bison openssl libssl-dev perl perl-base perl-modules libperl-dev libaio1 libaio-dev
  • Get setup script from DirectAdmin
    wget http://www.directadmin.com/setup.sh 
  • Remove bind-address from setup.sh script. Make it go though private interface (but it will be elastic IP address show up at DirectAdmin Licensing)
    sed -i 's/--bind-address=\$IP//;' setup.sh
  • Attached Elastic IP Address to the instance interface
    ifconfig eth0:0 inet $YOUR_IP_ADDRESS_HERE netmask 255.255.255.255 up
  • Running screen command to protect installation step from connection lost of your machine. this command will make Installation script running even you lost connection. (When you login back to the system can get back the previous session)
    screen 
  • Open the second terminal, We need to running one script parallel with installation process
  • You may Replace this step with the next one
    In the second terminal, be sure that you are root privilege and running following command
    cd /usr/local/directadmin/scripts; while [ true ]; do sed -i 's/--bind-address=\$IP//; s/--bind-address=\${3}//;' *.sh > /dev/null > 2&>1; sleep 1; done

    This script will be execute itself in infinite loop. You just terminate when installation completed. This is because when you run setup script, it will be download some of setup script that inside have --bind-address paramter which make you cannot retrieve the destination.
  • This step have replaced the previous one.
    sed -i 's/tar xzf update.tar.gz/tar xzf update.tar.gz\n[JOMYUT]/' setup.sh
    sed -i 's/\[JOMYUT\]/sh fix-binding.sh/' setup.sh
    echo "cd /usr/local/directadmin/scripts/" > fix-binding.sh
    echo "sed -i 's/--bind-address=\\\$IP//; s/--bind-address=\\\${3}//;' *.sh" >> fix-binding.sh
    chmod 755 fix-binding.sh
  • Back to the first terminal, running setup script
    ./setup.sh $CLIENT_ID $LICENSE_ID $YOUR_HOSTNAME eth0:0 $ELASTIC_IP

    Replace $CLIENT_ID with your client id received in DirectAdmin license
    Replace $LICENSE_ID with your license id received in DirectAdmin license
    Replace $YOUR_HOSTNAME with your hostname of this machine that you want
    Replace $ELASTIC_IP with your elastic ip that you binding to current instance

Finalize Step

After completed the installation, you have to add ec2-user or ssh user back into /etc/ssh/sshd_config file. this is because DirectAdmin installation have change it. Just put your username in the last line. otherwise, the next time you will not able access SSH by your username. However, if you forget this step, you may use Administrator username that DirectAdmin provide on the final setup screen.

You may reconfigure the PHP temporary file path, PHP session path to the local storage. This configuration will help you save costs from EBS I/O but remembered that any data in local storage will be lost when stop the instance. So, remember to use it as temporary file only.

Boot script

  • If you customize the machine such as PHP tmp path, PHP session path, you have to make a script that make temporary folder in local storage everytime that restart the instance. Any data in local storage will be lost when stop the instance. if you use `init 6` to restart your instance, data will still in your local storage.
  • Wake up your License Ethernet connection when restart machine Set up your IP address in the /etc/interfaces to make it binding when startup the instance
    cd /etc/network
    echo "auto eth0:0" >> interfaces
    echo "iface eth0:0 inet static" >> interfaces
    echo "address $YOUR_ELASTIC_IP" >> interfaces
    echo "netmask 255.255.255.255" >> interfaces

Test Running

Now, reboot! Hurey!, you may test your control panel after restart the instance, try login to your Control Panel.

Change Apache Template

At the time I wrote this guideline, Amazon can have only 1 Elastic IP per instance. Any incoming package will sent to internal ip address. This make a problem with default Apache config which handle each IP address in its configuration. So, we change /etc/httpd/conf/ips.conf to be global address instead of per IP address.

sed -i 's/\s.*:/ \*:/' /etc/httpd/conf/ips.conf

However, in any users created, it will also use IP address, so, we have to change httpd template where is in /usr/local/directadmin/data/templates/

cd /usr/local/directadmin/data/templates/
find . -name "*virtual_host*" -exec sed -i 's/|IP|/\*/' '{}' \;
find . -name "*virtual_host*" -exec sed -i 's/|MULTI_IP|//' '{}' \;

The above command will replace all IP address in every apache template to be global (*). and remove |MULTI_IP| because you cannot use this features.

Now, try to create new user account and test.

Watch Out

the directory /usr/local/directadmin/data/templates/ will be replaced when get DirectAdmin update. you should backup whole directory and replace back after update your DirectAdmin.

Done.

[Update on 20 Apr 2011] setup.sh - add enhancement for detect update.tar.gz extraction.
TODO: /templates/custom in the last section
TODO: Add full EC2 management script to the entry

11Apr/110

Install PHP 5.2/5.3 in the same machine

This is solution for DirectAdmin machine owner who would like to use both version of PHP5 in their system. First, you may see reference topic here and here. To install both PHP versions with custombuild, you are require to trick the DirectAdmin with PHP6 configuration because DirectAdmin itself doesn't support both PHP5 working at the same time.

One solution to choice

In the solution I provided, I make PHP5.3 as default compiler running as CLI. and PHP 5.2 can be optional used with .htaccess level configuration. (running by suPHP)

  1. Change the custombuild build script to version 1.2
    cd /usr/local/directadmin/custombuild/
    ./build set custombuild 1.2
  2. Change automatic download new versions.txt to be No.
    ./build set autover no
    Later, explained.
  3. Build update and copy PHP5 configuration to PHP6 custombuild path
    ./build update
    mkdir -p custom/suphp
    cp -pf configure/suphp/configure.php5 custom/suphp/configure.php6
  4. For me, I implement PHP5.3 running as CLI and PHP5.2 as CGI by suPHP. This is difference from referenced topic
    perl -pi -e 's/php5\:/phprep\:/' versions.txt
    perl -pi -e 's/php6/php5/' versions.txt
    perl -pi -e 's/phprep/php6/' versions.txt
  5. Set build options
    ./build set php5_ver 5.3
    ./build set php6_cgi yes
    ./build set php6_cli no
    ./build set php5_cgi no
    ./build set php5_cli yes

    Note that php6 is a configuration for PHP 5.2 and PHP5 is a configuration for PHP 5.3 and running as default engine.
  6. Build both PHP versions.
    ./build php n
  7. Change path of the PHP 5.2 package

Now, below is a configuration for PHP 5.2 based website. you have to put these code in .htaccess to root of public_html directory

<FilesMatch "\.php$">
AddHandler x-httpd-php6 .php
</FilesMatch>

if you don't like to use x-httpd-php6, you may change to x-httpd-php52 or somewhat you want. but you have to config below files

perl -pi -e 's/x-httpd-php6/x-httpd-php52/' /usr/local/suphp/etc/suphp.conf
perl -pi -e 's/x-httpd-php6/x-httpd-php52/' /etc/httpd/conf/extra/httpd-suphp.conf

Now, you can use website with PHP 5.2 and PHP 5.3 upon .htaccess configuration.