RHEL6 apache httpd virtual host the proper way

My recipie for name based virtual hosts in separate directories on RHEL:

We place all the virtual hosts under a new directory tree /var/www/vhosts:

# yum install httpd
# mkdir /var/www/vhosts
# semanage fcontext -a -t httpd_sys_content_t /var/www/vhosts
# restorecon -Rv /var/www/vhosts
# mkdir -p /var/www/vhosts/{site1,site2,site3}/{logs,htdocs}
# chown -R apache:apache /var/www/vhosts

I recommend using the FQDN of each site instead of the words “site1”, “site2”, in these examples.

Create the file /etc/httpd/conf.d/vhosts.conf with appropriate content such as:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName site1
  DocumentRoot /var/www/vhosts/site1/htdocs
  CustomLog "/var/www/vhosts/site1/logs/access.log" common
  ErrorLog "/var/www/vhosts/site1/logs/error.log"

  <Directory "/var/www/vhosts/site1/htdocs">
     Options None
     AllowOverride All
     Order Deny,Allow
     Allow from 127.0.0.1
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName site2
  DocumentRoot /var/www/vhosts/site2/htdocs
  CustomLog "/var/www/vhosts/site2/logs/access.log" common
  ErrorLog "/var/www/vhosts/site2/logs/error.log"

  <Directory "/var/www/vhosts/site2/htdocs">
     Options None
     AllowOverride All
     Order Deny,Allow
     Allow from 127.0.0.1
  </Directory>
</VirtualHost>

and so on

(Dont forget to set the Directory permissions properly. Above is just an example!)

Then activate the goodness:

# apachectl restart

Why is this method good?

1. Creating the vhosts.conf in conf.d doesn’t modify any vendor-supplied files, which means that we won’t lose them if we reinstall the package.

2. Keeping each virtual host and its logs under its own directory tree makes maintenance a breeze and permissions can be separated to give developers access to specific vhosts only.

Howto install perl modules

I often find myself trying to install (binary) packages that have dependencies to perl modules.

Because I work on varying platforms, sometimes RHEL/RedHat, CentOS, sometimes Debian based, like Ubuntu, and sometimes, less often now, but maybe I will go back again, to Gentoo. In many ways my ideal platform.

However, Perl is wicked, and the concept of perl modules in a package manager is even more crazy.

What are we going to do when we need a new version of a software (say, amavisd-new) that is not available in the distros package library?

I’m thinking, build from source and you can’t go wrong, right?

In the case of amavisd-new, these are the listed prerequisites:

Archive::Zip   (Archive-Zip-x.xx) (1.14 or later, currently 1.23)
Compress::Zlib (Compress-Zlib-x.xx) (1.35 or later, currently 2.008)
Compress::Raw::Zlib (Compress-Raw-Zlib) (2.017 or later)
Convert::TNEF  (Convert-TNEF-x.xx)
Convert::UUlib (Convert-UUlib-x.xxx) (1.08 or later, stick to new versions!)
MIME::Base64   (MIME-Base64-x.xx)
MIME::Parser   (MIME-Tools-x.xxxx) (latest version from CPAN - currently 5.425)
Mail::Internet (MailTools-1.58 or later have workarounds for Perl 5.8.0 bugs)
Net::Server    (Net-Server-x.xx) (version 0.88 finally does setuid right)
Digest::MD5    (Digest-MD5-x.xx) (2.22 or later)
IO::Stringy    (IO-stringy-x.xxx)
Time::HiRes    (Time-HiRes-x.xx) (use 1.49 or later, older can cause problems)
Unix::Syslog   (Unix-Syslog-x.xxx)
BerkeleyDB     with bdb library (preferably 4.4.20 or later)
Mail::DKIM     (Mail-DKIM-0.31 or later)

So, if I’m going to install amavisd-new, from souce, on a RHEL6 server, what do I need to do? -Well, I’ll show what I did. Not neccessarily what is the best thing to do… OK?

yum install cpan
perl -MCPAN -e shell

(going with the defaults, automatic is nice)

When I attempted to install the first module (Archive::Zip), I discovered that I did not have web access from my server, so I had to download the CPAN modules by hand. I did this by using the powerful http://search.cpan.org/ search tool, and just pasting the package name (Archive::Zip) in the search box and then downloading the tar.gz packages one at a time.

Manual installation of 1 CPAN package:

tar zxf Archive-Zip-1.31_04.tar.gz
cd Archive-Zip-1.31_04
perl Makefile.PL
make
make test
sudo make install

Had I had internet connection available:

perl -MCPAN -e 'install Archive::Zip'

The beauty of CPAN installation is that it resolves dependencies automatically.

Moved to new hosting

Hello again!

I recently had some very nice experiences with gandi simple hosting (where the story tellers guild is located), which is in effect a “hosted VPS”, that is, a hosted solution, but with a private set of apache, mysql, APC and Varnish threads. Very cool indeed.

So I’m now moving this blog to the same platform.

10 minutes of work, and all appears to be working as expected.

The steps:

  1. create the vhost(s) (with/without www.)
  2. add temp /etc/hosts entries while testing
  3. mysqldump the database (I took one of the cron-generated ones that was only an hour old)
  4. copy the files from the old DocumentRoot (put -r in sftp works in ubuntu for a recursive put, which was needed due to the amount of files)
  5. verify
  6. remove temporary /etc/hosts entry
  7. update DNS records to point to the new host

To finalize, I installed the varnish http purge plugin.
Looking forward to seeing the impact on performance in google webmaster tools.

Titanium Developer – more headaches

Just how much time does Appcelerator spend in bed with Apple?

I understand that iPhone is a nice target platform for selling apps, but Appcelerator markets Titanium much the same way that Sun Microsystems (R.I.P.) marketed Java: Write Once, Run Everywhere.

However, the developers at Appcelerator (who make Titanium) have lots to learn about portability. (How’s that for irony!) Probably everybody in software development has lots to learn from could learn from The Art of Unix Programming and general Unix Philosophy.

To make it work, even in a new Ubuntu, you have to (after installing) actually (re)move the following files from ~/.titanium/runtime/linux/1.0.0/:

libgio-2.0.la           libglib-2.0.la           libgobject-2.0.la
libgio-2.0.so           libglib-2.0.so           libgobject-2.0.so
libgio-2.0.so.0         libglib-2.0.so.0         libgobject-2.0.so.0
libgio-2.0.so.0.2200.4  libglib-2.0.so.0.2200.4  libgobject-2.0.so.0.2200.4

After that, at least it starts (albeit with LOADS of messages and warnings on the console).

The cryptic error message that “indicates” the error with the conflicting libraries, removed above, was:

symbol lookup error: /usr/lib/libgdk-x11-2.0.so.0: undefined symbol: g_malloc_n

So, if you get the error with titanium and libgdk-x11-2.0.so.0 and g_malloc_n, the solution is to move away the libraries from the runtime directory in your installation folder.

Android SDK not found by Titanium Developer?

When struggling with Titanium Developer on windows, (see tutorial examples in earlier posts) one of my main problems was that it failed to locate the Android SDK, despite the fact that I had installed it. The problem is due to Titanium Developer looking for the “adb.exe” and “android.bat” in the “tools” directory, but in the new versions of the SDK they are located in the “platform-tools” directory instead.

The easy fix to the problem, is to simply copy adb.exe and the corresponding DLL to the tools-directory. Read my full post for easy instructions on how to get started with Titanium.

Easy Android Development with Titanium Developer!

Everybody does it… Do you? If not, read on, to see what is needed to create your first HelloWorld Android app! We will use Titanium, which lets you use web technology to build apps for both Android and IOS.

Step 1: set up a development machine.

I like to separate stuff, and I had LOADS of trouble trying on my 64bit Windows 7 (x64), so I chose to install a 32bit (x86) version in VirtualBox (on my CentOS Linux workstation).

On my first attempt, I gave it only 9 GB of disk, which was way too little, so I started over with a 19.5 GB disk (preallocated). Configured the VM with 600MB RAM and no Audio device. I installed Windows 7 Ultimate N (From MSDN), turned off all desktop effects (optimize for performance), installed Google Chrome as the default web browser, unpinned IE from the task bar, pinned Chrome there instead, chose a desktop wallpaper (unneeded, but I couldn’t resist the image of the happy plastic figures holding their knees!), and applied the windows updates, except SP1, because that led me to an irrepairable “fatal error c0000034 applying update operation” error. (Yes, I tried DISM /image:D:\ /cleanup-image /revertpendingactions, even twice).

Step 2: set up the development environment

The development tool we will use is Appcelerator Titanium, and we will develop for Android, so we need the Java SE JDK and Android SDK first.

Java and Android SDK

Since the development machine is a windows host, we choose the Android SDK windows installer, and install it in the default location. It is friendly enough, checking for Java JDK and providing a link to the download page if it is not found. My machine is a fresh install of Windows 7, so we have no Java yet. I installed it through the Windows x86 JDK link after clicking the word “JDK” under the leftmost Java Icon and then accepting the license agreement on the next page. Install Java in the default location.

If you still have the Android SDK installer “hanging” after it didn’t find Java, click the “<Back” button, and then “Next>”, to begin the installation of the Android SDK. The default values are fine.

Add “C:\Program Files\Java\jdk1.6.0_25\bin” to the end of your PATH variable.

SDK Manager

Let the SDK installer start the SDK Manager, let it search for available packages. Being lazy, I let it download everything, by simply choosing “Accept All” and clicking “Install”. This will take a while. Quite a long while if you are on a slow link. Grab a coffee, Energy Drink, Tea, Beer, Milk, whatever and take a break while it downloads and installs what you’ve chosen.

Install Titanium Developer

Download and run the windows installer of Titanium Developer. Its target audience seems to be IOS developers, as there are (still) some annoying bugs in the version I use. For instance, it’s using a (nowadays) incorrect way of finding and checking the Android SDK.

Workaround

To get around the bug in Titanium, copy “adb.exe” and “AdbWinApi.dll” from the “platform-tools” directory to the “tools” directory, under (my example) C:\Program Files\Android\android-sdk\.

Step 3: Set up Titanium

Register a new account, click the green button “New Project” (+) on the top of the window, Click “Desktop” near “Project type:”, and change it to “Mobile”. Click the button with the red X at the bottom where it’s written “Android SDK found” (unless you have a green checkbox there), and help it find the SDK for Android if necessary. (Path in bold in previous paragraph).

Pick a name for your first app, chose an appropriate App Id, pick an empty directory for this app, if you have an URL, enter it, and click “Create Project”. This will create a directory tree starting with your app name, and under it, the directory “Resources“, the file “tiapp.xml” and a bunch of other files.

The Resources directory is the home of “app.js”, your first Android application, written in JavaScript!

Click the “Test & Package” button on the top right on the work space in Titanium. A view with three tabs: “Run Emulator”, “Run on Device” and “Distribute” should be visible. “Run Emulator” should be selected. Below it should be a tab named “Android”, and beneath that, a black log window. If not: delete your new project, import the KitchenSink demo app, and recreate your project. At the bottom you have selections for SDK version, Screen, and a filter for what kind of output to view, as well as a Launch button and a Stop button.

Press “Launch” and wait.

I’ll be back with a coding example. But I think this has been plenty for now!

By the way, if it in the message box (top right corner) says there’s an update for Titanium Mobile available, click the download link…