<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CB1, INC. &#187; apache</title>
	<atom:link href="http://www.cb1inc.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cb1inc.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Sep 2011 17:54:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>CB1 Ubuntu 10.10 Linux Development Setup</title>
		<link>http://www.cb1inc.com/2010/10/16/cb1-ubuntu-10-10-linux-development-setup/</link>
		<comments>http://www.cb1inc.com/2010/10/16/cb1-ubuntu-10-10-linux-development-setup/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 02:36:52 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[gearman]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.cb1inc.com/?p=1375</guid>
		<description><![CDATA[I use a MacBook Pro for my day-to-day operations here at CB1, INC. I&#8217;m a huge believer that a development environment should mimic the production environment, so I find myself running a couple virtual machines in VMware Fusion. The following guide is a reference for myself as well as possibly a helpful resource for setting [...]]]></description>
			<content:encoded><![CDATA[<p>I use a MacBook Pro for my day-to-day operations here at CB1, INC.  I&#8217;m a huge believer that a development environment should mimic the production environment, so I find myself running a couple virtual machines in VMware Fusion.</p>
<p>The following guide is a reference for myself as well as possibly a helpful resource for setting up your own Linux development environment. Here&#8217;s an checklist of the tasks to perform and software to install:</p>
<ul>
<li>Operating System
<ul>
<li><a href="http://www.ubuntu.com/" target="_blank">Ubuntu 10.10 64-bit</a>: I use Ubuntu Desktop in dev and Ubuntu Server in production</li>
<li>Package updates and upgrades</li>
<li>Network configuration (at least 2 static IP addresses)</li>
</ul>
</li>
<li>Development Tools
<ul>
<li>C/C++ development environment</li>
<li>Autotools</li>
<li>Sun Java JDK</li>
<li><a href="http://valgrind.org/" target="_blank">Valgrind</a></li>
<li>Version control: <a href="http://subversion.tigris.org/" target="_blank">Subversion</a>, <a href="http://bazaar.canonical.com/en/" target="_blank">Bazaar</a>, <a href="http://git-scm.com/" target="_blank">git</a></li>
<li><a href="http://developer.android.com/">Android SDK</a></li>
</ul>
</li>
<li>Servers
<ul>
<li><a href="http://www.samba.org/" target="_blank">Samba</a> (file sharing)</li>
<li>SSH (remote shell access)</li>
<li><a href="http://httpd.apache.org/" target="_blank">Apache 2.2</a> (web server)</li>
<li><a href="http://nginx.org/" target="_blank">nginx 0.8</a> (web server)</li>
<li><a href="http://www.php.net/" target="_blank">PHP 5.3.3</a> (application server)</li>
<li><a href="http://php-fpm.org/" target="_blank">PHP-FPM</a> (PHP&#8217;s FastCGI process manager)</li>
<li><a href="http://www.mysql.com/" target="_blank">MySQL 5.1</a> (database server)</li>
<li><a href="http://www.postgresql.org/" target="_blank">PostgreSQL</a> (database server)</li>
<li><a href="http://memcached.org/" target="_blank">memcached 1.4.5</a> (caching layer)</li>
<li><a href="http://gearman.org/" target="_blank">Gearman</a> (job queue manager)</li>
</ul>
</li>
<li>PHP Extensions
<ul>
<li><a href="http://pecl.php.net/package/memcached" target="_blank">memcached</a></li>
<li><a href="http://xdebug.org/" target="_blank">Xdebug</a></li>
<li><a href="http://pecl.php.net/package/gearman" target="_blank">Gearman</a></li>
<li><a href="http://pecl.php.net/package/APC" target="_blank">APC</a></li>
</ul>
</li>
<li>Desktop Applications
<ul>
<li><a href="http://www.google.com/chrome">Google Chrome</a></li>
<li>KCachegrind</li>
<li><a href="http://www.appcelerator.com/products">Appcelerator Titanium</a></li>
</ul>
</li>
</ul>
<h3>Operating System</h3>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/ubuntu.png"/></p>
<p>Start by installing Ubuntu 10.10 Desktop (or server). I&#8217;m not going to cover installing Ubuntu since there are already several other resources out there. Once Ubuntu is installed, open a <strong>Terminal</strong>:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo passwd root</span>
[sudo] password for user: &lt;type your password&gt;
Enter new UNIX password: &lt;type new root password&gt;
Retype new UNIX password: &lt;type new root password again&gt;
passwd: password updated successfully

user@ubuntu:~# <span class="cmd">sudo apt-get update</span>
user@ubuntu:~# <span class="cmd">sudo apt-get upgrade</span>

user@ubuntu:~# <span class="cmd">mkdir ~/src</span>
</pre>
<h3>New File Permissions</h3>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo pico /etc/profile</span>
</pre>
<p>Change 022 to 002. This setting controls the default permissions when a new file or directory is created.  This is mostly useful when managing files over Samba.</p>
<h3>Network IP Addresses</h3>
<p>Optionally, you may want to assign a static IP address. I set up one IP address for Apache and another for nginx.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo pico /etc/network/interfaces</span>
</pre>
<p>The following is a reference for adding two static IPs.  Change the IPs to meet your needs.</p>
<pre class="brush: plain; title: ;">
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	address 192.168.1.200
	netmask 255.255.255.0
	gateway 192.168.1.1

auto eth0:1
iface eth0:1 inet static
	address 192.168.1.201
	netmask 255.255.255.0
</pre>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo /etc/init.d/networking restart</span>
</pre>
<h3>Packages</h3>
<p>Here&#8217;s a bunch of packages that will set up compilers, version control, Java, MySQL, Apache, PHP, Memcache, Gearman, Samba, and more.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo apt-get install build-essential autotools-dev autoconf \
 autoconf2.13 openssh-server ethtool traceroute openjdk-6-jdk \
 mysql-server-5.1 bzr subversion subversion-tools ntp ntpdate \
 libpcre3-dev libevent-dev automake bison libtool scons  g++ \
 ncurses-dev libreadline-dev libz-dev libssl-dev  libcurl4-openssl-dev \
 ruby rubygems libzip-ruby1.8 libzip-ruby1.9.1 python-dev ruby-dev \
 libdbus-glib-1-dev uuid-dev libpam0g libpam0g-dev gperf samba valgrind \
 libxml2-dev libfreetype6-dev curl libcurl4-openssl-dev \
 libjpeg62-dev libpng12-dev sqlite3 libsqlite3-dev git-core \
 postgresql postgis gearman libgearman-dev php5 \
 libapache2-mod-php5 php5-dev memcached php5-memcached \
 php5-curl php5-gd php5-mysql php5-pgsql php-apc \
 php5-xdebug php5-fpm libapache2-mod-fastcgi</span>
</pre>
<h3>MySQL</h3>
<p>During the package install above, MySQL will prompt you for the root password.</p>
<p>After the packages are installed, we need to allow remote MySQL connections.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo pico /etc/mysql/my.cnf</span>
</pre>
<p>Comment out the <em>bind-address</em> line.</p>
<pre class="brush: plain; title: ;">
# bind-address          = 127.0.0.1
</pre>
<h3>SSH</h3>
<p>Next, you may optionally increase the connection keep alive interval for remote ssh connections. Timeouts aren&#8217;t really an issue for SSH&#8217;ing into a local VM, but really helps for remote installs.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo echo &quot;ClientAliveInterval 60&quot; &gt;&gt; /etc/ssh/sshd_config</span>
</pre>
<h3>Samba</h3>
<p>Samba allows me to drag and drop files between my Mac and Linux VM. I personally do <strong>not</strong> enable/install Samba on production servers.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig</span>
user@ubuntu:~# <span class="cmd">sudo pico /etc/samba/smb.conf</span>
</pre>
<p>You can add a share such as the following:</p>
<pre class="brush: plain; title: ;">
[ubuntu]
        force user = &lt;your username&gt;
        writeable = yes
        create mode = 644
        path = /home/&lt;your username&gt;
        directory mode = 755
        force group = &lt;your username&gt;
</pre>
<p>Then create yourself a Samba user:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo smbpasswd -a &lt;your username&gt;</span>
</pre>
<h4>Apache 2</h4>
<p>Apache is mostly configured out of the box, but I like to enable rewrite and SSL so I can test production features.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo a2enmod rewrite</span>
user@ubuntu:~# <span class="cmd">sudo a2enmod ssl</span>
</pre>
<p>Since I&#8217;m going to run Apache and nginx, I&#8217;m going bind Apache to <em>eth0</em>.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo pico /etc/apache2/ports.conf</span>
</pre>
<pre class="brush: plain; title: ;">
NameVirtualHost 192.168.1.200:80
Listen 192.168.1.200:80

&lt;IfModule mod_ssl.c&gt;
    Listen 192.168.1.200:443
&lt;/IfModule&gt;
</pre>
<p>Now we need to add <em>eth0</em>&#8216;s IP to the default host:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo pico /etc/apache2/sites-enabled/000-default</span>
</pre>
<pre class="brush: plain; title: ;">
&lt;VirtualHost 192.168.1.200:80&gt;
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        &lt;Directory /&gt;
                Options FollowSymLinks
                AllowOverride None
        &lt;/Directory&gt;
        &lt;Directory /var/www/&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        &lt;/Directory&gt;

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;
</pre>
<p>Restart Apache for the changes to take effect.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo apache2ctl restart</span>
</pre>
<h3>Gearman</h3>
<p>By default, Gearman uses memory to store pending jobs in the queue, but I prefer to use MySQL for persistent storage.  To do this, first create the queue database and table:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">mysqladmin -uroot -p123123 create gearman</span>
user@ubuntu:~# <span class="cmd">mysql -uroot -p123123 -e "CREATE TABLE gearman.gearman_queue (
  unique_key VARCHAR(64) NOT NULL,
  function_name VARCHAR(255) NULL,
  priority INT NULL,
  data LONGBLOB NULL,
  PRIMARY KEY (unique_key)
) ENGINE = InnoDB;"</span>
</pre>
<p>Next update the init script to tell Gearman to use the database:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo mv /etc/default/gearman-job-server /etc/default/gearman-job-server.bak</span>
user@ubuntu:~# <span class="cmd">sudo echo &quot;PARAMS=\&quot;-q libdrizzle --libdrizzle-host=127.0.0.1&quot; \
   &quot;--libdrizzle-user=root --libdrizzle-password=123123 --libdrizzle-db=gearman&quot; \
   &quot;--libdrizzle-table=gearman_queue --libdrizzle-mysql\&quot;&quot; &gt; /etc/default/gearman-job-server</span>
user@ubuntu:~# <span class="cmd">sudo /etc/init.d/gearman-job-server restart</span>
</pre>
<h3>Gearman PHP Extension</h3>
<p>We need to download and install the Gearman PHP extension if we want to write PHP workers or post jobs to the queue.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">cd ~/src</span>
user@ubuntu:~/src# <span class="cmd">wget http://pecl.php.net/get/gearman-0.7.0.tgz</span>
user@ubuntu:~/src# <span class="cmd">tar xzf gearman-0.7.0.tgz</span>
user@ubuntu:~/src# <span class="cmd">rm gearman-0.7.0.tgz package.xml</span>
user@ubuntu:~/src# <span class="cmd">cd gearman-0.7.0</span>
user@ubuntu:~/src# <span class="cmd">phpize</span>
user@ubuntu:~/src# <span class="cmd">./configure</span>
user@ubuntu:~/src# <span class="cmd">make</span>
user@ubuntu:~/src# <span class="cmd">sudo make install</span>
</pre>
<p>Next, add the config file to load the Gearman PHP extension:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo echo &quot;extension=gearman.so&quot; &gt;&gt; /etc/php5/conf.d/gearman.ini</span>
</pre>
<h3>memcached PHP Extension</h3>
<p>Since we have memcached and the memcached PHP extension install, let&#8217;s use it for storing session data:</p>
<pre class="terminal">
user@ubuntu:~/src# <span class="cmd">sudo echo &quot;session.save_handler = memcached
session.save_path = \&quot;127.0.0.1:11211\&quot;&quot; &gt;&gt; /etc/php5/conf.d/memcached.ini</span>
</pre>
<h3>nginx</h3>
<p>nginx is web server that is really fast.  I use nginx as my primary development web server unless I&#8217;m running a web app that only works with Apache. You can choose to install nginx from package, but I like to live life on the bleeding edge, so I&#8217;ll be building nginx from source. To install nginx, we need to download the source, compile it, install it, and configure it.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">cd ~/src</span>
user@ubuntu:~/src# <span class="cmd">wget http://nginx.org/download/nginx-0.8.52.tar.gz</span>
user@ubuntu:~/src# <span class="cmd">tar xzf nginx-0.8.52.tar.gz</span>
user@ubuntu:~/src# <span class="cmd">rm nginx-0.8.52.tar.gz</span>
user@ubuntu:~/src# <span class="cmd">cd nginx-0.8.52</span>
user@ubuntu:~/src# <span class="cmd">mkdir /var/lib/nginx</span>
user@ubuntu:~/src# <span class="cmd">./configure \
    --sbin-path=/usr/sbin \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/lock/nginx.lock \
    --http-log-path=/var/log/nginx/access.log \
    --http-client-body-temp-path=/var/lib/nginx/body \
    --http-proxy-temp-path=/var/lib/nginx/proxy \
    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
    --http-scgi-temp-path=/var/lib/nginx/scgi \
    --with-http_stub_status_module</span>
user@ubuntu:~/src# <span class="cmd">make</span>
user@ubuntu:~/src# <span class="cmd">sudo make install</span>

user@ubuntu:~# <span class="cmd">sudo pico /etc/init.d/nginx</span>
</pre>
<p>Here&#8217;s the init script that will start nginx for us:</p>
<pre class="brush: bash; title: ;">
#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
case &quot;$1&quot; in
  start)
        echo -n &quot;Starting $DESC: &quot;
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo &quot;$NAME.&quot;
        ;;
  stop)
        echo -n &quot;Stopping $DESC: &quot;
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON
        echo &quot;$NAME.&quot;
        ;;
  restart|force-reload)
        echo -n &quot;Restarting $DESC: &quot;
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo &quot;$NAME.&quot;
        ;;
  reload)
        echo -n &quot;Reloading $DESC configuration: &quot;
        start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON
        echo &quot;$NAME.&quot;
        ;;
  *)
        echo &quot;Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}&quot; &gt;&amp;2
        exit 1
        ;;
esac
exit 0
</pre>
<p>Now we need to make the init script executable and enable it:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo chmod +x /etc/init.d/nginx</span>
user@ubuntu:~# <span class="cmd">sudo update-rc.d nginx defaults</span>

user@ubuntu:~# <span class="cmd">sudo pico /etc/nginx/nginx.conf</span>
</pre>
<p>Here&#8217;s a starter nginx.conf with some basic settings:</p>
<pre class="brush: plain; title: ;">
user  www-data www-data;
worker_processes  2;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile                on;
    tcp_nodelay             on;
    tcp_nopush              on;
    keepalive_timeout       65;
    server_name_in_redirect off;
    server_tokens           off;

    add_header Strict-Transport-Security max-age=1800;
    add_header X-Frame-Options deny;

    gzip            on;
    gzip_buffers    16 8k;
    gzip_comp_level 9;
    gzip_types      text/plain text/xml application/x-javascript text/css;

    include /etc/nginx/sites/*;
}
</pre>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo mkdir /etc/nginx/sites</span>
user@ubuntu:~# <span class="cmd">sudo pico /etc/nginx/sites/default</span>
</pre>
<p>Now we need to set up a default host that supports PHP (via <a href="http://php-fpm.org/" target="_blank">PHP-FPM, PHP&#8217;s FastCGI Process Manager</a>) and we want the default host to use the <em>eth0:1</em> IP address:</p>
<pre class="brush: plain; title: ;">
server {
    listen       192.168.1.201:80 default;
    server_name  _;
    root   /var/www;
    index  index.php;
    location / {
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?q=$1 last;
            break;
        }
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~* (\.(htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)|code-style\.pl|Entries.*|Repository|Root|Tag|Template)$ {
        deny all;
    }
}
</pre>
<p>After the config files are good to go, start nginx:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo /etc/init.d/nginx start</span>
</pre>
<h3>Service Names</h3>
<p>I also like to add service names so I can see what ports are in use when I run <em>netstat</em>. I added drizzle and Cassandra for fun despite this post not including them.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo cp /etc/services /etc/services.bak</span>
user@ubuntu:~# <span class="cmd">su</span>
root@ubuntu:~# <span class="cmd">echo &quot;drizzle     4427/tcp
drizzle     4427/udp
memcached   11211/tcp
memcached   11211/udp
gearmand    4730/tcp
gearmand    4730/udp
fastcgi     9000/tcp
cassandra   9160/tcp&quot; &gt;&gt; /etc/services</span>
root@ubuntu:~# <span class="cmd">exit</span>
</pre>
<h3>Android SDK</h3>
<p>The Android SDK is unfortunately not in package, so you&#8217;ll need to download it from the Android Developer site: <a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a>.</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">wget http://dl.google.com/android/android-sdk_r07-linux_x86.tgz</span>
user@ubuntu:~# <span class="cmd">tar xzf android-sdk_r07-linux_x86.tgz</span>
user@ubuntu:~# <span class="cmd">rm android-sdk_r07-linux_x86.tgz</span>
user@ubuntu:~# <span class="cmd">sudo mv android-sdk-linux_x86 /usr/local</span>
user@ubuntu:~# <span class="cmd">sudo find /usr/local/android-sdk-linux_x86 -type d -exec chmod 777 {} \;</span>
</pre>
<p>You&#8217;ll need to add the Android SDK path near the top of your <code>~/.bash_profile</code> <em>or</em> <code>~/.bashrc</code>:</p>
<pre class="brush: plain; title: ;">
export PATH=${PATH}:/usr/local/android-sdk-linux_x86/tools
</pre>
<p>To manage your Android SDK packages and virtual devices, you&#8217;ll need to run the <em>android</em> app:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">android</span>
</pre>
<p>First go to <em>Available Packages</em> and download version <strong>1.6</strong> <em>and</em> <strong>2.2</strong> Android SDK packages.  You can also choose to download the documentation, samples, and Google APIs.</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/android4.jpg"/></p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/android5.jpg"/></p>
<p>Downloading the package may take several minutes. You don&#8217;t have to create a virtual device right now if you are planning on installing Appcelerator&#8217;s Titanium platform.  You can exit the Android app when you&#8217;re done.</p>
<h3>Desktop Apps</h3>
<p>If you&#8217;re running Ubuntu Desktop, there are a couple handy apps I install.  The first is Google Chrome and can be directly downloaded from the <a href="http://www.google.com/chrome/eula.html">Google Chrome download page</a>.</p>
<p>I find <em>KCachegrind</em> and <em>GHex</em> to be useful:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo apt-get install kcachegrind ghex</span>
</pre>
<h3>Appcelerator Titanium</h3>
<p>Titanium is an awesome platform for developing desktop applications for Linux, Mac OS X, and Windows as well as mobile apps for iPhone and Android. We use Titanium Developer to create Titanium projects. Begin by downloading the 64-bit version of Titanium:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">wget -O titanium.tgz http://www.appcelerator.com/download-linux64</span>
</pre>
<p>There&#8217;s also a 32-bit version available at <code>http://www.appcelerator.com/download-linux32</code>.</p>
<p>Next we unpack Titanium Developer and move it to a safe place:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">tar xzf titanium.tgz</span>
user@ubuntu:~# <span class="cmd">rm titanium.tgz</span>
</pre>
<p>Next you need to run the installer by double-clicking the <em>Titanium Developer</em> executable. Run the executable and then click the <em>Install</em> button. You can try installing to <code>/opt/titanium</code>, but you might need root privileges.</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/titanium1.jpg"/></p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/titanium2.jpg"/></p>
<p>Next, there are a few issues with outdated libraries, so we simply delete them:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">rm ~/.titanium/runtime/linux/1.0.0/libgobject-2.0.*</span>
user@ubuntu:~# <span class="cmd">rm ~/.titanium/runtime/linux/1.0.0/libglib-2.0.*</span>
user@ubuntu:~# <span class="cmd">rm ~/.titanium/runtime/linux/1.0.0/libgio-2.0.*</span>
user@ubuntu:~# <span class="cmd">rm ~/.titanium/runtime/linux/1.0.0/libgthread-2.0.*</span>
</pre>
<p>Titanium Developer also complains if <em>/bin/java</em> doesn&#8217;t exist, so create a quick link:</p>
<pre class="terminal">
user@ubuntu:~# <span class="cmd">sudo ln -s /usr/bin/java /bin/java</span>
</pre>
<p>Relaunch Titanium Developer and enter your login credentials.  If you don&#8217;t have a login, you can get a free account.</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/titanium3.jpg"/></p>
<p>After signing in, you may notice there are some updates available in the upper right corner of the window. Click in the box and the updates will be downloaded and installed.</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/titanium4.jpg"/></p>
<p>Optionally you can create a launcher icon for your GNOME panel. Don&#8217;t forget to escape spaces in the command with a backslash!</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/titanium5.jpg"/></p>
<h3>Finishing Touches</h3>
<p>Lastly, I like to re-arrange my desktop to maximize my coding real estate.</p>
<p><img class="aligncenter" src="http://cb1inc.com/wp-content/uploads/2010/10/ubuntu_10-10.jpg"/></p>
<h3>Conclusion</h3>
<p>That should get you up and running with a neato dev environment.  If you need to run SSL, I wrote a post on <a href="http://www.cb1inc.com/2007/05/13/creating-self-signed-certs-on-apache-2-2/">Creating Self-Signed Certs on Apache 2.2</a> and <a href="http://www.cb1inc.com/2008/09/11/virtual-hosts-and-wildcard-ssl-certificates-with-apache-2-2/">Virtual Hosts and Wildcard SSL Certificates with Apache 2.2</a>.</p>
<p>If you find any typos or additions, please feel free to sound off in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2010/10/16/cb1-ubuntu-10-10-linux-development-setup/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Virtual Hosts and Wildcard SSL Certificates with Apache 2.2</title>
		<link>http://www.cb1inc.com/2008/09/11/virtual-hosts-and-wildcard-ssl-certificates-with-apache-2-2/</link>
		<comments>http://www.cb1inc.com/2008/09/11/virtual-hosts-and-wildcard-ssl-certificates-with-apache-2-2/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 07:00:15 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[It is possible with Apache to host multiple websites with a single static IP address.  However, you can only have one SSL certificate per static IP.  This post describes setting up Apache with multiple secure virtual hosts and a single self-signed wildcard certificate.  To learn about creating the certificate, check out <a href="http://www.cb1inc.com/2007/05/13/creating-self-signed-certs-on-apache-2.2">Creating Self-Signed Certs on Apache 2.2</a>.

Here's a table of our example hosts:

<table>
<thead><tr>
<th>Domain</th><th>Force SSL?</th><th>Trusted?</th><th>Valid Domain?</th>
</tr></thead>
<tbody>
<tr><td>www.site-a.com</td><td>No</td><td>No</td><td>Yes</td></tr>
<tr><td>secure.site-a.com</td><td>Yes</td><td>No</td><td>Yes</td></tr>
<tr><td>test.site-a.com</td><td>No</td><td>No</td><td>Yes</td></tr>
<tr><td>www.site-b.com</td><td>No</td><td>No</td><td>No</td></tr>
<tr><td>secure.site-b.com</td><td>Yes</td><td>No</td><td>No</td></tr>
</tbody></table>

In order for the certificate to be trusted, you need to obtain the certificate from a trusted <a href="http://en.wikipedia.org/wiki/Certificate_Authority">certificate authority</a>. Since we are using self-signed certificates, they are not trusted and we will see some warning messages. The data will still be encrypted.

For this to work, we are going to use <a href="http://httpd.apache.org/docs/2.2/vhosts/name-based.html">name-based virtual hosts</a>.

The name and location of Apache's configuration files vary based on which platform you use.  This post assumes Ubuntu in which case the configuration files in the <code>/etc/apache2</code> directory.

For starters, we need to tell Apache which ports to listen on by editing the file <code>/etc/apache2/ports.conf</code>.

<pre><code>Listen 80
&#60;IfModule mod_ssl.c&#62;
    Listen 443
&#60;/IfModule&#62;</code></pre>

Next we need to add our virtual hosts.  They are kept in the <code>/etc/apache2/sites-available</code> directory.  For organization purposes, separate your sites into separate config files, then run <code>a2ensite</code> for each site to generate a symbolic link in the <code>/etc/apache2/sites-enabled</code> directory.

Here is the configuration for the sites:

<pre><code>NameVirtualHost 192.168.1.200:80
NameVirtualHost 192.168.1.200:443

# http://site-a.com
# https://site-a.com -- Throws warning because cert is for *.site-a.com... see bottom
# http://www.site-a.com
# https://www.site-a.com
&#60;VirtualHost 192.168.1.200:80 192.168.1.200:443&#62;
  ServerName site-a.com
  ServerAlias www.site-a.com
  DocumentRoot /path/to/www.site-a
  # Note: SSL settings only need to be defined once!
  SSLEngine On
  SSLCertificateFile /path/to/thecert.crt
  SSLCertificateKeyFile /path/to/thecert.key
&#60;/VirtualHost&#62;

# Not SSL, redirect to https://secure.site-a.com
&#60;VirtualHost 192.168.1.200:80&#62;
  ServerName secure.site-a.com
  Redirect / https://secure.site-a.com/
&#60;/VirtualHost&#62;

# https://secure.site-a.com
&#60;VirtualHost 192.168.1.200:443&#62;
  ServerName secure.site-a.com
  DocumentRoot /path/to/secure.site-a
&#60;/VirtualHost&#62;

# http://test.site-a.com
# https://test.site-a.com
&#60;VirtualHost 192.168.1.200:80 192.168.1.200:443&#62;
  ServerName test.site-a.com
  DocumentRoot /path/to/test.site-a
&#60;/VirtualHost&#62;

# http://www.site-b.com
# https://www.site-b.com -- Throws warning because cert is for *.site-a.com
&#60;VirtualHost 192.168.1.200:80 192.168.1.200:443&#62;
  ServerName www.site-b.com
  DocumentRoot /path/to/secure.site-b
&#60;/VirtualHost&#62;

# Not SSL, redirect to https://secure.site-b.com
&#60;VirtualHost *:80&#62;
  ServerName secure.site-b.com
  Redirect / https://secure.site-b.com/
&#60;/VirtualHost&#62;

# https://secure.site-b.com -- Throws warning because cert is for *.site-a.com
&#60;VirtualHost 192.168.1.200:443&#62;
  ServerName secure.site-b.com
  DocumentRoot /path/to/secure.site-b
&#60;/VirtualHost&#62;</code></pre>

Despite having a wildcard certificate for <code>*.site-a.com</code>, you will get an invalid domain message when you don't supply the subdomain (i.e.  http://site-a.com).  The only way I know of to solve this is with 2 static IPs and 2 certs where one cert is for <code>site-a.com</code> and the other is for <code>*.site-a.com</code>.

I'm using 192.168.1.200 for the server's IP address behind the firewall.  You could try using * instead of 192.168.1.200 in the <code>&#60;VirtualHost&#62;</code> blocks, but I haven't tested this.  Leave a comment if you happen to test this. :)

Assuming the stars have aligned, you should have several secured virtual hosts!]]></description>
			<content:encoded><![CDATA[<p>It is possible with Apache to host multiple websites with a single static IP address.  However, you can only have one SSL certificate per static IP.  This post describes setting up Apache with multiple secure virtual hosts and a single self-signed wildcard certificate.  To learn about creating the certificate, check out <a href="/2008/05/13/creating-self-signed-certs-on-apache-2.2">Creating Self-Signed Certs on Apache 2.2</a>.</p>
<p>Here&#8217;s a table of our example hosts:</p>
<table>
<thead>
<tr>
<th>Domain</th>
<th>Force SSL?</th>
<th>Trusted?</th>
<th>Valid Domain?</th>
</tr>
</thead>
<tbody>
<tr>
<td>www.site-a.com</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td>secure.site-a.com</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td>test.site-a.com</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td>www.site-b.com</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>secure.site-b.com</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
</tbody>
</table>
<p>In order for the certificate to be trusted, you need to obtain the certificate from a trusted <a href="http://en.wikipedia.org/wiki/Certificate_Authority">certificate authority</a>. Since we are using self-signed certificates, they are not trusted and we will see some warning messages. The data will still be encrypted.</p>
<p>For this to work, we are going to use <a href="http://httpd.apache.org/docs/2.2/vhosts/name-based.html">name-based virtual hosts</a>.</p>
<p>The name and location of Apache&#8217;s configuration files vary based on which platform you use.  This post assumes Ubuntu in which case the configuration files in the <code>/etc/apache2</code> directory.</p>
<p>For starters, we need to tell Apache which ports to listen on by editing the file <code>/etc/apache2/ports.conf</code>.</p>
<pre class="brush: xml; title: ;">
Listen 80
&lt;IfModule mod_ssl.c&gt;
    Listen 443
&lt;/IfModule&gt;
</pre>
<p>Next we need to add our virtual hosts.  They are kept in the <code>/etc/apache2/sites-available</code> directory.  For organization purposes, separate your sites into separate config files, then run <code>a2ensite</code> for each site to generate a symbolic link in the <code>/etc/apache2/sites-enabled</code> directory.</p>
<p>Here is the configuration for the sites:</p>
<pre class="brush: xml; title: ;">
NameVirtualHost 192.168.1.200:80
NameVirtualHost 192.168.1.200:443

# http://site-a.com
# https://site-a.com -- Throws warning because cert is for *.site-a.com... see bottom
# http://www.site-a.com
# https://www.site-a.com
&lt;VirtualHost 192.168.1.200:80 192.168.1.200:443&gt;
  ServerName site-a.com
  ServerAlias www.site-a.com
  DocumentRoot /path/to/www.site-a
  # Note: SSL settings only need to be defined once!
  SSLEngine On
  SSLCertificateFile /path/to/thecert.crt
  SSLCertificateKeyFile /path/to/thecert.key
&lt;/VirtualHost&gt;

# Not SSL, redirect to https://secure.site-a.com
&lt;VirtualHost 192.168.1.200:80&gt;
  ServerName secure.site-a.com
  Redirect / https://secure.site-a.com/
&lt;/VirtualHost&gt;

# https://secure.site-a.com
&lt;VirtualHost 192.168.1.200:443&gt;
  ServerName secure.site-a.com
  DocumentRoot /path/to/secure.site-a
&lt;/VirtualHost&gt;

# http://test.site-a.com
# https://test.site-a.com
&lt;VirtualHost 192.168.1.200:80 192.168.1.200:443&gt;
  ServerName test.site-a.com
  DocumentRoot /path/to/test.site-a
&lt;/VirtualHost&gt;

# http://www.site-b.com
# https://www.site-b.com -- Throws warning because cert is for *.site-a.com
&lt;VirtualHost 192.168.1.200:80 192.168.1.200:443&gt;
  ServerName www.site-b.com
  DocumentRoot /path/to/secure.site-b
&lt;/VirtualHost&gt;

# Not SSL, redirect to https://secure.site-b.com
&lt;VirtualHost *:80&gt;
  ServerName secure.site-b.com
  Redirect / https://secure.site-b.com/
&lt;/VirtualHost&gt;

# https://secure.site-b.com -- Throws warning because cert is for *.site-a.com
&lt;VirtualHost 192.168.1.200:443&gt;
  ServerName secure.site-b.com
  DocumentRoot /path/to/secure.site-b
&lt;/VirtualHost&gt;
</pre>
<p>Despite having a wildcard certificate for <code>*.site-a.com</code>, you will get an invalid domain message when you don&#8217;t supply the subdomain (i.e.  http://site-a.com).  The only way I know of to solve this is with 2 static IPs and 2 certs where one cert is for <code>site-a.com</code> and the other is for <code>*.site-a.com</code>.</p>
<p>I&#8217;m using 192.168.1.200 for the server&#8217;s IP address behind the firewall.  You could try using * instead of 192.168.1.200 in the <code>&lt;VirtualHost&gt;</code> blocks, but I haven&#8217;t tested this.  Leave a comment if you happen to test this. <img src='http://www.cb1inc.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Assuming the stars have aligned, you should have several secured virtual hosts!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2008/09/11/virtual-hosts-and-wildcard-ssl-certificates-with-apache-2-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>High Availability with DRBD and Heartbeat Presentation</title>
		<link>http://www.cb1inc.com/2008/06/10/high-availability-with-drbd-and-heartbeat-presentation/</link>
		<comments>http://www.cb1inc.com/2008/06/10/high-availability-with-drbd-and-heartbeat-presentation/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 16:51:55 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[drbd]]></category>
		<category><![CDATA[heartbeat]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Here's my presentation I gave June 9, 2008, at the <a href="http://mysql.meetup.com/92/">Twin Cities MySQL and PHP User Group</a> about my highly available cluster using <a href="http://www.drbd.org">DRBD</a> and <a href="http://www.linux-ha.org/Heartbeat">Heartbeat</a>.

<div style="width:425px;text-align:left" id="__ss_458973"><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=high-availability-with-drbd-heartbeat-1213116273279688-9"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=high-availability-with-drbd-heartbeat-1213116273279688-9" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>

I added a few slides and cleaned things up a bit.  The presentation went well and we had a lot of good questions.

The MySQL and PHP User Group will be taking some time off over the summer.  There will be another meetup mid-summer to come up with some ideas for future meetings.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my presentation I gave June 9, 2008, at the <a href="http://mysql.meetup.com/92/">Twin Cities MySQL and PHP User Group</a> about my highly available cluster using <a href="http://www.drbd.org">DRBD</a> and <a href="http://www.linux-ha.org/Heartbeat">Heartbeat</a>.</p>
<div style="margin:0 auto;width:425px;"><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=high-availability-with-drbd-heartbeat-1213116273279688-9"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=high-availability-with-drbd-heartbeat-1213116273279688-9" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>
<p>I added a few slides and cleaned things up a bit.  The presentation went well and we had a lot of good questions.</p>
<p>The MySQL and PHP User Group will be taking some time off over the summer.  There will be another meetup mid-summer to come up with some ideas for future meetings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2008/06/10/high-availability-with-drbd-and-heartbeat-presentation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>mod_dbd MySQL Driver Woes With Ubuntu 7.04</title>
		<link>http://www.cb1inc.com/2008/04/22/mod-dbd-mysql-driver-woes-with-ubuntu-7-04/</link>
		<comments>http://www.cb1inc.com/2008/04/22/mod-dbd-mysql-driver-woes-with-ubuntu-7-04/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 16:58:53 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Apache has a neat module called <a href="http://httpd.apache.org/docs/2.2/mod/mod_dbd.html">mod_dbd</a> that allows your Apache modules to connect to a database.  mod_dbd interfaces with apr_dbd, an Apache Portable Runtime (APR) abstraction layer around database specific drivers.

Back when Ubuntu 7.04 (fiesty) was released, a MySQL driver was not bundled with Apache for licensing concerns.  So, in order to use mod_dbd to connect to a MySQL database, you need to get the MySQL driver source code from WebThing (<a href="http://apache.webthing.com/svn/apache/apr/apr_dbd_mysql.c">apr_dbd_mysql.c</a>) and manually re-compile apr-utils.

You also need the source code for Apache 2.2.3 (which includes <a href="http://packages.ubuntu.com/gutsy/i386/libaprutil1/filelist">apr-utils</a> 1.2.7) from the Ubuntu 7.04 repositories, then copy the apr_dbd_mysql.c file into the Apache source apr-utils/dbd directory.  The Ubuntu guys made a nice INSTALL.MySQL file in the apr-utils with some basic instructions.

What they don't tell you is you need to install the MySQL source.  To make matters worse, once you install it, the apr-utils 1.2.7 configure script can't find it, even if you tell it where it is.

<pre>&#60;snip&#62;
configure: checking for mysql in /usr/src/mysql-dfsg-5.0-5.0.38/include
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
&#60;snip&#62;</pre>

This apparently was a <a href="http://www.techlists.org/archives/web/apache-users/2006-09/msg00540.shtml">known issue</a> and was fixed in apr-utils 1.2.8.

Starting with <a href="http://svn.apache.org/viewvc/apr/apr-util/tags/1.2.11/dbd/">apr-utils 1.2.11</a>, the MySQL driver is bundled with it.  Unfortunately, even Ubuntu 7.10 (gutsy) still ships with apr-utils 1.2.7.  So, you are forced to download the source and compile.

Or, you can wait a couple days and Ubuntu 8.04 (hardy) which has <a href="http://packages.ubuntu.com/hardy/web/apache2">Apache 2.2.8</a> and <a href="http://packages.ubuntu.com/hardy/amd64/libaprutil1/filelist">apr-utils 1.2.11</a>.  In theory the MySQL driver will work out of the box.

As for me, I'll be compiling Apache, PHP, MySQL, memcached, and &#60;insert essential infrastructure software&#62; from source like I should have done in the beginning.]]></description>
			<content:encoded><![CDATA[<p>Apache has a neat module called <a href="http://httpd.apache.org/docs/2.2/mod/mod_dbd.html">mod_dbd</a> that allows your Apache modules to connect to a database.  mod_dbd interfaces with apr_dbd, an Apache Portable Runtime (APR) abstraction layer around database specific drivers.</p>
<p>Back when Ubuntu 7.04 (fiesty) was released, a MySQL driver was not bundled with Apache for licensing concerns.  So, in order to use mod_dbd to connect to a MySQL database, you need to get the MySQL driver source code from WebThing (<a href="http://apache.webthing.com/svn/apache/apr/apr_dbd_mysql.c">apr_dbd_mysql.c</a>) and manually re-compile apr-utils.</p>
<p>You also need the source code for Apache 2.2.3 (which includes <a href="http://packages.ubuntu.com/gutsy/i386/libaprutil1/filelist">apr-utils</a> 1.2.7) from the Ubuntu 7.04 repositories, then copy the apr_dbd_mysql.c file into the Apache source apr-utils/dbd directory.  The Ubuntu guys made a nice INSTALL.MySQL file in the apr-utils with some basic instructions.</p>
<p>What they don&#8217;t tell you is you need to install the MySQL source.  To make matters worse, once you install it, the apr-utils 1.2.7 configure script can&#8217;t find it, even if you tell it where it is.</p>
<pre>&lt;snip&gt;
configure: checking for mysql in /usr/src/mysql-dfsg-5.0-5.0.38/include
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
&lt;snip&gt;</pre>
<p>This apparently was a <a href="http://www.techlists.org/archives/web/apache-users/2006-09/msg00540.shtml">known issue</a> and was fixed in apr-utils 1.2.8.</p>
<p>Starting with <a href="http://svn.apache.org/viewvc/apr/apr-util/tags/1.2.11/dbd/">apr-utils 1.2.11</a>, the MySQL driver is bundled with it.  Unfortunately, even Ubuntu 7.10 (gutsy) still ships with apr-utils 1.2.7.  So, you are forced to download the source and compile.</p>
<p>Or, you can wait a couple days and Ubuntu 8.04 (hardy) which has <a href="http://packages.ubuntu.com/hardy/web/apache2">Apache 2.2.8</a> and <a href="http://packages.ubuntu.com/hardy/amd64/libaprutil1/filelist">apr-utils 1.2.11</a>.  In theory the MySQL driver will work out of the box.</p>
<p>As for me, I&#8217;ll be compiling Apache, PHP, MySQL, memcached, and &lt;insert essential infrastructure software&gt; from source like I should have done in the beginning.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2008/04/22/mod-dbd-mysql-driver-woes-with-ubuntu-7-04/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Hello World! Apache Module with KDevelop on Ubuntu</title>
		<link>http://www.cb1inc.com/2007/12/24/creating-a-hello-world-apache-module-with-kdevelop-on-ubuntu/</link>
		<comments>http://www.cb1inc.com/2007/12/24/creating-a-hello-world-apache-module-with-kdevelop-on-ubuntu/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 10:06:55 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[kdevelop]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<iframe src="http://rcm.amazon.com/e/cm?t=ci09-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=0132409674&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000FF&#038;bc1=999999&#038;bg1=F6F6F6&#038;f=ifr" style="float:right;width:120px;height:240px;margin-left:10px;margin-bottom:10px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>

<p>The <a href="http://httpd.apache.org/">Apache HTTP Web Server</a> is a powerful and extensible web server that is the "A" in "LAMP". One of the neat things about Apache is its API for writing custom modules.</p>

<p><a href="http://people.apache.org/~niq/">Nick Kew</a> wrote an excellent book called <a href="http://www.amazon.com/dp/0132409674?tag=ci09-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0132409674&#038;adid=1MDYV18CJT05FYHY83PH&#038;">The Apache Modules Book</a>. Anyone who is serious about Apache module development must buy this book.</p>

<p>Modules can be written a number of ways, but the most common way is to use the C programming language. For an C/C++ development IDE, I use <a href="http://www.kdevelop.org/">KDevelop</a>. It is pretty easy to use once you figure out what you need to do.</p>

<p>It is possible to write modules in C++, but I don't recommend it if your module's source can't be contained in a single source file. There's all sorts of interesting issues with exported symbols and static function declarations. Another reason to stick with C is pretty much all core modules and examples are written using C. You may give it a try and determine that it works just fine for your project.</p>

<h4>Prerequisites</h4>

<p>Before you begin, there is a handful of applications and libraries you must have installed:
<ul>
<li>Apache 2</li>
<li>KDevelop 3.4</li>
<li>GCC (bundled with "build-essential" package)</li>
<li>automake</li>
<li>autoconf</li>
</ul></p>

<h4>Creating the Project</h4>

<p>Launch KDevelop and select "New Project" from the Project menu. Since we are focusing on using C, select "Simple Hello world program" under the "C" folder. Give your module an "Application name" and specify the location to create the project.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-new-project-01.png" alt="KDevelop New Project"/></div>

<p>On the next page of the wizard, you must enter your name, but your email address is not required.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-new-project-02.png" alt="KDevelop New Project"/></div>

<p>The next couple wizard screens ask about version control and source templates. After finishing the wizard, you will be back at the IDE with the new project created.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-ide.png" alt="KDevelop IDE"/></div>

<h4>The Code</h4>

<p>Delete all of the source code that the editor created. Next paste the following code which originated from Nick's version on <a href="http://www.apachetutor.org/book/">The Apache Modules Book Companion site</a>.</p>

<pre>#include &#60;httpd.h&#62;
#include &#60;http_protocol.h&#62;
#include &#60;http_config.h&#62;

static int helloworld_handler(request_rec* r)
{
	if (!r-&#62;handler &#124;&#124; strcmp(r-&#62;handler, "helloworld"))
		return DECLINED;
	
	if (r-&#62;method_number != M_GET)
		return HTTP_METHOD_NOT_ALLOWED;
	
	ap_set_content_type(r, "text/html;charset=ascii");
	ap_rputs("&#60;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&#62;n", r);
	ap_rputs("&#60;html&#62;&#60;head&#62;&#60;title&#62;Hello World!&#60;/title&#62;&#60;/head&#62;", r);
	ap_rputs("&#60;body&#62;&#60;h1&#62;Hello World!&#60;/h1&#62;&#60;/body&#62;&#60;/html&#62;", r);
	return OK;
}

static void register_hooks(apr_pool_t* pool)
{
	ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA helloworld_module = {
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	register_hooks
};
</pre>

<h4>Configuring the Project</h4>

<p>Next we need to reconfigure the build target to create a library instead of a normal program. Right-click the build target and click "Remove":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-remove-target.png" alt="Remove build target"/></div>

<p>When the dialog displays, uncheck the "Also remove from disk" option before clicking "OK". Now we need to add a new build target. Right-click the "src" folder and select "Add Target":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-add-target-01.png" alt="Add new build target"/></div>

<p>From the "Add Target" dialog, change the type to "Libtool Library" and enter the name of the module. Also check the "-avoid-version" and "-module" options.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-add-target-02.png" alt="Add new build target dialog"/></div>

<p>As soon as the target is created, right-click on it and make sure the checked options saved properly.  Right-click on the target again and select "Make Target Active":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-make-target-active.png" alt="Make target active"/></div>

<p>Edit the project's options by right-clicking the "src" folder and selecting "Options":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-project-options-01.png" alt="Src dropdown menu"/></div>

<p>Since this is a C project, we want to add the following options to the "CFLAGS" field:</p>

<pre>-DLINUX=2 -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -pthread</pre>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-project-options-02.png" alt="Options - Compiler"/></div>

<p>From the "Includes" tab, add the following outside include directories:
<ul><li>/usr/includes/apr-1.0</li><li>/usr/includes/apache2</li></ul>
</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-project-options-03.png" alt="Options - Includes"/></div>

<p>Reorder the include paths so that "$(all_includes)" is first. Due to a bug or poor design, you must edit the two paths you just added and prepend a "-I":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-project-options-04.png" alt="Include path prepend -I"/></div>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-project-options-05.png" alt="Include path prepend -I"/></div>

<p>Since we deleted the old build target, we need to add the source files to the target by right-clicking the target and selecting "Add Existing Files":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-add-files-01.png" alt="Adding files to target"/></div>

<p>From the dialog, drag and drop the files you want to be apart of the target. For this simple example, we only move the "mod_helloworld.c" file.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-add-files-02.png" alt="Adding files to target"/></div>

<h4>Building the Project</h4>

<p>We are all set to compile the project. From the "Build" menu, select "Build Active Target":</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-build-01.png" alt="Building the active target"/></div>

<p>If this is the first time you are performing the build, KDevelop will prompt you whether or not you want to run automake. Click the "Run Them" button to continue.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-build-02.png" alt="Run automake dialog"/></div>

<p>When the build is finished, the "Messages" panel will show up and display the build results. If everything went as planned, the output will say the build was successful.</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-build-03.png" alt="Build results"/></div>

<h4>Deploying the Module</h4>

<p>The build process put the shared library file in the following location (assuming debug build):</p>

<pre>/path/to/mod_helloworld/debug/src/.libs/libmod_helloworld</pre>

<p>We need to install that file in the Apache modules directory which on Ubuntu is:</p>

<pre>/usr/lib/apache2/modules</pre>

<p>From a terminal, run the following command as root or sudo:</p>

<pre>cp /path/to/mod_helloworld/debug/src/.libs/libmod_helloworld 
    /usr/lib/apache2/modules/mod_helloworld.so</pre>

<p>Next you'll need to edit the Apache configuration file. In Ubuntu, the file is located at:

<pre>/etc/apache2/apache2.conf</pre>

<p>You need to add the <code>LoadModule</code> and <code>&#60;Location&#62;</code> directives so Apache knows when to invoke the module.</p>

<pre>LoadModule helloworld_module /usr/lib/apache2/modules/mod_helloworld.so
&#60;Location /helloworld&#62;
    SetHandler helloworld
&#60;/Location&#62;</pre>

<p>I've had spotty luck where to actually insert those settings. After the <code>LogLevel</code>, but before any other <code>LoadModule</code> entries seems to work for me. After you save the changes, restart Apache using the following command as root or sudo:</p>

<pre>apache2ctl restart</pre>

<p>If your Apache acts funny, try restarting it again.</p>

<h4>Testing the Module</h4>

<p>The last step is to test the module. Open up your favorite web browser and hit <code>http://localhost/helloworld</code>:</p>

<div align="center"><img src="http://cb1inc.com/sites/default/blog/20071224-browser.png" alt="Hello World in Firefox"/></div>

<p>If everything worked, you should see something similar to the image above.</p>

<h4>Where To Go From Here</h4>

<p>We have only scratched the surface. The Apache Portable Runtime (APR) provides a ton of functionality that makes developing modules much easier. <a href="http://www.amazon.com/dp/0132409674?tag=ci09-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0132409674&#038;adid=1MDYV18CJT05FYHY83PH&#038;">The Apache Modules Book</a> dives into several topics such as configuration settings, content generators, filters, and database connectivity.</p>

<p>Another great resource is Apache's own module source code in their Subversion repository: <a href="http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/">http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/</a>.</p>

]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://rcm.amazon.com/e/cm?t=ci09-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=0132409674&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000FF&#038;bc1=999999&#038;bg1=F6F6F6&#038;f=ifr" style="float:right;width:120px;height:240px;margin-left:10px;margin-bottom:10px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
<p>The <a href="http://httpd.apache.org/">Apache HTTP Web Server</a> is a powerful and extensible web server that is the &#8220;A&#8221; in &#8220;LAMP&#8221;. One of the neat things about Apache is its API for writing custom modules.</p>
<p><a href="http://people.apache.org/~niq/">Nick Kew</a> wrote an excellent book called <a href="http://www.amazon.com/dp/0132409674?tag=ci09-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0132409674&#038;adid=1MDYV18CJT05FYHY83PH&#038;">The Apache Modules Book</a>. Anyone who is serious about Apache module development must buy this book.</p>
<p>Modules can be written a number of ways, but the most common way is to use the C programming language. For an C/C++ development IDE, I use <a href="http://www.kdevelop.org/">KDevelop</a>. It is pretty easy to use once you figure out what you need to do.</p>
<p>It is possible to write modules in C++, but I don&#8217;t recommend it if your module&#8217;s source can&#8217;t be contained in a single source file. There&#8217;s all sorts of interesting issues with exported symbols and static function declarations. Another reason to stick with C is pretty much all core modules and examples are written using C. You may give it a try and determine that it works just fine for your project.</p>
<h4>Prerequisites</h4>
<p>Before you begin, there is a handful of applications and libraries you must have installed:</p>
<ul>
<li>Apache 2</li>
<li>KDevelop 3.4</li>
<li>GCC (bundled with &#8220;build-essential&#8221; package)</li>
<li>automake</li>
<li>autoconf</li>
</ul>
<h4>Creating the Project</h4>
<p>Launch KDevelop and select &#8220;New Project&#8221; from the Project menu. Since we are focusing on using C, select &#8220;Simple Hello world program&#8221; under the &#8220;C&#8221; folder. Give your module an &#8220;Application name&#8221; and specify the location to create the project.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-new-project-01.png" alt="KDevelop New Project"/></div>
<p>On the next page of the wizard, you must enter your name, but your email address is not required.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-new-project-02.png" alt="KDevelop New Project"/></div>
<p>The next couple wizard screens ask about version control and source templates. After finishing the wizard, you will be back at the IDE with the new project created.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-ide.png" alt="KDevelop IDE"/></div>
<h4>The Code</h4>
<p>Delete all of the source code that the editor created. Next paste the following code which originated from Nick&#8217;s version on <a href="http://www.apachetutor.org/book/">The Apache Modules Book Companion site</a>.</p>
<pre class="brush: cpp; title: ;">
#include &lt;httpd.h&gt;
#include &lt;http_protocol.h&gt;
#include &lt;http_config.h&gt;

static int helloworld_handler(request_rec* r)
{
	if (!r-&gt;handler || strcmp(r-&gt;handler, &quot;helloworld&quot;))
		return DECLINED;

	if (r-&gt;method_number != M_GET)
		return HTTP_METHOD_NOT_ALLOWED;

	ap_set_content_type(r, &quot;text/html;charset=ascii&quot;);
	ap_rputs(&quot;&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;&gt;n&quot;, r);
	ap_rputs(&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Hello World!&lt;/title&gt;&lt;/head&gt;;&quot;, r);
	ap_rputs(&quot;&lt;body&gt;&lt;h1&gt;Hello World!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&quot;, r);
	return OK;
}

static void register_hooks(apr_pool_t* pool)
{
	ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA helloworld_module = {
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	register_hooks
};
</pre>
<h4>Configuring the Project</h4>
<p>Next we need to reconfigure the build target to create a library instead of a normal program. Right-click the build target and click &#8220;Remove&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-remove-target.png" alt="Remove build target"/></div>
<p>When the dialog displays, uncheck the &#8220;Also remove from disk&#8221; option before clicking &#8220;OK&#8221;. Now we need to add a new build target. Right-click the &#8220;src&#8221; folder and select &#8220;Add Target&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-add-target-01.png" alt="Add new build target"/></div>
<p>From the &#8220;Add Target&#8221; dialog, change the type to &#8220;Libtool Library&#8221; and enter the name of the module. Also check the &#8220;-avoid-version&#8221; and &#8220;-module&#8221; options.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-add-target-02.png" alt="Add new build target dialog"/></div>
<p>As soon as the target is created, right-click on it and make sure the checked options saved properly.  Right-click on the target again and select &#8220;Make Target Active&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-make-target-active.png" alt="Make target active"/></div>
<p>Edit the project&#8217;s options by right-clicking the &#8220;src&#8221; folder and selecting &#8220;Options&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-project-options-01.png" alt="Src dropdown menu"/></div>
<p>Since this is a C project, we want to add the following options to the &#8220;CFLAGS&#8221; field:</p>
<pre class="brush: plain; title: ;">
-DLINUX=2 -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -pthread
</pre>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-project-options-02.png" alt="Options - Compiler"/></div>
<p>From the &#8220;Includes&#8221; tab, add the following outside include directories:</p>
<ul>
<li>/usr/includes/apr-1.0</li>
<li>/usr/includes/apache2</li>
</ul>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-project-options-03.png" alt="Options - Includes"/></div>
<p>Reorder the include paths so that &#8220;$(all_includes)&#8221; is first. Due to a bug or poor design, you must edit the two paths you just added and prepend a &#8220;-I&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-project-options-04.png" alt="Include path prepend -I"/></div>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-project-options-05.png" alt="Include path prepend -I"/></div>
<p>Since we deleted the old build target, we need to add the source files to the target by right-clicking the target and selecting &#8220;Add Existing Files&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-add-files-01.png" alt="Adding files to target"/></div>
<p>From the dialog, drag and drop the files you want to be apart of the target. For this simple example, we only move the &#8220;mod_helloworld.c&#8221; file.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-add-files-02.png" alt="Adding files to target"/></div>
<h4>Building the Project</h4>
<p>We are all set to compile the project. From the &#8220;Build&#8221; menu, select &#8220;Build Active Target&#8221;:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-build-01.png" alt="Building the active target"/></div>
<p>If this is the first time you are performing the build, KDevelop will prompt you whether or not you want to run automake. Click the &#8220;Run Them&#8221; button to continue.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-build-02.png" alt="Run automake dialog"/></div>
<p>When the build is finished, the &#8220;Messages&#8221; panel will show up and display the build results. If everything went as planned, the output will say the build was successful.</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-build-03.png" alt="Build results"/></div>
<h4>Deploying the Module</h4>
<p>The build process put the shared library file in the following location (assuming debug build):</p>
<pre class="brush: plain; title: ;">
/path/to/mod_helloworld/debug/src/.libs/libmod_helloworld
</pre>
<p>We need to install that file in the Apache modules directory which on Ubuntu is:</p>
<pre class="brush: plain; title: ;">
/usr/lib/apache2/modules
</pre>
<p>From a terminal, run the following command as root or sudo:</p>
<pre class="brush: plain; title: ;">
cp /path/to/mod_helloworld/debug/src/.libs/libmod_helloworld /usr/lib/apache2/modules/mod_helloworld.so
</pre>
<p>Next you&#8217;ll need to edit the Apache configuration file. In Ubuntu, the file is located at:</p>
<pre class="brush: plain; title: ;">
/etc/apache2/apache2.conf
</pre>
<p>You need to add the <code>LoadModule</code> and <code>&lt;Location&gt;</code> directives so Apache knows when to invoke the module.</p>
<pre class="brush: plain; title: ;">
LoadModule helloworld_module /usr/lib/apache2/modules/mod_helloworld.so
&lt;Location /helloworld&gt;
    SetHandler helloworld
&lt;/Location&gt;
</pre>
<p>I&#8217;ve had spotty luck where to actually insert those settings. After the <code>LogLevel</code>, but before any other <code>LoadModule</code> entries seems to work for me. After you save the changes, restart Apache using the following command as root or sudo:</p>
<pre class="brush: plain; title: ;">
apache2ctl restart
</pre>
<p>If your Apache acts funny, try restarting it again.</p>
<h4>Testing the Module</h4>
<p>The last step is to test the module. Open up your favorite web browser and hit <code>http://localhost/helloworld</code>:</p>
<div align="center"><img src="/wp-content/uploads/2009/12/20071224-browser.png" alt="Hello World in Firefox"/></div>
<p>If everything worked, you should see something similar to the image above.</p>
<h4>Where To Go From Here</h4>
<p>We have only scratched the surface. The Apache Portable Runtime (APR) provides a ton of functionality that makes developing modules much easier. <a href="http://www.amazon.com/dp/0132409674?tag=ci09-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0132409674&#038;adid=1MDYV18CJT05FYHY83PH&#038;">The Apache Modules Book</a> dives into several topics such as configuration settings, content generators, filters, and database connectivity.</p>
<p>Another great resource is Apache&#8217;s own module source code in their Subversion repository: <a href="http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/">http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2007/12/24/creating-a-hello-world-apache-module-with-kdevelop-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Self-Signed Certs on Apache 2.2</title>
		<link>http://www.cb1inc.com/2007/05/13/creating-self-signed-certs-on-apache-2-2/</link>
		<comments>http://www.cb1inc.com/2007/05/13/creating-self-signed-certs-on-apache-2-2/#comments</comments>
		<pubDate>Sun, 13 May 2007 23:07:14 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Security is a always a big concern and there's no reason your website should go unsecure. You can secure your Apache website with a self-signed SSL certificate. This post describes the process using Apache 2.2 and <a href="http://www.openssl.org" target="_blank">OpenSSL</a> on a Ubuntu Linux server.

Begin by generating a private key:

<div class="cb1-docs-code"><pre>&#62; openssl genrsa -out mycert.key 1024</pre></div>

Next, generating a certificate request and enter the information:

<div class="cb1-docs-code"><pre>&#62; openssl req -new -key mycert.key -out mycert.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:</pre></div>

Next, generate the self-signed certificate. You can specify the number of days the cert is valid for.

<div class="cb1-docs-code"><pre>&#62; openssl x509 -req -days 365 -in mycert.csr -signkey mycert.key -out mycert.cert
Signature ok
subject=/C=/ST=/L=/O=/CN=
Getting Private key</pre></div>

You no longer need the .csr request file. Create a folder and move the .key and .cert files into it:

<div class="cb1-docs-code"><pre>&#62; sudo mkdir /etc/apache2/ssl
&#62; sudo mv *.cert /etc/apache2/ssl
&#62; sudo mv *.key /etc/apache2/ssl
&#62; sudo chmod 400 /etc/apache2/ssl/*.key</pre></div>

If the cert is protected with a password, by default Apache will prompt for the password when it starts. This can be a problem since you will need to enter the password each time Apache is restarted. We can fix this by having Apache call a program that returns the password.

Create the shell script <code>/etc/apache2/ssl/password.sh</code> and enter the following:

<div class="cb1-docs-code"><pre>#!/bin/bash
echo “password”;</pre></div>

Next we need to tell Apache to run the script. Apache's SSL settings are stored in:

<div class="cb1-docs-code"><pre>/etc/apache2/mods-enabled/ssl.conf</pre></div>

Edit the file and change the <code>SSLPassPhraseDialog</code> to:

<div class="cb1-docs-code"><pre>SSLPassPhraseDialog exec:/etc/apache2/ssl/password.sh</pre></div>

The last step is to assign the certificate to your Apache site by editing the sites file:

<div class="cb1-docs-code"><pre>/etc/apache2/sites-enabled/000-default</pre></div>

You'll need to configure the SSL settings for the site:

<div class="cb1-docs-code"><pre>&#60;VirtualHost 192.168.1.100:443&#62;
        ...
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/mycert.cert
        SSLCertificateKeyFile /etc/apache2/ssl/mycert.key
        ...
&#60;/VirtualHost&#62;</pre></div>

Don't forget to tell Apache to listen on port 443 in the <code>/etc/apache2/ports.conf</code> file. Restart Apache with <code>sudo apache2ctl restart</code> and you should be a little closer to being secure.]]></description>
			<content:encoded><![CDATA[<p>Security is a always a big concern and there&#8217;s no reason your website should go unsecure. You can secure your Apache website with a self-signed SSL certificate. This post describes the process using Apache 2.2 and <a href="http://www.openssl.org" target="_blank">OpenSSL</a> on a Ubuntu Linux server.</p>
<p>Begin by generating a private key:</p>
<pre class="brush: plain; title: ;">
$ openssl genrsa -out mycert.key 1024
</pre>
<p>Next, generating a certificate request and enter the information:</p>
<pre class="brush: plain; title: ;">
$ openssl req -new -key mycert.key -out mycert.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
</pre>
<p>Next, generate the self-signed certificate. You can specify the number of days the cert is valid for.</p>
<pre class="brush: plain; title: ;">
$ openssl x509 -req -days 365 -in mycert.csr -signkey mycert.key -out mycert.cert
Signature ok
subject=/C=/ST=/L=/O=/CN=
Getting Private key
</pre>
<p>You no longer need the .csr request file. Create a folder and move the .key and .cert files into it:</p>
<pre class="brush: bash; title: ;">
$ sudo mkdir /etc/apache2/ssl
$ sudo mv *.cert /etc/apache2/ssl
$ sudo mv *.key /etc/apache2/ssl
$ sudo chmod 400 /etc/apache2/ssl/*.key
</pre>
<p>If the cert is protected with a password, by default Apache will prompt for the password when it starts. This can be a problem since you will need to enter the password each time Apache is restarted. We can fix this by having Apache call a program that returns the password.</p>
<p>Create the shell script <code>/etc/apache2/ssl/password.sh</code> and enter the following:</p>
<pre class="brush: bash; title: ;">
#!/bin/bash
echo “password”;
</pre>
<p>Next we need to tell Apache to run the script. Apache&#8217;s SSL settings are stored in:</p>
<pre class="brush: plain; title: ;">
/etc/apache2/mods-enabled/ssl.conf
</pre>
<p>Edit the file and change the <code>SSLPassPhraseDialog</code> to:</p>
<pre class="brush: plain; title: ;">
SSLPassPhraseDialog exec:/etc/apache2/ssl/password.sh
</pre>
<p>The last step is to assign the certificate to your Apache site by editing the sites file:</p>
<pre class="brush: plain; title: ;">
/etc/apache2/sites-enabled/000-default
</pre>
<p>You&#8217;ll need to configure the SSL settings for the site:</p>
<pre class="brush: plain; title: ;">
&lt;VirtualHost 192.168.1.100:443&gt;
        ...
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/mycert.cert
        SSLCertificateKeyFile /etc/apache2/ssl/mycert.key
        ...
&lt;/VirtualHost&gt;
</pre>
<p>Don&#8217;t forget to tell Apache to listen on port 443 in the <code>/etc/apache2/ports.conf</code> file. Restart Apache with <code>sudo apache2ctl restart</code> and you should be a little closer to being secure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2007/05/13/creating-self-signed-certs-on-apache-2-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Self-Signed Certs on Apache Tomcat 5.5</title>
		<link>http://www.cb1inc.com/2007/05/12/creating-self-signed-certs-on-apache-tomcat-5-5/</link>
		<comments>http://www.cb1inc.com/2007/05/12/creating-self-signed-certs-on-apache-tomcat-5-5/#comments</comments>
		<pubDate>Sat, 12 May 2007 15:13:32 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Recently I needed to generate a self-signed SSL cert for Apache Tomcat 5.5 on my Ubuntu Linux server. The basic process is to create a Java keystore with the self-signed cert, change Tomcat's configuration file, and restart the server. Here's how I did it:

<div class="cb1-docs-code"><pre>&#62; keytool -genkey -alias tomcat -keyalg RSA -keystore mycert.jks
Enter keystore password:  changeit
What is your first and last name?
  [Unknown]:  Chris Barber
What is the name of your organizational unit?
  [Unknown]:  
What is the name of your organization?
  [Unknown]:  CB1, INC.
What is the name of your City or Locality?
  [Unknown]:  Minneapolis
What is the name of your State or Province?
  [Unknown]:  MN
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=Chris Barber, OU=Unknown, O="CB1, INC.", L=Minneapolis, ST=MN, C=US correct?
  [no]:  yes

Enter key password for <tomcat>
        (RETURN if same as keystore password):  
</pre></div>

By default, Tomcat will assume the password as "changeit".  You can change the password, but then you need to set the keystorePass in Tomcat's configuration file. Regardless, the password for both the keystore and the cert MUST be the same.  Store the keystore in a safe place such as Tomcat's configuration folder:

<div class="cb1-docs-code"><pre>/etc/tomcat5.5</pre></div>

Next edit Tomcat's server configuration file:

<div class="cb1-docs-code"><pre>/etc/tomcat5.5/server.xml</pre></div>

Locate the SSL connector declaration, uncomment it, and add the keystoreFile path:

<div class="cb1-docs-code"><pre>
&#60;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&#62;
&#60;Connector port="8443" maxHttpHeaderSize="8192"
        maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
        enableLookups="false" disableUploadTimeout="true"
        acceptCount="100" scheme="https" secure="true"
        keystoreFile="/etc/tomcat5.5/mycert.jks"
        clientAuth="false" sslProtocol="TLS" /&#62;
</pre></div>

Save the changes and restart Tomcat:

<div class="cb1-docs-code"><pre>sudo /etc/init.d/tomcat5.5 restart</pre></div>

You should be good to go at this point. Launch your <a href="http://www.mozilla.com" target="_blank">favorite web browser</a> and go to https://localhost:8443.

<div align="center"><img alt="SSL dialog" src="/sites/default/blog/20070512-ssl.png" /></div>

Now you are secure and ready to rock.]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to generate a self-signed SSL cert for Apache Tomcat 5.5 on my Ubuntu Linux server. The basic process is to create a Java keystore with the self-signed cert, change Tomcat&#8217;s configuration file, and restart the server. Here&#8217;s how I did it:</p>
<pre class="brush: plain; title: ;">
$ keytool -genkey -alias tomcat -keyalg RSA -keystore mycert.jks
Enter keystore password:  changeit
What is your first and last name?
  [Unknown]:  Chris Barber
What is the name of your organizational unit?
  [Unknown]:
What is the name of your organization?
  [Unknown]:  CB1, INC.
What is the name of your City or Locality?
  [Unknown]:  Minneapolis
What is the name of your State or Province?
  [Unknown]:  MN
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=Chris Barber, OU=Unknown, O=&quot;CB1, INC.&quot;, L=Minneapolis, ST=MN, C=US correct?
  [no]:  yes

Enter key password for &lt;tomcat&gt;
        (RETURN if same as keystore password):
</pre>
<p>By default, Tomcat will assume the password as &#8220;changeit&#8221;.  You can change the password, but then you need to set the keystorePass in Tomcat&#8217;s configuration file. Regardless, the password for both the keystore and the cert MUST be the same.  Store the keystore in a safe place such as Tomcat&#8217;s configuration folder:</p>
<pre class="brush: plain; title: ;">
/etc/tomcat5.5
</pre>
<p>Next edit Tomcat&#8217;s server configuration file:</p>
<pre class="brush: plain; title: ;">
/etc/tomcat5.5/server.xml
</pre>
<p>Locate the SSL connector declaration, uncomment it, and add the keystoreFile path:</p>
<pre class="brush: plain; title: ;">
&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&gt;
&lt;Connector port=&quot;8443&quot; maxHttpHeaderSize=&quot;8192&quot;
        maxThreads=&quot;150&quot; minSpareThreads=&quot;25&quot; maxSpareThreads=&quot;75&quot;
        enableLookups=&quot;false&quot; disableUploadTimeout=&quot;true&quot;
        acceptCount=&quot;100&quot; scheme=&quot;https&quot; secure=&quot;true&quot;
        keystoreFile=&quot;/etc/tomcat5.5/mycert.jks&quot;
        clientAuth=&quot;false&quot; sslProtocol=&quot;TLS&quot; /&gt;
</pre>
<p>Save the changes and restart Tomcat:</p>
<pre class="brush: plain; title: ;">
$ sudo /etc/init.d/tomcat5.5 restart
</pre>
<p>You should be good to go at this point. Launch your <a href="http://www.mozilla.com" target="_blank">favorite web browser</a> and go to https://localhost:8443.</p>
<div align="center"><img alt="SSL dialog" src="/wp-content/uploads/2009/12/20070512-ssl1.png" /></div>
<p>Now you are secure and ready to rock.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2007/05/12/creating-self-signed-certs-on-apache-tomcat-5-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

