Edison Wong

Subscribe to Edison Wong feed
Updated: 7 min 7 sec ago

Gallery 3 on Ubuntu 12.04 mini-HOWTO

Tue, 05/01/2012 - 08:56

Categories:

Drupal

This mini-HOWTO will guide you though installation of Gallery 3 on Ubuntu 12.04, as a subdomain managed by Virtualmin.

Since the main dish of this mini-HOWTO is NOT about Virtualmin + Ubuntu 12.04, so I will assume you have that installed correctly. Please also refer to link provided for more information of subdomain creation.

Prepare the subdomain for Gallery 3

Here I will create a subdomain for Gallery 3 as below:

  • Domain name: gallery3.example.com
  • Parent server: example.com (example)
  • Home directory: /home/example/domains/gallery3.example.com
  • Website documents sub-directory: /home/example/domains/gallery3.example.com/public_html

Fetch Gallery 3 from GIT

I would like to use GIT version of Gallery 3 so can update with git pull simply. First login as user example then run:

cd /home/example/domains/gallery3.example.com/public_html/
git init
git remote add origin git://github.com/gallery/gallery3.git
git fetch
git branch 3.0.x origin/3.0.x
git checkout 3.0.x
chown -Rf example:example /home/example/

Start Gallery 3 installation

Now access http://gallery3.example.com/ and should start the installer as below:

Fill in the information as below:

  • Database name: example_gallery3
  • User: example
  • Password: your_secret_password
  • Host: localhost

Update administrator information

Once install complete click on "Start using Gallery" and now it should prompt you as below:

Add some photoes

Ok so most likely your Gallery 3 already get ready for use. Now add some photoes?

Let's enjoy it ;-)

Tags: GalleryUbuntuHOWTO

Virtualmin + Drupal 7.x on Ubuntu 12.04 HOWTO

Mon, 04/30/2012 - 13:46

Categories:

Drupal

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 should be:

www.example.com

The /etc/hosts should also be:

127.0.0.1       localhost
127.0.1.1       www.example.com                 www

Now reboot your system, and check the system hostname with command:

hostname

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:

cd /tmp
wget http://software.virtualmin.com/gpl/scripts/install.sh
/bin/bash /tmp/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:

cd /tmp
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 <<-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/debian/ virtualmin-squeeze main
deb http://software.virtualmin.com/gpl/debian/ 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 update
aptitude -y full-upgrade

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 colordiff 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-apc php-pear php5 php5-cgi php5-curl php5-ffmpeg php5-gd php5-imap php5-mcrypt php5-memcached php5-mysql php5-snmp php5-sqlite php5-tidy php5-xmlrpc phpmyadmin postfix postfix-pcre postgresql postgresql-client procmail proftpd-basic pwgen python quota resolvconf ri rsync ruby sasl2-bin spamassassin spamc subversion unzip usermin webalizer webmin zip

aptitude -y install virtualmin-base

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

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).

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):

So now go to the most important about the server templates. Go to "System Settings -> Server Templates -> Default Settings" and update as below:

  • MySQL database
    • Default database name: ${PREFIX}
    • Prefix for additional database: ${PREFIX}_
    • 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:

  • 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, *:80

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:

echo "<?php print phpinfo(); ?>" > /home/example/public_html/phpinfo.php

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/public_html/
git init
git remote add origin http://git.drupal.org/project/drupal.git
git fetch
git branch 7.x origin/7.x
git checkout 7.x
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 ;-)

Tags: UbuntuWebminHOWTODrupal

Ubuntu 12.04 on Virtualbox 4.1 mini-HOWTO

Mon, 04/30/2012 - 00:20

Categories:

Drupal

This mini-HOWTO will guide you though installing Ubuntu Server 12.04 with minimal setup on Virtualbox 4.1.x.

Before start, you should first install latest Virtualbox from https://www.virtualbox.org/wiki/Downloads, including:

  • VirtualBox platform packages
  • Oracle VM VirtualBox Extension Pack

Also, download the latest Ubuntu Server 12.04 install CD from http://releases.ubuntu.com/12.04/

Assume that your Virtualbox already install correctly, let's create a new VM as below:

Some check points:

  • Both number of processor, base memory, video memory and disk storage size are optional, you may scale it up according to your situation
  • At least enable 1 network interface with NAT (recommened for testing) or bridge to your public internet connection, else during Ubuntu installation it will not able to fetch latest information from internet
  • In the Storage -> IDE Controller -> Attributes -> CD/DVD Driver, choose the Ubuntu Server 12.04 install CD and confirm it

Once start the VM the screen should show up as:

  • Press F6 and choose "Expert mode"
  • Press F4 and choose "Install a minimal virtual machine"

NOTE: By choosing the "Install a minimal virtual machine" default Linux kernel will only come with limited modules + hardware support, e.g. even without disk quota support. Anyway, for sure that due to the trim down of kernel size memory usage and speed would be better when compare with normal kernal

Just install "linux-image-extra-virtual" to get all available kernel modules if required.

Update the hostname according to your needs.

My reason for using "Expert mode": we can enable root access by default during installation. Usually I will NOT create a normal user account in next step, too (Since for most cases I will combine the server usage with Virtualmin so it will manage that for me).

Choose "Manual" during partition disks.

  • Choose "msdos" for Partition table type for most cases (e.g. < 2TB)
  • Just create single primary root partition (i.e. no swap partition). This is because as a VM, if it is running out of memory and able to use disk as swap, it may keep on use up all disk I/O so other else VMs may be killed, too. Just give enough base memory for it ;-)

Choose the archive mirror that most close to your location.

Usually I will left this empty selection for manually install after first reboot.

After first reboot, it should looks like this. I would like to add some quick fix once first boot successful:

aptitude update && \
aptitude -y full-upgrade && \
aptitude -y install ubuntu-extras-keyring vim ntp openssh-server rsync colordiff pwgen locate

Ok now your Ubuntu 12.04 should ready for on going development ;-)

Tags: VirtualBoxUbuntu

Apache 2.4 + PHP5.4 + PDO_OCI on Ubuntu 12.04 HOWTO

Sun, 04/29/2012 - 00:21

Categories:

Drupal

This simple HOWTO will guide you about how to setup Apache2.4 + PHP5.4 + PDO_OCI from sketch. Compile all package from tarball can give you the maximum flexibility of functionality, e.g. you can enable both mysql/mysqli/pgsql/oci8/pdo_mysql/pdo_pgsql/pdo_oci within single installation.

Before start, I will assume you have Ubuntu 12.04 and Oracle 11gR2 installed correctly, which will not detail within this document. If you really need some help for that, please refer to my other article for more indeed guideline.

Install required packages

Debian apt-get can give us a great hand when prepare system for building custom packages from sketch. Just simply run this command:

aptitude update && \
aptitude -y full-upgrade && \
aptitude -y install git vim libmcrypt-dev && \
apt-get -y build-dep apache2 php5

Install Apache2.4

Get Apache2.4 source from GIT, compile, and install it:

cd /usr/local/src
wget http://www.us.apache.org/dist/httpd/httpd-2.4.2.tar.gz
tar zxvf httpd-2.4.2.tar.gz
cd httpd-2.4.2
./configure --enable-suexec --enable-rewrite --enable-so
make
make install

You should retouch the Apache configuration. Edit /usr/local/apache2/conf/httpd.conf and take the similar change as below:

User www-data
Group www-data
ServerAdmin root@localhost.localdomain
DocumentRoot "/var/www"
<Directory "/var/www">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
</Directory>

Also need to ensure Apache have correct privilege to access its document root:

chown -Rf www-data:www-data /var/www

Symbolic link all Apache execute binaries to /usr/local/bin:

ln -s /usr/local/apache2/bin/* /usr/local/bin/

Remove the /etc/init.d/apache2 and replace it as a symbolic link to /usr/local/bin/apachectl:

rm -rf /etc/init.d/apache2
ln -s /usr/local/bin/apachectl /etc/init.d/apache2

Ensure your Apache will start automatically during system boot:

update-rc.d -f apache2 remove
update-rc.d -f apache2 defaults 91 09

Restart Apache and so let all changes take effect:

/etc/init.d/apache2 stop
/etc/init.d/apache2 start

Try to access http://localhost.localdomain/index.html and check if message appear.

Install PHP5.4

First of all, unpack the PHP tarball:

cd /usr/local/src/
git clone --branch PHP-5.4 https://github.com/php/php-src.git php-5.4.x
cd php-5.4.x
./buildconf

You should check all available parameter with:

./configure --help

Before start the configuration, I would like to give you some suggested combination of parameters. E.g.:

  --enable-bcmath \
  --enable-calendar \
  --enable-dba \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-shmop \
  --enable-sigchild \
  --enable-soap \
  --enable-sockets \
  --enable-sqlite-utf8 \
  --enable-sysvmsg \
  --enable-wddx \
  --enable-zip \
  --with-apxs2=/usr/local/apache2/bin/apxs \
  --with-bz2 \
  --with-config-file-path=/usr/local/apache2/conf \
  --with-curl \
  --with-gd \
  --with-gettext \
  --with-mcrypt \
  --with-mysql \
  --with-mysqli \
  --with-openssl \
  --with-pdo-mysql \
  --with-pdo-pgsql \
  --with-pgsql \
  --with-xmlrpc \
  --with-zlib \

Moreover, OCI8 and PDO_OCI should configuration as (assume you have install Oracle 11gR1 to /u01/app/oracle/product/11.2.0/dbhome_1):

  --with-oci8=/u01/app/oracle/product/11.2.0/dbhome_1 \
  --with-pdo-oci=/u01/app/oracle/product/11.2.0/dbhome_1 \

So the complete PHP5.4 configuration command with PDO_OCI should be:

./configure \
  --enable-bcmath \
  --enable-calendar \
  --enable-dba \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-shmop \
  --enable-sigchild \
  --enable-soap \
  --enable-sockets \
  --enable-sysvmsg \
  --enable-wddx \
  --enable-zip \
  --with-apxs2=/usr/local/apache2/bin/apxs \
  --with-bz2 \
  --with-config-file-path=/usr/local/apache2/conf \
  --with-curl \
  --with-gd \
  --with-gettext \
  --with-mcrypt \
  --with-openssl \
  --with-pdo-mysql \
  --with-pdo-oci=/u01/app/oracle/product/11.2.0/dbhome_1 \
  --with-pdo-pgsql \
  --with-xmlrpc \
  --with-zlib

Next, build and install the PHP5:

make && \
make test && \
make install

Copy PHP's supplied initialization file:

cp php.ini-development /usr/local/apache2/conf/php.ini
sed -i 's/^;\(date\.timezone\) =\s*$/\1 = "Asia\/Hong_kong"/g' /usr/local/apache2/conf/php.ini
sed -i 's/^\(memory_limit\) = .*$/\1 = 256M/g' /usr/local/apache2/conf/php.ini
sed -i 's/^\(post_max_size\) = .*$/\1 = 32M/g' /usr/local/apache2/conf/php.ini
sed -i 's/^\(upload_max_filesize\) = .*$/\1 = 32M/g' /usr/local/apache2/conf/php.ini

Create a PHP configuration file for Apache as /usr/local/apache2/conf/extra/httpd-php5.conf and add the following lines:

#
# This next section will call PHP for .php, .phtml, and .phps files
#
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php-source .phps

#
# This is the directory containing php.ini
#
PHPIniDir "/usr/local/apache2/conf"

Retouch /usr/local/apache2/conf/httpd.conf and add this line to the end of file:

Include conf/extra/httpd-php5.conf

If a LoadModule line was not already inserted by the PHP install, add it too:

LoadModule php5_module        modules/libphp5.so

Also update the DirectoryIndex:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
</IfModule>

Create a testing file as /var/www/phpinfo.php with below content:

<?php print phpinfo(); ?>

Restart your Apache and test your PHP setup with http://localhost.localdomain/phpinfo.php

Oracle specific fine tune

By default, Apache's user account and user group don't have privilege to access Oracle's resources, so we will need some hack:

adduser www-data oinstall

Next, Apache don't have the idea about where is the Oracle instance client, so we need to specify for it. Edit /usr/local/apache2/bin/envvars and add the following lines at the end of file:

umask 022
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=AL32UTF8
export NLS_LANG=.AL32UTF8
unset TNS_ADMIN
if [ -d "$ORACLE_HOME/bin" ]; then
    PATH="$ORACLE_HOME/bin:$PATH"
fi

Assume you have already activate your Oracle's HR user account from database AL32UTF8. Create /var/www/pdo_oci.php with following content, access http://localhost.localdomain/pdo_oci.php, test if your PDO_OCI driver install correctly:

<?php
$db_conn = new PDO('oci:dbname=//localhost.localdomain/AL32UTF8.localdomain', 'HR', 'CHANGE');
$cmdstr = 'SELECT "LAST_NAME", "SALARY" FROM "HR"."EMPLOYEES"';
$stmt = $db_conn->query($cmdstr);
$results = $stmt->fetchAll();
$stmt = $db_conn->query("SELECT COUNT(*) AS nrows FROM ($cmdstr)");
$nrows = $stmt->fetch(PDO::FETCH_OBJ)->NROWS;
echo "<html><head><title>Oracle PHP Test</title></head><body>";
echo "<center><h2>Oracle PHP Test</h2><br>";
echo "<table border=1 cellspacing='0' width='50%'>\n<tr>\n";
echo "<td><b>Name</b></td>\n<td><b>Salary</b></td>\n</tr>\n";
for ($i = 0; $i < $nrows; $i++ ) {
        echo "<tr>\n";
        echo "<td>" . $results[$i]["LAST_NAME"] . "</td>";
        echo "<td>$ " . number_format($results[$i]["SALARY"], 2). "</td>";
        echo "</tr>\n";
}
echo "<tr><td colspan='2'> Number of Rows: $nrows</td></tr></table><br>";
echo "<em>If you see data, then it works!</em><br>";
echo "</center></body></html>\n";
?>

Sample output:

Tags: ApacheUbuntuHOWTOOraclePHP

Oracle Database 11g Release 2 on Ubuntu 12.04 HOWTO

Sat, 04/28/2012 - 02:37

Categories:

Drupal

This HOWTO will guide you though installation of ORacle Database 11g Release 2 on Ubuntu 12.04.

Install the base system

First of all you should install Ubuntu 12.04 with minimal packages, almost nothing else is required at the beginning.

After initial installation run the following command to upgrade your system as latest stable + some optional useful packages:

aptitude update && \
aptitude -y full-upgrade && \
tasksel install openssh-server && \
tasksel install server && \
tasksel install mail-server && \
tasksel install ubuntu-desktop && \
aptitude -y install colordiff locate ntp pwgen rsync vim

Once everything get ready you may start the GUI and test with:

startx

Check your /etc/hostname and update as below:

localhost.localdomain

Check your /etc/hosts and update as below:

127.0.0.1       localhost.localdomain   localhost

Running /etc/init.d/hostname.sh (or simply reboot your Ubuntu), then test the hostname of system with:

hostname

Ok up to this point your Ubuntu 12.04 should basically configure for installing Oracle 11gR2.

Check your hardware setup

First of all, you need to have AT LEAST 1GB of physical memory (I use 2GB here). Check it with:

grep MemTotal /proc/meminfo

On the other hand, it is suggest to have swap with 1.5 time of your physical memory, e.g. around 2GB. Check it with:

grep SwapTotal /proc/meminfo

In case I am using libvirt + KVM VM client, I don't hope to create swap partition by default or else if all VMs are running out of resourse they will all keep on swapping to harddisk and finally all gone...

Here I will create a temperate swap file and activate it during installation; once reboot it will gone automatically (or manually disable it with swapoff /tmp/swap):

dd if=/dev/zero of=/tmp/swap bs=1M count=4096
chmod 600 /tmp/swap
mkswap /tmp/swap
swapon /tmp/swap
grep SwapTotal /proc/meminfo

Shared memory is very important, too. Or else you may face the ORA-00845 error message. First check it with:

df -kh /dev/shm/

If you have less than 512MB (I will suggest for 1GB), edit your /etc/fstab and add/modify the following line:

tmpfs           /dev/shm        tmpfs   defaults,size=1024M    0       0

Then remount it and check the size once again:

mount -o remount /dev/shm
df -kh /dev/shm/

Install dependence packages

As I assume you have Ubuntu 12.04 installed correctly with X11, we just need to dig into dependence packages installation directly (in case of AMD64):

aptitude -y install alien binutils build-essential cpp-4.4 debhelper g++-4.4 gawk gcc-4.4 gcc-4.4-base gettext html2text ia32-libs intltool-debian ksh lesstif2 lib32bz2-dev lib32z1-dev libaio-dev libaio1 libbeecrypt7 libc6 libc6-dev libc6-dev-i386 libdb4.8 libelf-dev libelf1 libltdl-dev libltdl7 libmotif4 libodbcinstq4-1 libodbcinstq4-1:i386 libqt4-core libqt4-gui libsqlite3-0 libstdc++5 libstdc++6 libstdc++6-4.4-dev lsb lsb-core lsb-cxx lsb-desktop lsb-graphics lsb-qt4 make odbcinst pax po-debconf rpm rpm-common sysstat unixodbc unixodbc-dev unzip

System groups and users

Check your existing setup with:

grep oinstall /etc/group
grep dba /etc/group
grep nobody /etc/group
id oracle
id nobody

Most likely, you should run the following command for create the required system groups and users. Latest Ubuntu already come with user nobody so we don't need to retouch it:

addgroup --system oinstall
addgroup --system dba
useradd -r -g oinstall -G dba -m -s /bin/bash -d /var/lib/oracle oracle
passwd oracle

Configure kernel parameters

Check your existing setup with:

/sbin/sysctl -a | grep sem
/sbin/sysctl -a | grep shm
/sbin/sysctl -a | grep file-max
/sbin/sysctl -a | grep ip_local_port_range
/sbin/sysctl -a | grep rmem_default
/sbin/sysctl -a | grep rmem_max
/sbin/sysctl -a | grep wmem_default
/sbin/sysctl -a | grep wmem_max

Then edit your /etc/sysctl.d/99-oracle.conf and add the following lines:

cat > /etc/sysctl.d/99-oracle.conf <<-EOF
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
EOF

Run the following command to reload these kernel parameters:

sysctl -p 

Shell limits for oracle user

Add the following to /etc/security/limits.conf as below:

oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
oracle              soft    stack   10240

Check (or add) if the following line exits within /etc/pam.d/login:

session required /lib/security/pam_limits.so 

Check (or add) if the following line exits within /etc/pam.d/su:

session required pam_limits.so 

Create required directories

Create required directory and change permission:

mkdir -p /u01/app/oracle
mkdir -p /u02/oradata
chown -R oracle:oinstall /u01 /u02
chmod -R 775 /u01 /u02

Configuring the oracle user's environment

Add following line to /var/lib/oracle/.profile (as i will create a AL32UTF8 database; change to US7ASCII if you will create ASCII database). This will also map Oracle's /bin to your $PATH so can run Oracle's binary directly when login as user oracle:

if [ $SHELL = "/bin/ksh" ]; then
  ulimit -p 16384
  ulimit -n 65536
else
  ulimit -u 16384 -n 65536
fi

umask 022
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=AL32UTF8
export NLS_LANG=.AL32UTF8
unset TNS_ADMIN
if [ -d "$ORACLE_HOME/bin" ]; then
    PATH="$ORACLE_HOME/bin:$PATH"
fi

Fake Oracle installer

As mentioned before , Ubuntu is not listed as Oracle officially support platform and so we need to "fake" it. Create symbolic links:

mkdir /usr/lib64
ln -s /etc /etc/rc.d
ln -s /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib64/
ln -s /usr/bin/awk /bin/awk
ln -s /usr/bin/basename /bin/basename
ln -s /usr/bin/rpm /bin/rpm
ln -s /usr/lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib64/
ln -s /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a /usr/lib64/
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.5 /lib64/
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.5 /usr/lib64/
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /lib64/
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib64/

Also mask ourself as RedHat:

echo 'Red Hat Linux release 5' > /etc/redhat-release

Last step before installation start

First of all, login with your new oracle user, with X enabled.

If you are using PuTTY + Xming, for sure that the X11 forward is enabled.

Copy the file linux_11gR1_database.zip to oracle's home directory, then unzip it:

cp linux.x64_11gR2_database_1of2.zip /var/lib/oracle
cp linux.x64_11gR2_database_2of2.zip /var/lib/oracle
cd /var/lib/oracle
unzip -q linux.x64_11gR2_database_1of2.zip
unzip -q linux.x64_11gR2_database_2of2.zip

I will STRONGLY suggest for a complete reboot, and double-check ALL pre-installation BEFORE starting the next step.

Recommended installation procedures

First of all login with useraccount "oracle" and start the X11 with startx, then start the installer with:

cd /var/lib/oracle/database && ./runInstaller

Next we go though the installation (I don't have the "Oracle Support Password" so just skip in here):

In "Selection Installation Option", choose "Create and configure a database":

In "System Class", choose "Server Class" (we hope to give a full control during installation):

In "Node Selection", choose "Single instance database installation":

In "Select Install Type", choose "Advanced install":

In "Select Product Languages", I choose to install all available languages:

In "Select Database Edition", I choose "Enterprise Edition":

In "Specify Installation Location", it should default as below:

  • Oracle Base: /u01/app/oracle
  • Sofeware Location: /u01/app/oracle/product/11.2.0/dbhome_1

In "Create Inventory", it should default as below:

  • Inventory Directory: /u01/app/oraInventory
  • oraInventory Group Name: oinstall

In "Select Configure Type", choose "General Purpose / Transaction Processing":

(IMPORTANT!) In "Specify Database Identifiers", configure as below:

  • Global database name: AL32UTF8.localdomain
  • Oracle Service Identifier (SID): AL32UTF8

In "Specify Configuration Options", configure as below:

  • Memory -> Enable Automatic Memory Management: TRUE
  • Character sets: Use Unicode (AL32UTF8)

In "Specify Management Options", choose "Use Database Control for database management" but keep other else empty:

In "Specify Database Storage Options", choose "File System" where:

  • Specify database file location: /u01/app/oracle/oradata

In "Specify Recovery Options", choose "Do not enable automated backups":

In "Specify Schema Passwords", I am a bit lazy so choose "Use the same password for all accounts" (don't do this in production server!):

In "Privileged Operating System Groups", confirm as below:

  • Database Administrator (OSDBA) Group: dba
  • Database Operator (OSOPER) Group: oinstall

In "Preform Prerequisite Checks", just simply ignore all warning message (since we are using Debian but not Oracle officially supported OS):

So just confirm everything in "Summary":

And now let's go for a coffee break ;-)

Oh it should that almost done! Special note for Ubuntu 12.04: If you face error during installation so update as below:

Open /u01/app/oracle/product/11.2.0/dbhome_1/sysman/lib/ins_emagent.mk, search for:

$(SYSMANBIN)emdctl:
        $(MK_EMAGENT_NMECTL)

And replace as:

$(SYSMANBIN)emdctl:
        $(MK_EMAGENT_NMECTL) -lnnz11

Open /u01/app/oracle/product/11.2.0/dbhome_1/bin/genorasdksh, search for:

$LD $LD_RUNTIME $LD_OPT $LD_OUT $LD_SELF_CONTAINED $BASE_LIB \
        $LD_OBJS $LD_SYMS $OLIBS $SYSLIBS $USRLIBS

And replace as:

$LD $LD_RUNTIME -Wl,--no-as-needed $LD_OPT $LD_OUT $LD_SELF_CONTAINED $BASE_LIB \
        $LD_OBJS $LD_SYMS $OLIBS $SYSLIBS $USRLIBS

Open /u01/app/oracle/product/11.2.0/dbhome_1/srvm/lib/ins_srvm.mk, search for:

GETCRSHOME_LINKLINE=$(LINK) $(LDPATHFLAG)$(RDBMSLIB) $(CDEBUG) $(OPT) $(GETCRSHOME_OBJ1) \
        $(OCRLIBS_DEFAULT) $(LLIBCLNTSH) $(LINKLDLIBS)

And replace as:

GETCRSHOME_LINKLINE=$(LINK) $(LDPATHFLAG)$(RDBMSLIB) $(CDEBUG) $(OPT) $(GETCRSHOME_OBJ1) \
        -Wl,--no-as-needed $(OCRLIBS_DEFAULT) $(LLIBCLNTSH) $(LINKLDLIBS)

Open /u01/app/oracle/product/11.2.0/dbhome_1/network/lib/env_network.mk, search for:

TNSLSNR_LINKLINE=$(LINK) $(TNSLSNR_OFILES) $(LINKTTLIBS) $(LLIBONS) \
                 $(LOCALNETLIBS) $(MATHLIB) $(TNSLSNR_THREADLIB)

And replace as:

TNSLSNR_LINKLINE=$(LINK) $(TNSLSNR_OFILES) -Wl,--no-as-needed $(LINKTTLIBS) $(LLIBONS) \
                 $(LOCALNETLIBS) $(MATHLIB) $(TNSLSNR_THREADLIB)

Open /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/env_rdbms.mk, search for:

ORACLE_LINKLINE=$(ORACLE_LINKER) $(PL_FLAGS) $(ORAMAI) $(SSORED) $(TTCSOI) \
        $(ORACLE_KERNEL_LIBS) $(LINKLDLIBS)

And replace as:

ORACLE_LINKLINE=$(ORACLE_LINKER) -Wl,--no-as-needed $(PL_FLAGS) $(ORAMAI) $(SSORED) $(TTCSOI) \
        $(ORACLE_KERNEL_LIBS) $(LINKLDLIBS)

Then keep ongoing for installation ;-)

Now following the instructions and run the following commands with "root" user:

  • /u01/app/oraInventory/orainstRoot.sh
  • /u01/app/oracle/product/11.2.0/dbhome_1/root.sh

Ok you get it!

Confirm with installation progress

In previous screen the installer mentioned that we can access "Enterprise Manager Database Control URL - (AL32UTF8)" from https://localhost.localdomain:1158/em, so now let's open the browser and test it with following account:

  • User Name: SYS
  • Password: your_secret_password
  • Connect As: SYSDBA

Once login it should show as below:

Autostart Oracle during system boot

There is almost for sure that you will hope to start your Oracle automatically during system boot. Even you may turn this feature off, but the init.d script is very useful, too.

First of all, specify which database instant will be started together with Oracle. Edit /etc/oratab as below:

AL32UTF8:/u01/app/oracle/product/11.2.0/dbhome_1:Y

Next, create init.d script as /etc/init.d/oracle:

#!/bin/bash
#
# Run-level Startup script for the Oracle Instance and Listener
#
### BEGIN INIT INFO
# Provides:          Oracle
# Required-Start:    \$remote_fs \$syslog
# Required-Stop:     \$remote_fs \$syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Startup/Shutdown Oracle listener and instance
### END INIT INFO
 

ORA_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
ORA_OWNR="oracle"

# if the executables do not exist -- display error

if [ ! -f $ORA_HOME/bin/dbstart -o ! -d $ORA_HOME ]
then
        echo "Oracle startup: cannot start"
        exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
        start)
                # Oracle listener and instance startup
                echo -n "Starting Oracle: "
                su - $ORA_OWNR -c "$ORA_HOME/bin/dbstart $ORA_HOME"
                su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl start"

                #Optional : for Enterprise Manager software only
                su - $ORA_OWNR -c "$ORA_HOME/bin/emctl start dbconsole"

                touch /var/lock/oracle
                echo "OK"
                ;;
        stop)
                # Oracle listener and instance shutdown
                echo -n "Shutdown Oracle: "

                #Optional : for Enterprise Manager software only
                su - $ORA_OWNR -c "$ORA_HOME/bin/emctl stop dbconsole"

                su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl stop"
                su - $ORA_OWNR -c "$ORA_HOME/bin/dbshut $ORA_HOME"
                rm -f /var/lock/oracle
                echo "OK"
                ;;
        reload|restart)
                $0 stop
                $0 start
                ;;
        *)
                echo "Usage: $0 start|stop|restart|reload"
                exit 1
esac
exit 0

Permission is very important, too:

chmod 755 /etc/init.d/oracle

Finally, install the script so Oracle will start during system bootup:

update-rc.d oracle defaults 99 01

NOTE: You may find the following error message during /etc/init.d/oracle/stop:

Shutdown Oracle: ulimit: 25: bad number

You can then update /u01/app/oracle/product/11.2.0/dbhome_1/bin/emctl with #!/bin/bash to solve the problem:

#!/bin/bash -f

References Tags: UbuntuOracleHOWTO

Gitorious on Ubuntu 12.04 mini-HOWTO

Sun, 04/15/2012 - 10:03

Categories:

Drupal

Gitorious provides open source infrastructure for hosting open source projects that use Git. This mini-HOWTO will guide you though the installation procedure on Ubuntu 12.04.

Install the base system

First of all you should install Ubuntu 12.04 with minimal packages, almost nothing else is required at the beginning.

After initial installation run the following command to upgrade your system as latest stable + some optional useful packages:

aptitude update
aptitude -y full-upgrade
tasksel install openssh-server
tasksel install server
tasksel install mail-server
aptitude -y install ntp openssh-server colordiff pwgen vim rsync locate

Install packages

Let's clone the similar setup as Debian Seueeze installation procedure:

aptitude -y install apache2 apache2-threaded-dev apg aspell aspell-en build-essential geoip-bin git-core git-cvs git-doc git-svn imagemagick libapache2-mod-xsendfile libaspell-dev libcurl4-openssl-dev libdbd-mysql-ruby libexpat1-dev libgeoip-dev libgeoip1 libmagick++-dev libmagick++4 libmysql-ruby libmysqlclient-dev libonig-dev libpcre3 libpcre3-dev libreadline-dev libreadline5 libruby libsqlite3-dev libxslt1-dev libyaml-dev memcached mysql-client mysql-server openjdk-6-jre phpmyadmin postfix ruby ruby-dev rubygems sphinxsearch sqlite3 unzip zip zlib1g zlib1g-dev

Install RubyGem

REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
gem install --no-ri --no-rdoc -v 0.8.7 rake
gem install --no-ri --no-rdoc -v 1.1.0 daemons
gem install -b --no-ri --no-rdoc rmagick stompserver passenger bundler

Fetch Gitorious

git clone git://gitorious.org/gitorious/mainline.git /var/www/gitorious
cd /var/www/gitorious
git submodule init
git submodule update

Initialize services

cd /var/www/gitorious/doc/templates/ubuntu
cp git-daemon git-ultrasphinx git-poller stomp /etc/init.d
cp gitorious-logrotate /etc/logrotate.d/gitorious
chmod 755 git-daemon git-ultrasphinx git-poller stomp
update-rc.d git-daemon defaults
update-rc.d git-ultrasphinx defaults
update-rc.d git-poller defaults
update-rc.d stomp defaults

Since both git-daemon, gitultrasphinx, git-poller and stomp RUBY_HOME are pointing to /opt/ruby-enterprise, let's update them to /usr:

sed -i 's/\/opt\/ruby-enterprise/\/usr/g' /etc/init.d/git-daemon
sed -i 's/\/opt\/ruby-enterprise/\/usr/g' /etc/init.d/git-ultrasphinx
sed -i 's/\/opt\/ruby-enterprise/\/usr/g' /etc/init.d/git-poller
sed -i 's/\/opt\/ruby-enterprise/\/usr/g' /etc/init.d/stomp

As refer to http://stackoverflow.com/questions/7201687/gitorious-git-daemon-ruby-gem..., it is better to modify git-daemon in hard way:

sed -i 's/^GIT_DAEMON=".*"$/GIT_DAEMON="bundle exec $GITORIOUS_HOME\/script\/git-daemon -d"/g' /etc/init.d/git-daemon

Configure Apache2

Install Passenger:

/usr/lib/ruby/gems/1.8/gems/passenger-3.0.12/bin/passenger-install-apache2-module

Create /etc/apache2/mods-available/passenger.load as below:

# Did you verify this matches the values from
# the 'sudo /usr/lib/ruby/gems/1.8/gems/passenger-3.0.12/bin/passenger-install-apache2-module' command ?
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.12
PassengerRuby /usr/bin/ruby1.8

Enable required modules:

a2enmod passenger rewrite ssl xsendfile
/etc/init.d/apache2 restart

Create /etc/apache2/sites-available/gitorious as below:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost

  DocumentRoot /var/www/gitorious/public

  ErrorLog /var/log/apache2/gitorious-error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog /var/log/apache2/gitorious-access.log combined

  <IfModule mod_xsendfile.c>
    XSendFile on
  </IfModule>

</VirtualHost>

Create /etc/apache2/sites-available/gitorious-ssl as below:

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/gitorious/public

    ErrorLog /var/log/apache2/gitorious-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/gitorious-ssl_access.log combined

    SSLEngine on

    SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

    BrowserMatch ".*MSIE.*" \
      nokeepalive ssl-unclean-shutdown \
      downgrade-1.0 force-response-1.0

    <IfModule mod_xsendfile.c>
      XSendFile on
    </IfModule>

  </VirtualHost>
</IfModule>

So let's restart Apache2 with new site setup:

a2dissite default
a2dissite default-ssl
a2ensite gitorious
a2ensite gitorious-ssl
/etc/init.d/apache2 restart

Setup MySQL

Start the mysql command line client by running:

mysql -u root -p
mysql> DROP DATABASE gitorious_production; CREATE DATABASE gitorious_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Configure Gitorious

Install Gitorious's RubyGems:

cd /var/www/gitorious/
bundle install
bundle pack

Run the following:

adduser --system --home /var/www/gitorious --no-create-home --group --shell /bin/bash git
chown -R git:git /var/www/gitorious
su - git
git submodule init
git submodule update
mkdir .ssh
touch .ssh/authorized_keys
chmod -R go-rwx .ssh
mkdir tmp/pids repositories tarballs  tarballs-work
cp config/database.sample.yml config/database.yml  
cp config/gitorious.sample.yml config/gitorious.yml  
cp config/broker.yml.example config/broker.yml

Edit config/gitorious.yml: Remove every section but production

  • gitorious_client_port should be 80
  • gitorious_client_host should be your localhost for Apache2
  • gitorious_host needs to be the exact hostname (e.g. gitorious.example.com) that clients will use (cookies get messed up otherwise)
  • repository_base_path should be something like /var/www/gitorious/repositories
  • archive_cache_dir should be something like /var/www/gitorious/tarballs
  • archive_work_dir should be something like /var/www/gitorious/tarballs-work
  • cookie_secret should generated by "apg -m 64"
  • exception_notification_emails should be something like admin@example.com
  • public_mode should be false (optional)
  • hide_http_clone_urls should be true (they require extra unknown setup to work)
  • is_gitorious_dot_org should be false
  • gitorious_support_email should be something like support@example.com

NOTE: Some hack is required for Rackfile and config/environment.rb. Update as below:

require 'thread'

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

Run the following:

export RAILS_ENV=production
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake ultrasphinx:bootstrap

Update contab by "crontab -e" as below:

* * * * * cd /var/www/gitorious && /usr/bin/bundle exec /usr/bin/rake ultrasphinx:index RAILS_ENV=production

Create a Admin User as User ‘git’:

env RAILS_ENV=production script/create_admin

Finish

Now access your setup with browser, e.g. https://gitorious.example.com. Login and enjoy it ;-)

Tags: UbuntuGITHOWTO

Girocco on Ubuntu 12.04 HOWTO

Sat, 03/17/2012 - 14:58

Categories:

Drupal
Install dependance package

apt-get install git-core build-essential netcat-openbsd apache2 wget libwww-perl libjson-perl librpc-xml-perl

Clone Girocco

cd /opt/
git clone git://repo.or.cz/girocco.git
cd /opt/girocco/
git submodule update --init

Tags: UbuntuGIT

要是換做你們的話?你們會毀滅誰?創造誰?

Fri, 02/03/2012 - 16:41

Categories:

Drupal

An interesting article shared by my friend from Facebook:

朋友拿了一份報紙要我作個實驗,我同意了。

問題一︰如果你知道一個女人懷孕了,她已經生了8個小孩子了,其中有3個耳朵聾,2個眼楮瞎,一個智能不足,而這個女人自己又有梅毒,請問,你會建議她墮胎嗎?

我剛要回答,朋友制止了我,又問我第二個問題。

問題二︰現在要選舉一名領袖,而你這一票很關鍵,下面是關于3個候選人的的一些事實︰

候選人A︰跟一些不誠實的政客有往來,而且會星象佔卜學。他有婚外情,是一個老煙槍,每天喝8到10杯的馬丁尼。

候選人B︰他過去有過2次被解雇的記錄,睡覺睡到中午才起來,大學時吸鴉片,而且每天傍晚會喝一大夸特威士忌。

候選人C︰他是一位受勛的戰爭英雄,素食主義者,不抽煙,只偶爾喝一點啤酒。從沒有發生婚外情。

請問你會在這些候選人中選擇誰?

我把答案寫在紙上,然後朋友告訴我︰

候選人A是富蘭克林羅斯福,候選人B是溫斯頓丘吉爾,候選人C是亞道夫希特勒。

我听了答案張大了嘴巴。朋友問我你是不是為人們選擇了希特勒?那你會建議哪個婦女去墮胎嗎?

我說︰這個問題不用考慮,我們受優生優育教育多年了,都生那麼多歪瓜劣棗了,就別在添亂了。我建議她去墮胎。

朋友告訴我︰你殺了貝多芬,她是貝多芬的母親。

我又一次張大了嘴巴。朋友說︰嚇一跳吧?本來以為你認為很好的答案,結果卻扼殺了貝多芬,創造了希特勒?

最後的總結是︰所以不要用既定的價值觀來思考事物!

要是換做你們的話?你們會毀滅誰?創造誰?

Read more: 關於「你的決定滅了誰」這則文章,你選擇相信 or 尋找答案?

P.S.

交通大學在民國93年經營管理組的考題中,還把這個測驗題當做考題之一,最後一行加上:
請你將讀完以上這段敘述對你在管理決策的啟發寫下來。

天哪~這教人怎麼寫?

如果是我,大概會寫:上述資訊告訴我們~做任何決策前,一定要取得充足而正確的資訊,免得被誤導後做出錯誤的決策!...(=_=)

Tags: Personal

夫唯不爭,故天下莫能與之爭。

Sat, 01/28/2012 - 17:15

Categories:

Drupal

曲則全,枉則直,窪則盈,敝則新,少則得,多則惑。

是以,聖人抱一為天下式。

不自見,故明;不自是,故彰;不自伐,故有功;不自矜,故長。夫唯不爭,故天下莫能與之爭。

古之所謂「曲則全」,豈虛語?故誠全而歸之。

Tags: Personal