VirtualHost rewrite rules for Silex

November 9, 2011

After seeing Igor Wiedler's presentation on symfony Day I really wanted to try SIlex. It's a PHP micro-framework that seems especially well-suited for creating small sites and API's.

The Silex documentation lists the Apache rewrite rules when using a .htaccess file:

  <IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    #RewriteBase /path/to/app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
  </IfModule>

But if possible, I put the Apache rewrite rules into the VirtualHost configuration. This requires to change the rules a bit. Namely adding a slash to index.php.

VirtualHost settings:

    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /index.php [L]

So I hope this will be useful to someone. Happy coding!

Free fonts for presentations

November 6, 2011

For presentations it is always good to have nice looking and readable fonts. Usually I publish my presentations as PDF on Slideshare. Because fonts are embedded in the PDF document they should be free to use. I have been looking around for quite a while and have tried various fonts. At the moment I use the following set of fonts.

Fonts
Calluna Sans Body text (Sans-Serif)
Calluna Title, quotes (Serif)
Inconsolata Code (Monospace)
Architect's Daughter Notes (Handwritten)

A collection of free fonts is available from Google web fonts. Inconsolata and Architect's Daughter fonts are in there. The complete collection is available as a mercurial repository:
hg clone https://googlefontdirectory.googlecode.com/hg/ googlefontdirectory

Mobilism Workshop Frankfurt

August 11, 2011

Lately, I have been looking into development for the mobile web. Fortunately I was offered the opportunity to host a mobile web workshop in Frankfurt on 28 + 29 Sept. 2011 as part of the Mobilism Workshops Series.

Mobilism workshops are a two-day affair where at least half of the time is spent in actually testing websites on mobile devices; including a few you've never even heard of. The other half of the time is taken up by PPK and Stephen Hay talking about various aspects of mobile web design and development.

So if you are interested and live in Germany, register for the workshop.

Getting host interface networking to work again in VirtualBox

March 19, 2011

After installing a new version of openSUSE I had some issues with VirtualBox. Before the install I exported my virtual machines (VM) as appliances. This makes it easy to re-use VMs without having to install an OS from scratch. Exporting and importing is literally as easy as clicking a button.

Unfortunately after importing my VMs, I got the following error message:

Failed to open a session for the virtual machine Windows.

Failed to open/create the internal network 'HostInterfaceNetworking-eth0' (VERR_SUPDRV_COMPONENT_NOT_FOUND).

One of the kernel modules was not successfully loaded. Make sure that no kernel modules from an older version of VirtualBox exist. Then try to recompile and reload the kernel modules by executing '/etc/init.d/vboxdrv setup' as root (VERR_SUPDRV_COMPONENT_NOT_FOUND)

Running /etc/init.d/vboxdrv setup actually did not help. I was told the kernel module was already installed. Running the network in NAT mode worked. Only the bridged adapter option caused this error and I really needed that option to communicate between VMs over ssh.

After some searching, it turned out that openSUSE had installed the VirtualBox guest kernel module. That is apparently useful if you run openSUSE inside VirtualBox. But I was running VirtualBox inside openSUSE.

So in Yast I added the virtualbox-host-kmp-desktop package and removed all virtualbox-guest-* packages. Rebooted and problem solved!

Using pretty URLs in concrete5 with Nginx

February 12, 2011

The Nginx web server is becoming ever more popular as an alternative to Apache. Especially if you want to use the PHP FastCGI Process Manager (php-fpm) that shipped with PHP 5.3.3.

Lately I have been using the concrete5 CMS a lot. It offers an option to use pretty URLs, but only tells how to configure it for Apache. After reading the Nginx documentation and searching the web I came up with a simple configuration (tested with nginx-0.8.54).

http {
  include mime.types;
  default_type application/octet-stream;
  sendfile on;
  keepalive_timeout 65;
  access_log logs/access.log;
  index index.html index.php;

  #default server
  server {
    listen 80 default_server;
    server_name _;
    root html;
  }

  #concrete5
  server {
    server_name concrete5.com www.concrete5.com;
    root /srv/www/vhosts/concrete5.com;
    access_log logs/concrete5.access.log;

    location / {
      try_files $uri $uri/ /index.php/$request_uri;
    }

    #pass PHP scripts to FastCGI server
    location ~ \.php($|/) {
      set $script $uri;
      if ($uri ~ "^(.+\.php)(/.+)") {
        set $script $1;
      }

      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$script;
      fastcgi_intercept_errors on;
      fastcgi_pass 127.0.0.1:9000;
    }
}