Archive for the 'Ubuntu' Category

Accessing Apache Virtual Host from VirtualBox

Jun 10 2011 Published by under Apache,VirtualBox

On my Ubuntu I run Apache vhost for each of my projects.

Now, wouldn’t it be cool if you could access your Apache vhost from IE running in VirtualBox!?

I managed to solve this problem by editing a Vbox instance settings:

Settings: Network: Adapter 1: Attached to: Bridged Adapter

Start a VirtualBox instance and type http://localhost in IE and you’ll see a localhost running on Ubuntu.

Now, associate IP address to a host name in Windows (192.168.1.38 is my Ubuntu IP address)

# c:/Windows/System32/drivers/etc/hosts
192.168.1.38	projectx.local

and Ubuntu

# /etc/hosts
192.168.1.38	projectx.local

Then create a new Apache config file

#/etc/apache2/sites-available/vbox-projectx
<VirtualHost projectx.local>
DocumentRoot /var/www/projectx
</VirtualHost>

Enable the config

$ sudo a2ensite vbox-projectx
$ sudo /etc/init.d/apache2 restart

Now, in IE (running in VirtualBox) type http://projectx.local and… that’s it

Comments Off

Relational Database Tables Indexed With SOLR

May 25 2011 Published by under MySQL,Ubuntu

Let’s say you have a gallery and it consists of three database tables (photos, category and gallery). Each of these tables has lots of related data, obviously…

By following the old database routine, I started indexing data from top to bottom (from gallery to photos table).

But this resulted in a weird behavior where SOLR would index gallery id and name, and only the first category; It simply ignored all other gallery categories and photos.

After spending days mind boggling what could go wrong, it suddenly occurred to me that the proper way to index data into SOLR would be to index is “opposite direction”, from bottom to top that is (from photos to gallery).

It was a great relief to finally see all relational data properly indexed :)

The example that bothered me was:

MySQL schema

photos
- id
- categoryId
- views
- url
- title

category
- id
- name
- galleryId

gallery
- id
- name

SOLR db-data-config.xml

<dataConfig>
	<dataSource
	    type="JdbcDataSource"
	    driver="com.mysql.jdbc.Driver"
	    url="jdbc:mysql://localhost/database"
	    user="username"
	    password="password"/>

	<document name="gallery">

		<entity rootEntity="true" name="photos" query="select *, rand() as uuid from photos">
		<field name="photo_id" column="id" />
		<field name="photo_categoryId" column="categoryId" />
		<field name="photo_views" column="views" />
		<field name="photo_url" column="url" />
		<field name="photo_title" column="title" />

			<entity name="category" query="select * from category where id='${photos.categoryId}'">
			<field name="category_id" column="id" />
			<field name="category_name" column="name" />
			<field name="category_galleryId" column="galleryId" />

				<entity name="gallery" query="select * from gallery where id='${category.galleryId}'">
				<field name="gallery_id" column="id" />
				<field name="gallery_name" column="name" />
				</entity>

			</entity>

		</entity>

	</document>

</dataConfig>

Comments Off

Swap File

May 21 2011 Published by under Shell,Ubuntu

To create swap space in a file:

First, create a file. I have 4GB of RAM, hence I create 4GB large file

$ sudo dd if=/dev/zero of=/media/4GB.swap bs=1G count=4

Set proper file attributes

$ sudo chmod 600 /media/4GB.swap

Set created file as a swap space

$ sudo mkswap /media/4GB.swap

Start swapping

$ sudo swapon /media/4GB.swap

Edit the fstab file

$ sudo vim  /etc/fstab

and set the swap file to mount automatically on next reboot

/media/4GB.swap	swap		swap		defaults	0	0

Comments Off

Reporting bugs in Ubuntu

May 13 2011 Published by under Ubuntu

One of the best ways to report a bug in Ubuntu is to report it right at Launchpad.

First, you need to identify a process that is causing a problem.

Open “System Monitor”, click on “Processes” tab and find a process ID that is bugging you.

Then open “Terminal” and run following command

$ ubuntu-bug $ID

The system will collect system and process data and upload it to Launchpad site.

All you need to provide is your description of a problem.

After that, just sit and wait (and provide aditional details about the bug to the developers)

Comments Off

Zend Studio old menu style in Unity

May 10 2011 Published by under Ubuntu,Unity

Java apps have a small issue with global menu in Unity.

To revert Zend Studio to old-style menus:

Create a “ZendStudio.sh” file in ZendStudio directory

#!/bin/bash
UBUNTU_MENUPROXY=0
/path/to/ZendStudio

Make the file executable

chmod +x ZendStudio.sh

Now create a lanucher icon “zend-studio.desktop”

vim ~/.local/share/applications/zend-studio.desktop

Add the following content to it

[Desktop Entry]
Name=Zend Studio
Exec=/path/to/ZendStudio/ZendStudio.sh
Icon=/path/to/ZendStudio/icon.xpm
Terminal=false
Type=Application
StartupNotify=true

Make the file executable

chmod +x ~/.local/share/applications/zend-studio.desktop

Then, navigate to that location via Nautilus (press CTRL+H to |un|hide files), run the “Zend Studio” icon and pin it to the launcher.

Comments Off

SSH SOCKS proxy server

Jan 04 2011 Published by under Security,Shell

If you crave for privacy and wish to protect your communications (like chat and email) from prying eyes, this is how dynamic port forwarding can turn SSH into a SOCKS proxy server.

The idea is to forward all traffic from @unsecure to @secure location via SSH and then use Internet from @secure location.

To set up a proxy run

ssh -C -D 1080 user@SecureLocation.com

-C enables compression
-D 1080 runs dynamic port forwarding on port 1080

After you connect to secure location, edit browser, email or chat SOCKS proxy settings, pointing them to ‘localhost:1080‘ and use your apps without worrying of being snooped.

Comments Off

Reset Gnome Settings

Dec 10 2010 Published by under Gnome

If you’ve “tweaked” Gnome beyond repair, by deleting its settings folders, Gnome can be restored to default looks.

First stop the GDM service

$ sudo service gdm stop

After that login to shell with your username/password and delete following folders in home directory

rm -rf .gnome2 .gconf .gconfd

When done, start the GDM service and login as usual.

$ sudo service gdm start

Gnome should look just like after the fresh install.

Comments Off

Dynamic apache vhosts

Jun 28 2010 Published by under Apache,Ubuntu

As a developer you most likely run dozens of projects in your webroot directory.

Setting up a new apache host and meddling through the apache conf files for every single project is just a waste of time. Not mentioning that conf file(s) can go huge over time. So, for the past six months or so I’ve been using a dynamic vhost configuration.

The concept is very simple. Let’s assume that you want to access each project via some dynamic domain like “$project.local”. “$project” would be a dynamic project name, and “.local” would actually be a localhost server.

First thing first, make sure that vhost module is enabled:

$ sudo cp /etc/apache2/mods-available/mod_vhost_alias.load /etc/apache2/mods-enabled/mod_vhost_alias.load

Now edit the default apache conf file:

$ sudo nano /etc/apache2/sites-enabled/000-default

Add following configuration to it:

<VirtualHost *:80>
ServerName local
ServerAlias *.local
VirtualDocumentRoot /var/www/%1/public_html
UseCanonicalName Off
</VirtualHost>

Retart the apache service

$ sudo service apache2 restart

Now the only “hard” part about this dynamic apache vhost configuration is that you have to set a new line ih hosts file for each project, which will point to local ip address. I’ve heard that this can also be dynamically ser over the bind DNS server, but I’ll explore that some other time

$ sudo nano /etc/hosts
127.0.0.1   local
127.0.0.1   foo.local

Comments Off

Rsync using SSH RSA auth key

Sep 23 2009 Published by under Security

rsynclogo

How to rsync files between two servers when remote server uses an RSA key for authentication.

Format:
rsync $options $host:$from $to

rsync -avz -e "ssh -i key.rsa" \
user@domain.com:/var/www /var/www/backup

The ‘-avz’ options are used for creating archive, being verbose and compressing the file transfer.

‘-e “$command”‘ specifies the shell command to use; in this case calling the SSH RSA key used for authentication

Comments Off

Resize and position Gnome Terminator

Sep 12 2009 Published by under Gnome

gnome-terminator

I am a huge fan of Gnome Terminator. Terminator is great because it allows multiple terminal instances to be run in a single window.

Since I usually run two or three separate terminal windows, I ofter find myself resizing the main window – so other istances can fit nicely. This can get very boring and time consuming when you need to do something on the fly.

After snooping around the help files, I found this nice little parameter which resizes and positions the Terminator window on my screen.

/usr/bin/terminator --geometry=1024x500+128+200

This command line can be added to Gnome-do or Gnome panel shortcuts, and it works great.

The first two parameters (1024×500) set the width and height, and the other two(128+200) set the padding from left and top of the screen.

Comments Off

Next »

Performance Optimization WordPress Plugins by W3 EDGE