Archive for the 'Howto' Category

MySQL database dump directly via SSH

I had a server with almost no disk space and i needed to move the site to another virtual server. Making a database dump locally was no option so I Googled around and found some handy commandline ways to copy the database to the other server.

Dump MySQL database gzipped via SSH to destination server:

Dump MySQL database gzippped via SSH and import it on destination server:
mysqldump –opt –add-drop-table -Q -u localuser –p localdatabase |gzip -c |ssh remoteuser@remoteserver 'gunzip -c | mysql -u remoteuser –password=remotepassword remotedatabase'

No Comments »

Stop OSX lion from opening all applications after reboot

One VERY annoying feature of OSX lion is the fact it opens ALL applications you ever opened despite the fact you disabled the “Restore windows when quitting and re-opening apps” feature in the system preferences.
After some googling around i found a solution that actually works!
Here is the solution:

– Open a terminal
– Run the following commands:

$ chflags nohidden ~/Library/
$ cd ~/Library
$ chmod a-w Saved\ Application\ State/

– Reboot

I hope this helps anybody with the same annoying problem.

No Comments »

Increase fastCgi / PHP activityTimeout in IIS7

When your have installed PHP with the Microsoft web platform installer PHP is installed in C:\Program Files (x86)\PHP\v5.2.
When your PHP script runs longer than 10 minutes (600 seconds) you will get an 500 Internal server error.
To fix this issue you will need to increase the fastCgi activityTimeout in IIS7.
After Googling around i found a solutions, but because the web platform installer installs PHP in a path with spaces in it all examples failed.
I Googled some more and after a while i combined 2 solutions and got it to work.

Start a command promt and go to this folder:

Execute this command to see the current settings:

C:\Windows\System32\inetsrv>appcmd list config -section:system.webServer/fastCgi

Output will be something like this:

<application fullPath="C:\Program Files (x86)\PHP\v5.2\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="600" requestTimeout="600" instanceMaxRequests="10000">
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\Program Files (x86)\PHP\v5.2" />

To change the timeout to 1 hour (3600 seconds) execute the following command:

C:\Windows\System32\inetsrv>appcmd set config -section:system.webServer/fastCgi "-[fullPath='C:\Program Files (x86)\PHP\v5.2\php-cgi.exe'].activityTimeout:3600"

Not the use of double and single quotes to specify the correct parameters.
After you run this command you will see this output:

Applied configuration changes to section "system.webServer/fastCgi" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

After running the list config command again the output now looks like this:

<application fullPath="C:\Program Files (x86)\PHP\v5.2\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="3600" requestTimeout="600" instanceMaxRequests="10000">
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\Program Files (x86)\PHP\v5.2" />

As you can see the activityTimeout is now increased.
Restart your IIS service and your good to go.


Connect to Windows Samba share on Mac OSX with SSH

After some googling around i found this post. It’s a very clear howto on connecting to a Windows Samba share on your Mac OSX with SSH. For example your NAS at home from any other location.
I copied it to my own site to be sure it stays on the web.

All credits go to the author.

Chances are if you are seeing this, you’ve tried quite a bit but it hasn’t worked. Look no further. If you are seeing this and haven’t been researching it, then this should still be enough info to get a good start.

First, here’s the point: Using windows file sharing (Samba/SMB) is a good way to access your files across your home network, but don’t even think about trying it over the internet. In order to access SMB shares across the internet you’re going to need to get creative. A method which works reasonably well is using a zero-configuration VPN program such as Hamachi, Remobo, Wippen, etc. to create a virtual lan connecion, thus fooling your computer into connecting like you were on the same lan. That works, but in my experience it isn’t very reliable, it has limitations, it has overhead, and it means you have to have that ZCVPN client on both ends. So here’s my solution, skip the program, jump straight to the solution. If you use an SSH tunnel to connect to your computer, you can access your SMB shares, you can use VNC to view your screen, or do just about anything that uses a port on your host computer. The best part about it is, once you have it up and running, it’s really simple to use!

Note: This post will assume that your “server” machine is running windows and your “client” machine is running Mac OS X Leopard.

Here’s how to do it:

1. Enable file sharing on your host computer (I’m going to assume this is running Windows). This will allow your files to be shared across your local network. If you don’t know how to do that, there’s a very good guide Here.

2. (Optional) Disable simple file sharing and edit the permissions on your shares so that the shares are password protected. You only need to do this if you don’t want just anyone on your local network to be able to access your files. (Google it)

3. Install an SSH server on your host computer, I’d recommend freeSSHd. This will allow your to create a secure connection between your computers. I’d suggest freeSSHd because it’s free and much easier to use than many of the alternatives (OpenSSH/Cygwin).

4. On the SSH tab in the freeSSHd settings, change the port to whatever port you want, I’ll be using 12345 in my examples. I’d recommend something in between 10000 and 50000 so that a network scanner is less likely to pick up the port.

5. On the Users tab in freeSSHd, add a user with the username and password of your choice, set your password as “Password stored as SH1 hash”.

6. On the Tunneling tab in freeSSHd, enable local and remote port forwarding.

7. Test your SSH server to make sure you can connect to it using a computer on the same network as the SSH server. You will need the local IP of the SSH server for this step you can find it using This guide.

To test it from your mac machine:

Open the Terminal (Applications/Utilities/Terminal)
Use the command ssh -p port username@hostip (Example: ssh -p 12345 lococobra@

8. Enable port-forwarding on your router to your SSH server at the port you used – Follow one of the guides for your router Here but use the port for SSH (12345)

9. (Optional) Set up an automatic DNS server for your host computer, you can set that up Here for free. I’d really suggest you do this, its very useful! Once you have that set up, install the No-IP Dynamic Update Client so that your DNS always matches your dynamic IP.

10. Test your SSH connection via the port forward. This is almost exactly the same as before, except instead of using the IP you got from ipconfig, use your global IP (or the DNS you set up in step 9). You can find your global IP Here.
Example: ssh -p 12345

Now that we have all that set up, we’re almost done. What we’re going to do is connect via SSH and forward the SMB ports from our host computer to our client. This will allow you to access your shares remotely. It works because your ssh/smb server will think that it’s directly connected with your client computer, when in fact the connection is all handled through SSH. The tricky part is, OS X Leopard will not allow you to do this. If you forward the SMB ports from the server to client computer, then the client will think that it’s connecting to itself, and so Leopard will deny the connect. In order to defeat this we’re going to have to work some magic.

11. Set up an alias for your loopback connection (localhost/ on your Mac. This will fool your computer into thinking it’s connecting to an external IP. This command needs admin privileges, so you have to use sudo. The command is:

sudo ifconfig lo0 alias up

This will create a temporary alias for your loopback connection which will stay active until the computer is restarted.

12. Edit the all users configuration file for your SSH settings so that you can connect quickly without setting it up each time.

Open the Terminal and run sudo pico /etc/ssh_config
Enter the following text above the line that says ” #Host *”, change the user and port to the ones you have used in your SSH configuration.

Host AliasForHost
HostName hostip
Port 12345
User YourUserName
ServerAliveInterval 200
ServerAliveCountMax 3

Keep in mind that you can add any number of ports to this list. For example, if you want to connect to VNC, add 5900 to that list. Then to use VNC, connect to

Hit control + x, Y, and enter to save the file. Since we’re saving it as a dotfile (there’s a dot at the beginning) you won’t be able to see it. If you need to edit it again, you can do it through pico the same way.

13. Initiate the SSH connection with your host computer using the host alias we set up before.

sudo ssh AliasForHost

14. Connect to the Samba share. Open a Finder window and hit command+ k to open a Connect to Server windows. For the server address, use:


Now click Connect, and if everything went well you should be prompted with a window to enter your Login credentials for the server machine!

Wow, that was complicated, but at this point it doesn’t need to be. Here’s a little AppleScript I came up with to automate the connection. (Don’t worry about running the ifconfig over and over, it won’t hurt anything)

set Command to “sudo ifconfig lo0 alias up; sudo ssh AliasForHost”

tell application "Terminal"
if (count of windows) is 0 then
do script Command
do script Command in window 1
end if
end tell

You can save that script as an application using the AppleScript Script Editor and run it to automatically run those commands.

I know for most people that post was probably really confusing but I tried! If you need help please comment or something. I’ll get back to you.

Edit: Take a look at Fredrik’s script in the first comment for an even more automated solution for connecting and mounting.

Edit2: I found a much more efficient way to actually initiate the connection using a host alias, take a look at the part about the ssh_config file

1 Comment »

Generate CSR for apache with mod_ssl

This post is just as a reminder so i can look this up when i need to.. But if it helps you that’s great.

To generate a 2048 bits certificate request do this:

openssl genrsa -out 2048
openssl req -new -key -out

In the vhost add this:

SSLCertificateFile /where/ever/
SSLCertificateKeyFile /where/ever/

When a intermediate CA is needed, download it, and add this line:

SSLCACertificateFile /where/ever/

No Comments »

The best editor on mac osx #textmate create your own commands using PHP

With the bundle editor it’s possible to create your own commands. And the best thing ever is you can use PHP in your commands.

Now i can do virtually anything, advanced text conversions, even with database lookups!

Textmate PHP command

No Comments »

Update Linksys WRT54GR firmware problem

I had a problem with updating the firmware of my Linksys WRT54GR from 1.04 to 1.18.
I got some kind of connection timeout when i pressed the “Start to upgrade” button. I tried all browsers, IE7, IE8, Firefox, Safari, Chrome on Windows and Mac.
Nothing worked..

After some googling around i found out that it only works when you use Internet Explorer 6!! OMFG… what a crappy router… They should hang the developer who wrote the 1.04 firmware..

Well, i installed IEtester, which you can find here, and it worked!!


Use wget in cron with no output

When you use wget in a cron to run a php script at a specific interval the home directory of the user this cron is running as is filled with files containing the output.
You can make cron output everything to stdout to make this stop:

/usr/bin/wget -O - -q

No Comments »

Set network interface to 100 mbit full duplex (eth0) in CentOS

Add this line to /etc/sysconfig/networking/devices/ifcfg-eth0
(or any other nic if you need to)

ETHTOOL_OPTS=”autoneg off speed 100 duplex full”

Make sure your switch also has this configured this way.

No Comments »

VMware 6.5.4 and Ubuntu vmnet compile problems and cursor flaw fix

VMware seems to go the Microsoft way of doing things; They create a flawed installer and no KB to fix this.
Fortunately there are some smart dudes who know their stuff and place it on the www. I was lazy to find out this time myself so this is some sort of “placeholder” for the next time when I run into this, or when VMware has sorted their stuff out with a new version, or fix.

Thanks to digital-scurf blog author; Sorry to copy this but this really makes sense. Short and clear:

I recently updated vmware on my desktop to workstation 6.5.4 having previously upgraded the machine to Ubuntu 10.04. This resulted in interesting issues so I thought I’d collate them all here.

1. vmware’s installer remains flawed wrt. output generated during module compile—to fix this, create a gcc wrapper script which removes the -W flags, e.g.

import sys
import copy
import os
argv = copy.copy(sys.argv)
i = len(argv)
for i in range(i-1, 0, -1):
if len(argv[i]) > 4 and argv[i][:2] == "-W" and argv[i][3] != ",":
del argv[i]
argv[0] = "/usr/bin/gcc"
os.execv(argv[0], argv)

2. Pop that somewhere like /tmp/gcc and chmod +x it.
3. Run sudo env PATH=/tmp:$PATH sh /wherver/VMware-Installer.bundle
4. When the installer finishes, cd into /etc/vmware and add export VMWARE_USE_SHIPPED_GTK=”force” to the bootstrap file. (This fixes the mouse-broken in fullscreen mode, two pointers visible, vmware losing grab blahblahblah problem)
5. cd into /usr/lib/vmware/modules/source
6. untar the vmci and vmnet tarballs
7. in vmci-only/include/pgtbl.h add compat_sched.h to the includes
8. in vmnet-only/vnetUserListener.c add compat_sched.h to the includes
9. tar those up again
10. run sudo vmware-modconfig—console—install-all
11. Assuming all is well, vmware will now work properly.

No Comments »

Next »