Home Blog
Feb 12
2010

Adding a startup script on Ubuntu server

Posted by: Marko Tomic

Tagged in: ubuntu , Shell , linux , command

This is a useful tip for my reference.  I've been creating some startup scripts on my Ubuntu server lately and her are a couple of steps required to get this working.

Write your startup script and place it in /etc/init.d/ directory. Let's say you called your startup script - myScript.  You then install your script by using update-rc.d debian utility:

update-rc.d myScript defaults

Have a look at man update-rc.d for more info.

And finally, you have to make your file executable:

chmod +x myScript

Feb 06
2010

HOWTO convert and shrink your DVD into a web-playable format

Posted by: Marko Tomic

Tagged in: HOWTO , HandBrake , DVD , command

HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded video transcoder, available for MacOS X, Linux and Windows.

It is my tool of choice when it comes to backing up my DVDs. It allows me to shrink DVDs to a relatively small size and convert them to a web-playable format, such as mp4.

I use the Command Line version of HandBrake simply because it is more efficient and I love typing geeky commands in my terminal window.  So here it is, the simplest command to convert your DVD into an .mp4 file is this:

HandBrakeCLI -i VIDEO_TS -o myVideo.mp4 -e x264 -b2000 -B 192

That will encode a source video located at the path VIDEO_TS to an output file called myVideo.mp4. It will use x264 with a bitrate of 2000 to encode the video, and encode the audio as 128kb/s AAC.

Jan 08
2010

yellowtrace blog

Posted by: Marko Tomic

Tagged in: General

I would like to welcome my dear sister to the blogosphere - the yellowtrace blog.  She has been blogging for about a month and I'm amazed with the number of ideas and thoughts she has shared in such a short period of time.  I find her blog posts very inspiring even though we have completely different careers and characters.

She's a very talented Interior Designer and I'm just a code buster.
She's cool and I'm not.
She's extremely creative and I'm not.
Her blog posts are exciting and mine are not.
These are just some of the differences between us, but the key difference is: I can build a good Website and she can't :-)

Best of success sis!

Dec 18
2009

Flex and Red5 simple demo

Posted by: Marko Tomic

Tagged in: Red5 , Flex , AS3

I've been using Red5 Flash Streaming Server for a while and the more I use it, the better I like it.  Sure, Adobe Flash Media Server is an excellent commercial product which does the same thing and supports server-side ActionScript.  Red5 doesn't support server-side ActionScript at the moment (this will probably change), but it is an open source Flash server and with a little bit of Java knowledge you can achieve the same result and possibly more.

The following example shows how to display the total number of subscribers that are currently connected to this simple Flex application.  If you open this blog page in multiple browser windows, the number should increase. The reverse will happen when you close browser windows.  This will obviously also depend on the number of other clients connected to the app, but because this is such a "high traffic" blog you probably won't have to worry about that :)  Many thanks go to Learnosity for providing me with Red5 hosting, which makes this demo work.

Dim lights

If you are interested, take a look at Red5 server documentation.

Nov 20
2009

Recursively remove .svn directories from your project

Posted by: Marko Tomic

Tagged in: SVN , Shell

Occasionally I find .svn directories in my old projects that are not in Subversion.  The quickest way to recursively remove them is to run the following command:

find . -name .svn -print0 | xargs -0 rm -rf

You need to cd into your project directory before running it.

You can also run the command to quickly disconnect your project from Subversion.

Nov 18
2009

Installing Tigase Jabber Server using console installer

Posted by: Marko Tomic

Tagged in: xmpp , Tigase , Jabber

Couple of months ago I installed Tigase server on my laptop and it was working beautifully until this morning.  I've installed quite a few major OS updates on my laptop since then and I must've done something to upset Tigase.  I visited Tigase Website to download a fresh copy of the server and see what the command is to install it using console.  The Website seems to be in the middle of some sort of upgrade and many links appear to be broken.  Thanks to Google cached search results I managed to find what I wanted.

Here's the magic command to install Tigase using consile installer:

java -jar nameOfTheDownloadedJarFile.jar -console

and follow the prompts. It's pretty simple, but my brain refuses to memorise it.

By the way, I was getting the following error when I started the server:

etc/tigase.xml: line 1: syntax error near unexpected token `newline'
etc/tigase.xml: line 1: `<?xml version='1.0' encoding='UTF-8'?>'
JAVA_HOME is not set.

tigase.xml is identical to the one on our staging server which works perfectly. And my JAVA_HOME is definitely set in tigase.conf. I've also noticed that Tigase likes to insert some whitespace in tigase.xml file upon every startup on a Mac. I've got the feeling that this is what's causing the server to eventually barf. I could be wrong though.

UPDATE: Tigase Website, is back online and installation instructions can be found here.
You can download Tigase server from Tigase Website.

Marko

Nov 12
2009

Generate Self-Signed SSL Certificate - HOWTO

Posted by: Marko Tomic

Tagged in: SSL , HOWTO

This is another one for my reference. I've had to generate a self-signed SSL certificate quite a few times and I'm sure I'll do it again in future. First of all, self-signed SSL certificates provide the same level of security as any other commercial ones, such as Verisign certs. The 2 main differences are:

1. Self-signed certificates are free
2. Self-signed certificates are not recognised by web browsers by default. They need to be installed in browsers manually in order to be accepted by them. This is a 10 second job.

So, if I am setting up a staging web server or a subversion server on a secure domain, a self-signed SSL would be an obvious choice for me. There are a few ways you can generate your SSL certificates, but this is how I like to do it because it works for me on Mac and Linux.

Step 1: cd into my working directory

cd ~/Desktop/KeyGen

Step 2: Generate my key - a Triple-DES encrypted, 1024 bit RSA key

openssl genrsa -des3 -out server.key 1024


You'll be asked to enter in a passphrase.

Step 3: Create a CSR (Certificate Signing Request)

openssl req -new -key server.key -out server.csr

You'll be asked to enter in some basic information about your organisation such as, country, name, state, email etc... Here's a sample output:

Country Name (2 letter code) [AU]: (enter your country code here)
State or Province Name (full name) [Some-State]: (Enter your state here)
Locality Name (eg, city) []: (enter your city here) Organization Name (eg, company) [Internet Widgits Pty Ltd]: (enter something here) Organizational Unit Name (eg, section) []: (enter something here)
Common Name (eg, YOUR name) []: (this is the important one)
Email Address []: (your e-mail address)

Step 4: Remove passphrase from my key. Note: I want to remove it because Apache web server will ask me to enter it in every time I restart the server. If you want to keep the passphrase, skip this step.

cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

Step 5: Create a self-signed certificate using the key I just created. Note: "days -365" will make the certificate valid for 1 year. You can easily make it valid for 10 years if you like. I'm sure you can figure out how to do that!

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

That's it. Now all you need to do is make it work with Apache by enabling mod_ssl and adding the following in your virtual host:

SSLEngine On
SSLCertificateFile 'full_path'/server.crt
SSLCertificateKeyFile 'full_path'/server.key

Nov 04
2009

SSH Tunneling - Add secondary address to your loopback interface HOWTO

Posted by: Marko Tomic

Tagged in: SSH , Shell , OS X

I'm writing this one for my own reference because almost everything I do for work, is done through SSH port forwarding. If you're not familiar with SSH port forwarding, you'll have to read up on it elsewhere. And the reason why we use SSH port forwarding is because it is secure and powerful.

I generally set up my port forwards to run on my local computer on an arbitrary port and configure SSH to create a proxy connection to the normal port on a remote computer. Then I configure my application to connect to my local computer on the chosen arbitrary port.

For example, I would create my virtual hosts in /etc/hosts:

sudo nano /etc/hosts

127.0.0.1 local1A.fwd
127.0.0.1 local1B.fwd
127.0.0.1 local1C.fwd

let's say I want to forward my local requests on ports 6800, 6801, 6802 to remote servers on ports 3012, 3013, 3014. Start by modifying your ssh config:

nano .ssh/config

add the following:

host remote1A
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 111.111.111.111:3012

host remote1B
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 111.111.111.111:3013

host remote1C
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 111.111.111.111:3014

You should now be able to ssh to remote machines:

ssh remote1A

and similarly for 1B and 1C.

Now, lets say you want to create another 3 local hosts and simultaneously port forward to another 3 remote machines via exact same port numbers. This is where you'll run into problems, because you can only use one local port at a time on 127.0.0.1. The workaround it is to create secondary addresses to your loopback interface 127.0.0.2, 127.0.0.3 and so on. The command to add the secondary IP address is:

ifconfig lo0 alias 127.0.0.2/32

Now you can add new set of hosts:

127.0.0.2 local2A.fwd
127.0.0.2 local2B.fwd
127.0.0.2 local2C.fwd

And use the same set of port numbers to tunnel through another set of remote servers:

host remote2A
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 222.222.222.222:3012

host remote2B
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 222.222.222.222:3013

host remote2C
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 222.222.222.222:3014

Marko

Nov 02
2009

MAMP vs Entropy PHP on OS X

Posted by: Marko Tomic

Tagged in: PHP , OS X , MySQL , Apache

Following my post on Snow Leopard Gotchas, I discovered another problem you might run into. SL comes with currently the latest version of PHP 5.3.0. However, not all PHP projects will play nice on v5.3.0. What you could do is:

1. build and configure an older version of PHP from source - e.g. 5.2.11
2. Install Entropy PHP (note: this will modify your SL Apache config files).
3. Or just be lazy and install MAMP (Macintosh, Apache, MySQL, PHP) in a few seconds.

I chose the last option for 5 reasons:
1. I'm lazy
2. Comes with PHP 4.4.9 & 5.2.10
3. It installs a complete package in one directory
4. It doesn't mess with my existing apache config files
5. it's easy to uninstall.

This is particularly useful for content editors who have phobia of terminal windows (I don't blame them). Hopefully some developers will find this useful too.

After you've downloaded and installed MAMP, you'll notice that the installer created /Applications/MAMP directory. Launch your MAMP Control Center, start your services and away you go.

By default, your Apache web server will run on port 8888. You can change this to port 80 in Preferences, but if you do that you will have to make sure that your OS X Web Sharing is stopped. You can stop it in System Preferences=>Sharing=>Web Sharing.

Normally your Apache virtual would be here:

/etc/apache2/users/*.conf or /etc/apache2/extra/httpd-vhosts.conf

MAMP keeps virtual hosts separately in:

/Applications/MAMP/Library/vhosts

If you ever want to uninstall MAMP, all you need to do is Trash /Applications/MAMP directory and you're done. It's simple and clean.

For more info see MAMP documentation.

Problems you may have with Entropy PHP

NOTE: always backup any .conf file you are going to modify or remove.

Entropy PHP will add a new config file in /etc/apache2/other and possibly modify your httpd.conf. If you're having problems running PHP, there could be various symptoms. The one I was seeing in apache error logs was this one:

child pid 7563 exit signal Segmentation fault (11)

I'm not sure what this means exactly, but it happens when your Entropy config file:

/etc/apache2/other/+entropy-php.conf

tries to load the problematic php module:

LoadModule php5_module /usr/local/php5/libphp5.so

To solve this, I would recommend removing all Entropy stuff and go back to your native PHP 5.3.0. You could try removing, or backing up +entropy-php.conf and uncomment the following line in your httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

Also check that this file exists:

/etc/apache2/other/php5.conf

and that it contains

<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.html index.php
</IfModule>

 

Oct 25
2009

Snow Leopard Gotchas

Posted by: Marko Tomic

Tagged in: OS X , MySQL , Apache

I recently upgraded to Snow Leopard from 10.5 and everything went relatively smoothly. I was particularly pleased to see extra 13GB of hard drive space.

However, I noticed a couple of things that I wasn't so pleased about:

  1. Apache unable to start
  2. PHP disabled
  3. MySQL unable to start

I've already walked a couple of people through this, so if you run into the same problem you can try the following:

1. For some reason Snow Leopard modified the following file:

/etc/apache2/extra/httpd-ssl.conf

I was using a self-signed SSL certificate for one of my local sites, which was stored in my custom "SSL" directory. The path to my SSL cert was specified in httpd-ssl.conf, but after upgrading to Snow Leopard, that path was replaced with the default path:

SSLCertificateFile "/private/etc/apache2/server.crt"
SSLCertificateKeyFile "/private/etc/apache2/server.key"

The default .crt and .key files didn't exist on my system, hence Apache failed to start. The error I got was:

Syntax error on line 99 of /private/etc/apache2/extra/httpd-ssl.conf SSLCertificateFile: file '/private/etc/apache2/server.crt' does not exist or is empty

You actually have to type 'httpd' in your terminal window to see those errors.

2. PHP disabled.  This problem is closely related to the previous one and it is very simple to fix.  In your httpd.conf file uncomment the following line:

LoadModule php5_module libexec/apache2/libphp5.so


For some reason Snow Leopard upgrade commented this line out for me.

3. MySQL unable to start.  This one scared me a little bit as I do all of my development work on my local machine running against a local MySQL database.   I typically start my MySQL server in terminal:

sudo mysqld -u root


To my surprise, I go this:

mysqld: command not found


The problem was that the following symbolic link was deleted: {/xtypo_code}/usr/local/mysql{/xtypo_code}
mysql symbolic link points to your current version of MySQL install, typically in the same directory. In my case, that directory is here:

/usr/local/mysql-5.0.45-osx10.4-i686/


All you need to do is recreate the symbolic link and you should be able to start your MySQL server again. You can create the symbolic link in your terminal window by typing the following:

sudo ln -s /usr/local/mysql-5.0.45-osx10.4-i686/ mysql

Note: You need to cd into /usr/local/ before running the command above.


« StartPrev12NextEnd »

Stalk Me

Facebook: marko.tomic Twitter: mtomic Twitter: SydneyScuba YouTube: migonyourtail Linked In: tomicmarko MySpace: markomedia Google Wave: marko2009 blip.fm: markotomic

Site Login

Tag Cloud

Browser Poll

What browser do you use?