Posted on 7 Comments

Setting up an Active Directory domain controller with Samba 4 on a Raspberry Pi 3

RaspberryPi Logo

The Raspberry Pi is a wonderful platform to simplify your daily IT jobs, such as serving as a media centre for your smart-TV, being the central hub for your home automation system or in the case at hand act as an Active Directory (AD) domain controller in a test lab. Obviously, we are talking about the Samba variant of the Active Directory implementation available since version 4 since the original one offered by the folks at Microsoft requires a x86 architecture which the Raspberry fails to provide using its ARM system. But hey, in the end for this scenario we don’t care too much about the underyling hardware but merely focus on the functional aspect. So let’s begin, shall we?

Raspberry Pi setup used

For the following guide I’ve used a vanilla Raspberry Pi 3 in the following configuration (although the setup should be just fine for other versions too):

$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Our goal at glance

Let’s break down what we need to do in order to achieve our goal to set up an Active Directory domain controller with Samba 4 on a Raspberry Pi 3:

  1. Initial setup of the Raspberry Pi using Raspbian
  2. Setup networking to use a static IP
  3. Install required packages
  4. Disable masked legacy service units
  5. Provision the AD domain
  6. Setup and start required Samba AD domain controller services
  7. Reboot
  8. Check setup by creating new AD user and add a client computer

For this particular setup we are going to use the following base information:

  • router has IP 192.168.1.1
  • hostname is pidc
  • pidc has IP 192.168.1.2
  • domain to be used my.domain.local

Initial setup of the Raspberry Pi using Raspbian

We are not going to cover this here since there are plenty of readups out there. Thus, please check them out and bootstrap your Raspberry Pi using Raspbian. Also make sure that your base system is at the latest version before proceeding further (i.e. sudo apt-get update && apt-get upgrade -V)

Setup networking to use a static IP

With an AD in place you will always want to have a static IP to keep things simple:

$ sudo nano /etc/dhcpcd.conf
# explicitely use eth0 and set static IPs, as well as domain specifics
interface eth0
static routers=192.168.1.1
static domain_name_servers=127.0.0.1
static domain_name_servers=192.168.1.1
static ip_address=192.168.1.2
static domain_search=my.domain.local

Install required packages

Next we need to install the required packages:

$ sudo apt-get install samba smbclient winbind krb5-user krb5-config krb5-locales winbind libpam-winbind libnss-winbind

During the setup you will be asked for

  • Default Kerberos realm
  • Kerberos servers
  • Administrative server

Based on our domain setup you need to enter the following data:

  • Default Kerberos realm: MY.DOMAIN.LOCAL
  • Kerberos servers: my.domain.local
  • Administrative server: pidc.my.domain.local

Disable masked legacy service units

In order to prevent error message related to masked legacy service units issue the following commands to stop and then fully disable them:

$ sudo systemctl stop samba-ad-dc.service smbd.service nmbd.service winbind.service
$ sudo systemctl disable samba-ad-dc.service smbd.service nmbd.service winbind.service

Provision the AD domain

Before being able to actually provision our AD domain let’s do a little house keeping round to make our life easier:

# double-check where the samba config file resides
$ smbd -b | grep "CONFIGFILE"
# let's make a backup of the original samba configuration determined above
$ sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.backup
# also, let's remove the original kerberos configuration, as it will be overwritten and edited later on
$ sudo rm /etc/krb5.conf

Having done those steps it’s finally time to provision our AD domain:

$ sudo samba-tool domain provision --use-rfc2307 --interactive

The provisioning process might take a little. When completed let’s handle the Kerberos configuration:

# again, let's make a backup of the original
$ sudo mv /etc/krb5.conf /etc/krb5.conf.backup
# and symlink to /etc/krb5.conf => NOTE: It's not the best to symlink here but it's OK for now
$ sudo ln -sf /var/lib/samba/private/krb5.conf /etc/krb5.conf

Hint: We will come back to /etc/krb5.conf at the very end for potential missing information so hang in there for now.

Setup and start required Samba AD domain controller services

Finally, let’s start setup and start the required Samba AD domain controller services to get things moving:

$ sudo systemctl unmask samba-ad-dc.service
$ sudo systemctl start samba-ad-dc.service
$ sudo systemctl status samba-ad-dc.service
$ sudo systemctl enable samba-ad-dc.service

Time to check if Samba is running correctly:

$ sudo netstat -tulpn | egrep 'smbd|samba'

Also, make sure to set the search domain and your nameservers in /etc/resolv.conf correctly at this point:

$ sudo nano /etc/resolv.conf

search domain.name.net
nameserver 192.168.1.2
nameserver 192.168.1.1

Once completed, mark /etc/resolv.conf as write-protected to save yourself some pain after reboots:

$ sudo chattr +i /etc/resolv.conf

Reboot

Time to reboot your shiny new AD domain controller setup to take effect:

$ sudo reboot now

Check setup by creating new AD user and add a client computer

# do some simple ping tests
$ ping -c3 my.domain.local
$ ping -c3 pidc.my.domain.local
$ ping -c3 pidc

# test DNS configuration
$ host -t A my.domain.local
$ host -t A pidc.my.domain.local
$ host -t SRV _kerberos._udp.my.domain.local
$ host -t SRV _ldap._tcp.my.domain.local

# test kerberos ticketing => Note the upper-case!
$ kinit administrator@MY.DOMAIN.LOCAL
$ klist
# create a (test) domain user
$ sudo samba-tool user create some.user

More detailed information and the commands available for the create domain user call can be found on the Samba Wiki.

Possible trouble shooting tips for DNS / Kerberos / Samba

If you get an error message like “Cannot contact any KDC for realm while getting initial credentials” first check if Kerberos was in fact started correctly and is listening on port 88 (or a custom port that you’ve defined earlier), e.g. using telnet:

$ telnet pidc.my.domain.local 88

If you are not able to connect (e.g. “Connection refused”) make sure that the Samba services including KDC (Kerberos) is in fact set to be started. For this check the [global] section of your /etc/samba/smb.conf:

$ sudo nano /etc/samba/smb.conf

and add the following line if required:

server services = rpc, nbt, wrepl, ldap, cldap, kdc, drepl, winbind, ntp_signd, kcc, dnsupdate, dns, s3fs

Afterwards restart Samba and re-test KDC kinit:

$ sudo systemctl stop samba-ad-dc.service
$ sudo systemctl start samba-ad-dc.service

Re-test kinit:

$ kinit administrator@MY.DOMAIN.LOCAL

In addition, also make sure that you have a working version of your /etc/krb5.conf, especially for the [realms] and [domain_realm] section:

[libdefaults]
default_realm = MY.DOMAIN.LOCAL
dns_lookup_realm = true
dns_lookup_kdc = true
dns_fallback = yes

[realms]
MY.DOMAIN.LOCAL = {
kdc = PIDC.MY.DOMAIN.LOCAL:88
default_domain = MY.DOMAIN.LOCAL
}

[domain_realm]
.MY.DOMAIN.LOCAL = MY.DOMAIN.LOCAL
MY.DOMAIN.LOCAL = MY.DOMAIN.LOCAL

Finally, make sure that Samba itself is fully started, including all of its services, especially after a reboot:

$ samba

Next steps / Where to go from here

As usual, when dealing with an Active Directory setup you should always have a secondary backup domain controller. The steps to do so are pretty straight forward given the guidelines shown here. Simply hook up a second Raspberry Pi and configure it as your secondary domain controller.

If you are running this setup in a test lab you might not need a backup domain controller but as always make sure to back up your Raspberry as an image to have a quick restore point to go to, e.g. using the following command:

$ dd if=/dev/mmcblk0 of=/your-backup-path/YOUR-BACKUP-NAME-$(date +%Y%m%d-%H%M%S).img bs=1MB

That’s all folks! I hope this saves you some time when setting up an Active Directory domain controller with Samba 4 on a Raspberry Pi 3.

Posted on Leave a comment

Setting up MongoDB on Debian Wheezy 64Bit

MongoDB Logo

Here are the steps required for setting up MongoDB on Debian Wheezy. This is the manual guide since the official MongoDB packages provided by Debian are a little dusty. Don’t worry, the setup process is pretty straight forward. Let’s get started!

Import public key for package management tool apk

First you need to import the public key for your package management tool. In this case apk:

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.YX8vkOfNgq --trustdb-name /etc/apt//trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-wheezy-stable.gpg --keyserver keyserver.ubuntu.com --recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Add MongoDB to package list

echo “deb http://repo.mongodb.org/apt/debian “$(lsb_release -sc)“/mongodb-org/3.0 main” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Note that this command requires lsb_release.  In case you haven’t installed it do so by issuing the following command:

sudo apt-get install lsb_release

Refresh local package list

In order to check for your new package entry reload your local package list:

apt-get update

...
Get:1 http://repo.mongodb.org wheezy/mongodb-org/3.0 Release.gpg [490 B]
Hit https://repo.varnish-cache.org wheezy/varnish-4.0 amd64 Packages
Get:2 http://repo.mongodb.org wheezy/mongodb-org/3.0 Release [2,017 B]
Get:3 http://repo.mongodb.org wheezy/mongodb-org/3.0/main amd64 Packages [4,113 B]
Fetched 6,620 B in 1s (3,471 B/s)
Reading package lists... Done

Install MongoDB

Now it’s time to actually install MongoDB – hurray! We are going to install the latest stable release. In case you want to install a specific release version simply specify the release number.

Install latest stable MongoDB

sudo apt-get install -y mongodb-org

Install specific MongoDB version

Replace VERSION-XYZ with your desired MongoDB version, e.g. 3.0.4-rc0:

sudo apt-get install -y mongodb-org=VERSION-XYZ mongodb-org-server=VERSION-XYZ mongodb-org-shell=VERSION-XYZ mongodb-org-mongos=VERSION-XYZ mongodb-org-tools=VERSION-XYZ

Check installation messages

Watch for the following installation messages to ensure that MongoDB was setup corectly:

Setting up mongodb-org-shell (3.0.3) ...
Setting up mongodb-org-server (3.0.3) ...
Adding system user `mongodb' (UID 111) ...
Adding new user `mongodb' (UID 111) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 113) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
[ ok ] Starting database: mongod.
Setting up mongodb-org-mongos (3.0.3) ...
Setting up mongodb-org-tools (3.0.3) ...
Setting up mongodb-org (3.0.3) ...

That’s it for the installation – Congratulations! By default, MongoDB listens on port 27017 for incoming requests. Please refer to /etc/mongod.conf for changing it, see section Configure MongoDB below

Run MongoDB

Once you’ve installed MongoDB here are the commands to control MongoDB.

Start MongoDB

sudo service mongod start

Verify status MongoDB

In order to verify the status of MongoDB have a look at log file located at

/var/log/mongodb/mongod.log

and watch out for the line

2015-06-14T10:21:05.027+0200 I NETWORK [initandlisten] waiting for connections on port 27017

Stop MongoDB

Like starting MongoDB use the service facilities to stop MongoDB:

sudo service mongod stop

Configure MongoDB

MongoDB can be configured using /etc/mongod.conf The file is pretty self-explanatory for the basic settings. Please refer to the Getting Started Guides for more information. Enjoy!

Posted on Leave a comment

Install PHP intl extension using Homebrew on XAMPP

PHP Logo

Recently, when trying to install the PHP intl extension for a Symfony2 based web project using Homebrew to following error message kept showing up:

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory /usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

This post steps explains what is needed to install PHP intl extension using Homebrew on XAMPP.

Reinstall required?

Trying to do a quick re-install did not succeed:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again:

bash-3.2$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

So, basically it’s advised to remove existing files and re-start the installer which resulted in

rm: /usr/local/Cellar/libmemcached/1.0.18/AUTHORS: Permission denied

rm: /usr/local/Cellar/libmemcached/1.0.18/bin/memcapable: Permission denied

rm: /usr/local/Cellar/libmemcached/1.0.18/bin/memcat: Permission denied

… and many more errors

Sudo to the rescue?

Ok, so let’s remove the files using sudo:

bash-3.2$ sudo rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Password: *****

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

Well, this is kind of embarrassing 🙂

Since the folder have been successfully removed it might just be the brew cleanup command that causes the problems?

bash-3.2$ sudo brew cleanup

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

It’s not 🙂 So, after manually removing these directories again it’s time for another attempt to call the brew installer:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

==> This script will install:

/usr/local/bin/brew

/usr/local/Library/…

/usr/local/share/man/man1/brew.1

==> The following directories will be made group writable:

/usr/local/sbin

/usr/local/share/man/man7

Press RETURN to continue or any other key to abort

==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin /usr/local/share/man/man7

==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew

==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew

==> Downloading and installing Homebrew…

remote: Counting objects: 3580, done.

remote: Compressing objects: 100% (3426/3426), done.

remote: Total 3580 (delta 35), reused 1458 (delta 18), pack-reused 0

Receiving objects: 100% (3580/3580), 2.74 MiB | 963.00 KiB/s, done.

Resolving deltas: 100% (35/35), done.

From https://github.com/Homebrew/homebrew

* [new branch]      master     -> origin/master

error: unable to unlink old ‘Library/Homebrew/extend/ENV/shared.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/extend/ENV/std.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/extend/ENV/super.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/hooks/bottles.rb’ (Permission denied)

error: unable to create file Library/Homebrew/language/go.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/language/haskell.rb’ (Permission denied)

error: unable to create file Library/Homebrew/language/java.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/language/python.rb’ (Permission denied)

error: unable to create file Library/Homebrew/utils/fork.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/utils/inreplace.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/utils/json.rb’ (Permission denied)

error: unable to create file Library/Homebrew/utils/popen.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/vendor/okjson.rb’ (Permission denied)

Checking out files: 100% (3584/3584), done.

fatal: Could not reset index file to revision ‘origin/master’.

Failed during: git reset –hard origin/master

Almost! As you can see we also need to manually remove the Library/Homebrew folder and finally it works:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

==> This script will install:

/usr/local/bin/brew

/usr/local/Library/…

/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort

==> Downloading and installing Homebrew…

remote: Counting objects: 3580, done.

remote: Compressing objects: 100% (3426/3426), done.

remote: Total 3580 (delta 35), reused 1458 (delta 18), pack-reused 0

Receiving objects: 100% (3580/3580), 2.74 MiB | 502.00 KiB/s, done.

Resolving deltas: 100% (35/35), done.

From https://github.com/Homebrew/homebrew

* [new branch]      master     -> origin/master

HEAD is now at f45116a swiftlint: add 0.1.0 bottle.

==> Installation successful!

==> Next steps

Run `brew help` to get started

bash-3.2$ brew help

Example usage:

  brew [info | home | options ] [FORMULA…]

  brew install FORMULA…

  brew uninstall FORMULA…

  brew search [foo]

  brew list [FORMULA…]

  brew update

  brew upgrade [–all | FORMULA…]

  brew pin/unpin [FORMULA…]

Troubleshooting:

  brew doctor

  brew install -vd FORMULA

  brew [–env | config]

Brewing:

  brew create [URL [–no-fetch]]

  brew edit [FORMULA…]

  open https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md

Further help:

  man brew

  brew home

Pretty easy, right? 😉 Now it’s time to actually install the PHP intl extension.

Install PHP intl extension using Homebrew

To actually install the PHP intl extension we can use Homebrew, thanks to Gigamike for the tip:

bash-3.2$ brew install icu4c

==> Downloading https://homebrew.bintray.com/bottles/icu4c-55.1.yosemite.bottle.tar.gz

######################################################################## 100,0%

==> Pouring icu4c-55.1.yosemite.bottle.tar.gz

==> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in

parallel can cause all kinds of trouble.

OS X provides libicucore.dylib (but nothing else).

Generally there are no consequences of this for you. If you build your

own software and it requires this formula, you’ll need to add to your

build variables:

    LDFLAGS:  -L/usr/local/opt/icu4c/lib

    CPPFLAGS: -I/usr/local/opt/icu4c/include

==> Summary

🍺  /usr/local/Cellar/icu4c/55.1: 244 files, 66M

And then finally install intl:

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

Cannot find autoconf phpize failed

In case you get an error Cannot find autoconf

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

downloading intl-3.0.0.tgz …

Starting to download intl-3.0.0.tgz (248,200 bytes)

…………………………………………….done: 248,200 bytes

150 source files, building

running: phpize

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize’ failed

make sure that autoconf is installed and PHP_AUTOCONF is set correctly (which is not set by default when using XAMPP).

You can easily install autoconf through Homebrew too:

bash-3.2$ brew install autoconf

==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.yosemite.bottle.1.tar.gz

######################################################################## 100,0%

==> Pouring autoconf-2.69.yosemite.bottle.1.tar.gz

Warning: This keg was marked linked already, continuing anyway

🍺  /usr/local/Cellar/autoconf/2.69: 70 files, 3,1M

Next, make sure that PHP_AUTOCONF is in your path by checking the path to autoconf:

bash-3.2$ which autoconf

/usr/local/bin/autoconf

 Now set PHP_AUTOCONF:

bash-3.2$ export PHP_AUTOCONF=/usr/local/bin/autoconf

and start the intl installation through PECL again:

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

downloading intl-3.0.0.tgz …

Starting to download intl-3.0.0.tgz (248,200 bytes)

…………………………………………….done: 248,200 bytes

150 source files, building

running: phpize

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

Specify where ICU libraries and headers can be found [DEFAULT] :

building in /private/tmp/pear/temp/pear-build-rootlnRgnx/intl-3.0.0

running: /private/tmp/pear/temp/intl/configure –with-icu-dir=DEFAULT

checking for grep that handles long lines and -e… /usr/bin/grep

checking for egrep… /usr/bin/grep -E

checking for a sed that does not truncate output… /usr/bin/sed

checking for cc… cc

checking whether the C compiler works… yes

checking for C compiler default output file name… a.out

checking for suffix of executables…

checking whether we are cross compiling… no

checking for suffix of object files… o

checking whether we are using the GNU C compiler… yes

checking whether cc accepts -g… yes

checking for cc option to accept ISO C89… none needed

checking how to run the C preprocessor… cc -E

checking for icc… no

checking for suncc… no

checking whether cc understands -c and -o together… yes

checking for system library directory… lib

checking if compiler supports -R… no

checking if compiler supports -Wl,-rpath,… yes

checking build system type… x86_64-apple-darwin14.3.0

checking host system type… x86_64-apple-darwin14.3.0

checking target system type… x86_64-apple-darwin14.3.0

checking for PHP prefix… /Applications/XAMPP/xamppfiles

checking for PHP includes… -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib

checking for PHP extension directory… /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212

checking for PHP installed headers prefix… /Applications/XAMPP/xamppfiles/include/php

checking if debug is enabled… no

checking if zts is enabled… no

… a lot more messages and compile output and finally:

———————————————————————-

Libraries have been installed in:

   /private/tmp/pear/temp/pear-build-rootlnRgnx/intl-3.0.0/modules

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR’

flag during linking and do at least one of the following:

   – add LIBDIR to the `DYLD_LIBRARY_PATH’ environment variable

     during execution

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

———————————————————————-

Build complete.

Don’t forget to run ‘make test’.

running: make INSTALL_ROOT=”/private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0″ install

Installing shared extensions:     /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/

running: find “/private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0” | xargs ls -dils

10839659   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0

10840601   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications

10840602   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP

10840603   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles

10840604   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib

10840605   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php

10840606   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions

10840607   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212

10840608 856 -rwxr-xr-x  1 root  wheel  434572 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/intl.so

Build process completed successfully

Installing ‘/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/intl.so’

install ok: channel://pecl.php.net/intl-3.0.0

configuration option “php_ini” is not set to php.ini location

You should add “extension=intl.so” to php.ini

Activate intl Extension in php.ini

Finally, make sure to add

extension=intl.so

to your php.ini and restart Apache. If everything is set up correctly you will see the intl information using phpinfo():

PHP intl extension phpinfo

 You are all set to go!

Posted on 5 Comments

Enabling Cross-Origin Resource Sharing CORS for PHP

Source Code Icon

This post is an addition to Enabling Cross-Origin Resource Sharing CORS for Apache to show you how to enable Cross-Origin Resource Sharing CORS for PHP. Thus, in case you don’t have access to the .htaccess you can simply enable CORS for PHP using the following steps.

Setting required headers using PHP

As explained in Enabling Cross-Origin Resource Sharing CORS for Apache you need to make sure that responses to cross-domain requests to your server (e.g. through Ajax requests using jQuery) need to include a set of required headers to be accepted by the client browser. These are

  1. Access-Control-Allow-Origin
  2. Access-Control-Allow-Methods
  3. Access-Control-Max-Age
  4. Access-Control-Allow-Headers

Make sure that Access-Control-Allow-Origin is set a domain value actually allowed by your server. In theory you could use ‘*‘ as well, but some browsers (e.g. Firefox) will simply ignore it and CORS will not work.

PHP code to enable CORS

The following snippet should give you a quick overview about the required HTTP headers to set for CORS to work.

First, it defines a list of allowed origin domains based on regular expressions. This list will be checked against $_SERVER[‘HTTP_ORIGIN’], i.e. the Origin header specified in the client request. If one origin entry from the list matches the required CORS headers will be set. This setup also takes care of the CORS pre-flight request.

// array holding allowed Origin domains
$allowedOrigins = array(
  '(http(s)://)?(www\.)?my\-domain\.com'
);

if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') {
  foreach ($allowedOrigins as $allowedOrigin) {
    if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) {
      header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
      header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
      header('Access-Control-Max-Age: 1000');
      header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
      break;
    }
  }
}
Posted on Leave a comment

Resize root Partition on Raspbian to use free space

RaspberryPi Logo

Raspbian comes pre-configured to run on smaller SD cards. Thus, the default partition sizes are generally configured to not exceed 4GB. In case you want to use SD cards larger than 4GB (e.g. 32GB) you will definitely want to use the free unallocated space, right? Luckily, this can be achieved rather easily. The default Raspbian partition schema looks something like the following using a 32GB sd card:

pi@raspberrypi / $ sudo fdisk -c -l /dev/mmcblk0

Disk /dev/mmcblk0: 31.3 GB, 31322013696 bytes
4 heads, 16 sectors/track, 955872 cylinders, total 61175808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00090806

Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     6399999     3138560   83  Linux

Although you could manually resize your partitions using fdisk Raspbian comes with a handy tool called raspi-config that will take care of this process for you:

raspi-config

All you need to do in order to resize your root partition is to select Expand Filesystem in the menu (see screenshot). raspi-config takes care of the rest for you, pretty neat, right? After a reboot all of your free disk space will be used:

pi@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           29G  2.3G   26G   9% /
/dev/root        29G  2.3G   26G   9% /
devtmpfs        215M     0  215M   0% /dev
tmpfs            44M  208K   44M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   56M  9.7M   47M  18% /boot

In case you are still interested in manually resizing your partitions you might want to have a look at e.g. Chris Newland’s post. Enjoy!

Posted on Leave a comment

Fixing ownCloud 6.0.3 upgrade problem on Asustor Data Master (ADM)

Unfortunately, trying to upgrade ownCloud on an Asustor AS-602T to version 6.0.3 running Asustor Data Master (ADM) 2.1.1.R3B2 resulted in a corrupted installation. Even removing and re-installing ownCloud via the App Central didn’t solve this issue.

So, in order to solve this issue and remove your corrupted ownCloud installation from your system first remove it via the App Central and then SSH to your NAS and remove the following folder:

NOTE: The following command will remove your installation and settings!

root@NAS:/volume1/.@plugins/AppCentral # rm -rf owncloud/

This fixed the ownCloud upgrade problem and I was able to install ownCloud 6.0.3.

Posted on Leave a comment

Custom build script for GIT based projects

Git Logo

When managing smaller GIT based projects I find it helpful to opt for custom build scripts rather than having to deal with the overhead of setting up proper Jenkins (or-likewise) runtime environments.

In order to deal with this need I’ve created a simple build script that creates a compressed TAR file based on committed files.

Furthermore, since I use version numbers for e.g. JavaScript builds it’s always nice to have automatic file inclusion/exlusion based on this number, say, read from a config file.

In this particular example I want to read the version number from a variable called MY_VERSION in file config/base.php and include a special JavaScript build-folder in the target compressed TAR file. In addition, I only want to include files in the src-folder, as well as manually include other folders.

So, here it is:

#!/bin/sh
#
# REQUIREMENTS:
# - git
# - php
# - sed
# - xargs
# - tar
#

#(absolute) path to PHP, or simply 'php' if it is in the PATH
PHP_PATH="php"

#release number should be read from config/base.php
PHP_REQUIRE="require('$(pwd)/config/base.php');"
RELEASE_NUMBER=`$PHP_PATH -r "$PHP_REQUIRE echo MY_VERSION;"`

#hold list of files to be added to release tar.gz
TMP_SRC_FILE_LIST=$(pwd)/TMP_RELEASE_INCLUDE

#get list of git's tracked files
git ls-files > $TMP_SRC_FILE_LIST

#filter only SRC directory
sed -i '/^src./!d' $TMP_SRC_FILE_LIST

#manually include additional folders of your choice
sed -i '/^src\/js\/folder1/d' $TMP_SRC_FILE_LIST
sed -i '/^src\/js\/folder2/d' $TMP_SRC_FILE_LIST

#add RELEASE directory only
`echo "src/js/release/$RELEASE_NUMBER" >> $TMP_SRC_FILE_LIST`

# enclose lines in "" to enable spaces in file and folder names
sed -i 's/^/"/g' $TMP_SRC_FILE_LIST
sed -i 's/$/"/g' $TMP_SRC_FILE_LIST

#create compresse TAR
cat $TMP_SRC_FILE_LIST | xargs tar czf release_$RELEASE_NUMBER.tar.gz

#clean up
rm $TMP_SRC_FILE_LIST

That’s it – Feel free to adjust it to your needs.

Posted on Leave a comment

Unable to remove read-only attribute for folder on Windows

Recently I ran into a little problem when trying to remove the read-only flag from a folder to be used as data store for a web application. Trying to remove the read-only attribute via the folder settings did not do the trick, as after unchecking the box, closing the settings window and re-opening it the read-only flag was set again…

After doing some research this is expected behavior, as stated in Microsoft’s KB326549.

The solution? Remove the attribute from the command line:

attrib -r +s c:\your_folder

This commands does nothing more than removing the read-only attribute and setting the system-folder attribute instead. This is the best you can do in this case – at least from what I’ve discovered.

Posted on Leave a comment

Installing OAuth PECL extension for XAMPP beta on Mac

Recently I ran into problems when installing OAuth PECL extension for XAMPP beta on Mac OS-X. Running pecl from the command line gave the following error:

bash-3.2$ /Applications/XAMPP/xamppfiles/bin/pecl

Notice: unserialize(): Error at offset 250 of 1301 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

Luckily, the solution to this problem is pretty simple. First, delete pear.conf by making a backup in your XAMPP setup:

bash-3.2$ mv pear.conf pear.conf.backup

This way PECL will create a new and correct config file when running the command again. Obviously, XAMPP ships with a corrupt pear.conf.

Then, install the OAuth extension as usual:

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install oauth
...
downloading oauth-1.2.3.tgz ...
Starting to download oauth-1.2.3.tgz (45,531 bytes)
.............done: 45,531 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
building in /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3
running: /private/tmp/pear/temp/oauth/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i386-apple-darwin12.4.0
checking host system type... i386-apple-darwin12.4.0
checking target system type... i386-apple-darwin12.4.0
checking for PHP prefix... /Applications/XAMPP/xamppfiles
checking for PHP includes... -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib
checking for PHP extension directory... /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix... /Applications/XAMPP/xamppfiles/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking for oauth support... yes, shared
checking for cURL in default path... found in /usr
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... no
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin12.4.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/libtool --mode=compile cc  -I. -I/private/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/include -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/main -I/private/tmp/pear/temp/oauth -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -Wall -g   -c /private/tmp/pear/temp/oauth/oauth.c -o oauth.lo
mkdir .libs
cc -I. -I/private/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/include -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/main -I/private/tmp/pear/temp/oauth -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -g -c /private/tmp/pear/temp/oauth/oauth.c  -fno-common -DPIC -o .libs/oauth.o
/private/tmp/pear/temp/oauth/oauth.c:507:19: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types]
Z_STRVAL(first) = f->arKey;
^ ~~~~~~~~
/private/tmp/pear/temp/oauth/oauth.c:516:20: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types]
Z_STRVAL(second) = s->arKey;
^ ~~~~~~~~
2 warnings generated.
/bin/sh /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/libtool --mode=compile cc  -I. -I/private/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/include -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/main -I/private/tmp/pear/temp/oauth -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -Wall -g   -c /private/tmp/pear/temp/oauth/provider.c -o provider.lo
cc -I. -I/private/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/include -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/main -I/private/tmp/pear/temp/oauth -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -g -c /private/tmp/pear/temp/oauth/provider.c  -fno-common -DPIC -o .libs/provider.o
/bin/sh /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/libtool --mode=link cc -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/include -I/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/main -I/private/tmp/pear/temp/oauth -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -Wall -g   -o oauth.la -export-dynamic -avoid-version -prefer-pic -module -rpath /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/modules  oauth.lo provider.lo -lcurl
cc ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/oauth.so -bundle  .libs/oauth.o .libs/provider.o  -lcurl
dsymutil .libs/oauth.so || :
creating oauth.la
(cd .libs && rm -f oauth.la && ln -s ../oauth.la oauth.la)
/bin/sh /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/libtool --mode=install cp ./oauth.la /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/modules
cp ./.libs/oauth.so /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/modules/oauth.so
cp ./.libs/oauth.lai /private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/modules/oauth.la
----------------------------------------------------------------------
Libraries have been installed in:
/private/tmp/pear/temp/pear-build-rootjw6ahH/oauth-1.2.3/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
running: make INSTALL_ROOT="/private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3" install
Installing shared extensions:     /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525/
running: find "/private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3" | xargs ls -dils
5144976   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3
5145326   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications
5145327   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP
5145328   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles
5145329   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib
5145330   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib/php
5145331   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib/php/extensions
5145332   0 drwxr-xr-x  3 root  wheel     102 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525
5145333 200 -rwxr-xr-x  1 root  wheel  101592 30 Sep 17:09 /private/tmp/pear/temp/pear-build-rootjw6ahH/install-oauth-1.2.3/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525/oauth.so
Build process completed successfully
Installing '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525/oauth.so'
install ok: channel://pecl.php.net/oauth-1.2.3
Extension oauth enabled in php.ini

That’s it.

Posted on Leave a comment

Using multiple SSH Keypairs for Git

Git Logo

When using multiple (GIT) services and repositories from different provider you are very likely to also use different sets of SSH keypairs. At first managing multiple keypairs might sound a little complicated but it is in fact quite easy.

Let’s say you have three keypairs for three different GIT services:

  • GitHub
  • PHP Cloud
  • your local GIT server

In order to separate access to these services you are using different keypairs for each service. In order to tell GIT to automatically choose the right keypair for the service you are trying to access you need to edit your local SSH config file (.ssh/config), as well as the GIT repository’s config file (.git/config).

First, you need to create an alias for each service in your SSH config file:

Host phpcloud-mycontainer
HostName mycontainer.my.phpcloud.com
User mycontainer
IdentityFile ~/.ssh/id_rsa.phpcloud-mycontainer
Host github-myaccount
HostName git.github.com
User myaccount
IdentityFile ~/.ssh/id_rsa_github-myaccount
Host localgitserver-myaccount
HostName localgitserver.local
User myaccount
IdentityFile ~/.ssh/id_rsa.localgitserver-myaccount

As you can see three aliases have been specified for the three services. This provides you with the option to specify what key to use depending on the service.

In order to “activate” these alias for existing repository clones you need to edit .git/config to set the proper remote origin. So for instance your config for GitHub would look something like the following:

[remote "origin"]
url = ssh://git@github-myaccount:myaccount/myrepo.git
...

Now all you need to do is the use the alias when accessing your services. This way the proper SSH key will be determined.

Also note that this approach is not limited to GIT – you are able to use these simple steps for any service based on SSH.

Posted on 2 Comments

Determine last day of month using Bash script

Oftentimes software systems need to carry out tasks on a regular basis at a given time, such as archiving log files or sending out newsletters. Normally cron is able to handle all kinds of time-based setups (daily, monthly, etc.) but what if you want to execute tasks on the last day of each month?

A simple bash script does the trick:

#!/bin/bash
TODAY=`/bin/date +%d`
TOMORROW=`/bin/date +%d -d "1 day"`
if [ $TOMORROW -lt $TODAY ]; then
exit 0
fi
exit 1

So, as you can see we need to simply check if the next day is “less” than today. All you need to do is to call this script at the required time each day and it will check if it’s the last day of the current month, like so:

59 23 * * * isLastDayOfMonth.sh && yourJob.sh

Thats’s it.

Posted on Leave a comment

Cygwin CMake Error cygmpfr-4.dll missing

Cygwin Logo

In case you run into the following error message when trying to run cmake in cygwin bash be sure the setup libmpfr4 via setup.exe:

/usr/lib/gcc/i686-pc-cygwin/4.5.3/cc1.exe: error while loading shared libraries: cygmpfr-4.dll: cannot open shared object file: No such file or directory

As always, make sure to restart your Cygwin bash afterwards.

Posted on Leave a comment

Updating Tables across multiple Databases

Recently I was asked if it is possible to update tables with data from other databases. Of course it is 🙂

Imagine the case where you want to update your customer table with data from a backup database. Let’s call the current database currentDB and the backup backupDB and the customer table respectively customer. Furthermore, let’s say column address got messed up and you want to restore it from the backup database. The following SQL statement does this job:

UPDATE  `currentDB`.`customer` `cdb`
JOIN `backupDB`.`customer` `bdb`
ON `cdb`.`customer` = `bdb`.`customer`
SET `cdb`.`address` = `bdb`.`address`;

As you can see updating tables across multiple databases straight forward. You only need to join the tables from your databases (based on a private key as usual) and set the values accordingly.

Pretty easy, right?

Posted on Leave a comment

Space instead of Backspace in Cygwin Bash Problem

Cygwin Logo

Recently I’ve experienced a weird behavior in a Cygwin installation on Windows 7. When pressing the backspace key Cygwin falsly interpreted it as a space.

Luckily, the problem is rather easy to fix. The easiest way (which did not work everytime while testing) is to simply reinstall terminfo and termcap via setup.exe, as mentioned here: Backspace does not work in Cygwin. If you don’t have termcap installed install it but make sure to reinstall terminfo properly too. At best this is all you need to do to get your backspace back again.

If not, you might need to remove .bashrc from your home folder, e.g. /cygwin/home/you/.bashrc. Then, just to make sure reinstall terminfo and termcap again. This always worked for me.

Enjoy your backspace 🙂

Posted on Leave a comment

Auto Mount TrueCrypt Drives on Windows Boot

Update: Please do not use TrueCrypt anymore. Development of TrueCrypt was discontinued a while ago due to numerous security flaws detected in the core part. In fact, TrueCrypt is not secure and you should switch as soon as possible. Luckily, there are a couple of viable alternative solutions available. Thanks to Comparitech for the heads-up on this rather old post. They have provided a list of viable free TrueCrypt alternatives for you to choose from. Enjoy!

TrueCrypt represents a viable solution to easily setup encryption for files, folder or even entire drives on Windows 7/Vista/XP, Mac OS X, and Linux.

Sometimes you might want your encrypted drive(s) to be automatically (re-)mounted when Windows starts. Fortunately, this can be easily achieved with a batch file and Window’s built-in Task Planner, as shown below:

@echo OFF
echo Mounting encrypted drive..
"C:\Program Files\TrueCrypt\truecrypt.exe" /v \Device\Harddisk1\Partition1 /l i /c /p "your_password" /q /m rm /w
echo Done!

Please note that in this example the password will be included in plaintext in the batch file, which might pose a security risk. Although there are more secure solutions available (e.g. have a look at the cache option) this example only serves demonstrational purposes.

For a list of all command line options please refer to the Command Line Usage page.