How i sync my code automatically to a remote server

I do not want to have my Docker setup on my Mac for several reasons. Docker on Mac sucks because of volumes. I could use Docker-Machine but i don’t like the idea of having a virtual machine running just for that.

That is why i have my docker setup running on a powerful server in the cloud.

As soon as the code changes it want all the changes to be automaticaly synced to my server.

But how the get code changes there ?

Because MacOs is awesome you can achieve this with included tools such as rsync and lauchd.

Here are my settings, please adapt it to your needs.

First of i have created a simple bash file which takes care of calling the actual rsync command. This fits my needs as a PHP/Symfony Developer but you can easily adapt it to your needs.

Please checkout my gist on github to get the code.

Put the file to ~/

You can call it like below but first you have to replace some placeholder with your variables

– my_user=your username on the remote server
– my_remote_host=the hostname of your destination server
– my_source_folder=this is the local folder where your code resides
– my_remote_folder=this is he remote folder where the code gets synced to
– my_project_folder_to_monitor=this is the local folder where your code resides (should be the same as my_source_folder)

/bin/sh -c "~/ -h my_remote_host -u my_user -s my_source_folder -d my_remote_folder"

Okay, that is already pretty good. But i wanted to run this script as soon as code changes in my project. To do this i created a job for the laund on my mac.

Please checkout my gist on github to get the code and create a file called my_sync_job.plist in ~/Library/LaunchAgents Of course you will need to adapt the placeholder as described before.

Now we can Load the Job by doing this.

launchctl load '~/Library/LaunchAgents/my_sync_job.plist'

Now if you did all correct you can try to make a change in any file in your project folder and i will get synced to the remote server.

You can unload it by doing this

launchctl unload '~/Library/LaunchAgents/my_sync_job.plist'

You could to some more fancy stuff with these tools so be creative 😉

How to change the owner on a shared hgfs folder

Let’s assume you want to change the owner of your shared folder to the user www-data and the group www-data

  • we use VMWare Fusion
  • VMWare Tools must be installed and updated
  • tested on Ubuntu Server 14.10 LTS and 15.04

1. create file /bin/remount_hgfs

1.1 become root on your system

sudo su

1.1 create the file with touch

touch /bin/remount_hgfs

1.2 make it executable

chmod a+x /bin/remount_hgfs

1.3 add the following 3 lines to the file

!/bin/sh -e
umount /mnt/hgfs
mount /mnt/hgfs

echo '#!/bin/sh -e' >> /bin/remount_hgfs
echo 'umount /mnt/hgfs' >> /bin/remount_hgfs
echo 'mount /mnt/hgfs' >> /bin/remount_hgfs

2. update your fstab file

i assume the uid and the gid of the user www-data on your system is 33, which is default on most Debian based Systems. You can verify that by doing:

id www-data

If you want to mount as a different user you can find out the same way. If the id is different please modifiy the value of the next command.

2.1 add the following line to your fstab file

.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0

echo '.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0' >> /etc/fstab

3. make sure the remount_hgfs gets executed when the system starts

3.1 add the following line to /etc/rc.local, before the exit

sh /bin/remount_hgfs

line=`wc -l /etc/rc.local | cut -f1 -d' '`; sed -i "${line}ish /bin/remount_hgfs" /etc/rc.local

4. reboot you VM


Now if you do „ls -l /mnt/hgfs“ you should see that the folder belongs to www-data:www-data

For those who trust me, you can do all commands at once 😉

sudo su
touch /bin/remount_hgfs
chmod a+x /bin/remount_hgfs
echo '#!/bin/sh -e' >> /bin/remount_hgfs
echo 'umount /mnt/hgfs' >> /bin/remount_hgfs
echo 'mount /mnt/hgfs' >> /bin/remount_hgfs
echo '.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0' >> /etc/fstab
line=`wc -l /etc/rc.local | cut -f1 -d' '`; sed -i "${line}ish /bin/remount_hgfs" /etc/rc.local

That’s it 😉

Howto install Webistrano on Ubuntu 14.04.1 LTS

First of all, i know Webistrano is an old project. The last commit on this project has been made 3 years ago. But it works fine for my needs.

This is a step by step howto on how to install Webistrano on a fresh clean install of ubuntu 14.04.01 LTS. Therefore i assume you have nothing but a clean install.

Howto install Webistrano on Ubuntu 14.04.1 LTS weiterlesen

make „sudo“ sessions last longer on your Mac

If you want to make your „sudo“ sessions last longer there is a pretty easy way to achieve this.

1. Open sudoers file

sudo vim /etc/sudoers

2. Find this line

Defaults     env_reset

3. Change it to the following, where timeout is the amount of minutes your „sudo“ session should last. In my case it is set to 300 minutes.

Defaults     env_reset,timestamp_timeout=300

4. Save your sudoers file

That’s it


Zf2 Doctrine2 working skeleton application

I wanted to try out Doctrine 2 in Zf2 so i started googling. I have found a lot of examples, skeletons and suggestions but none of them worked 100% for me so i decided to create my own skeleton based on what i have learned so far.

Check out my new ZF2 Doctrine skeleton Application on Github.

Howto see which Modules are enabled in Apache2

If you want to see which Modules are enabled in your Apache2 config the following command will probably help you.

apache2ctl -M

In my current config this gets me the following result.

Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK

Howto enable or disable a Module in Apache2

The following commands will show you how easy it is to enable or disable a module in Apache2. For this example we play with the well known mod_rewrite Module.

Enable a Module

a2enmod rewrite

After having enabled the Module you must reload Apache with the following Command, a complete restart ist not needed.

/etc/init.d/apache2 reload

Disable a Module

a2dismod rewrite

After having enabled the Module you must reload Apache with the following Command, a complete restart ist not needed.