Category Archives: Web Development

To install e-mail server on Ubuntu or just to use web mail services?

My goal was to create e-mails like user@mydomain.ru and use these e-mails outside the server, by accessing them using IMAP and SMTP protocols.

Unfortunately, instead of trying to find the most beautiful, fast and feature-rich solution, I decided to setup an e-mail server on Ubuntu on the basis of PostFix (running on a v-server at Hetzner hosting). It is a private server, that doesn’t support e-mail serving by default – you have to setup it yourself. Trying to create something great on Ubuntu for a not red eye Linux geek is like trying to build Boeing 747 by yourself. But I decided to accept this challenge without thinking much and wasted a ton of time as a result. I tried hard for 2 days and all that I had achieved is e-mail forwarding from my server to the Google e-mail.

I tried to use DoveCot and Courier to enable IMAP or POP, but without a success. I couldn’t connect Apple Mail to the resulting e-mail server and make it work. I worked with a lot of configuration files, tried to setup correctly SASL, etc. but at the end I understood, that this is a too hard work to create just an e-mail server. I understood that this must not be a correct way to go. Look for instance at this tutorial. Of course, it is a possiblity, but it works with a very little features and very hard to achieve good functionality. Look at these terrible configs:
ubuntu

I didn’t want to become a Linux geek with red eyes, but I did… The way of creating e-mail server on Ubuntu from scratch appeared to be absolutely unproductive because of tons of problems during configuration and a little number of features at the result. After some time I decided to look at Yandex and Google e-mail services for corporate businesses, when you use their e-mail servers by redirecting from your own domain. And I am glad, I decided to try! At the end, I created the goal e-mail server using Yandex. Yandex service is called a Mail for domain.

All I had to do – is to setup DNS entries, MX entries particularly and put one file to the root folder of the site.

Look, how nicely it works now both on Apple Mail and via Web Interface on Yandex:

yandex

And here is how to setup IMAP and SMTP on Apple Mail or any other E-mail client.

Shell scripts that copy, rename files and resize, crop images

I have written a bunch of shell scripts for my Mac, that do a lot of work automatically.

First script renames all files in a folder sequentially and gives the names with numbers starting from 64:

The second script creates copies of those files and adds “_mini” to the file name. It creates future miniatures of images.

The third script deletes all files in a folder that do not match a pattern with “_mini” word:

And the last script crops images to the given size:

It is also possible to resize images in other ways, for example percentage:

Here are the full instructions for ImageMagick.

Here is an information on copying files.

And here is an information on deleting by pattern.

Finally we get something like this:
Снимок экрана 2014-08-15 в 0.15.56

Final script:

This script rename files with spaces in their file names:

Here you can read more about treating spaces in file names in bash scripts.

Apache config file with multiple VirtualHosts

I wanted to be able to open sites like *.ladby.ru and *.lovecakes.ru besides main sites ladby.ru and lovecakes.ru. This is how I solved this problem – by editing Apache config file, making it much simpler and by using ServerNames instead of ServerAliases.

And this is how the tree looks like:
Снимок экрана 2014-08-13 в 16.57.17

Do not forget to reload Apache after editing conf file, which lies here: /etc/apache2/sites-available:

So, now the following sites are working:
club.ladby.ru
ladby.ru
www.ladby.ru
lovecakes.ru
www.lovecakes.ru
galina.lovecakes.ru

Solving Google App Engine : 500 Server Error

I started to learn Google App Engine. Everything was perfect – tutorials, easiness of testing on development server before I wanted to deploy it on server. I knew that I had to use Java 7 instead of Java 8, which is currently supported by App Engine, but didn’t know, where I should change it easily to make this happen, since I used Maven.

This error happened to me:
Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds.

In errors of my app on App Engine Console I saw this:
Uncaught exception from servlet java.lang.UnsupportedClassVersionError: org/apache/jsp/guestbook_jsp : Unsupported major.minor version 52.0 at com.go

You can see logs this way:
blogpost

You can check your java version:

This is solution:

Then go to profile:

And change your JAVA_HOME variable:

Update that variable:

And now rebuild your AppEngine project and redeploy it on server:

Now check your application on browser: https://your_app_id.appspot.com/

How to add www?

Let’s say, you have a website, that is opened by URL: http://ladby.ru. And you want to be able to open it by http://www.ladby.ru also. What should you do? I will describe it now.

In this case www is a subdomain for your website. It is useful usually if you want to have also ftp.ladby.ru for instance. Also it can be useful to redirect from www.ladby.ru so that some users that type your website URL with www will not have any problems accessing it. Here is more information on what is the purpose of the www subdomain.

To achieve this, you should create a CNAME record in your DNS Zone file. Basicly, CNAME record tells where one should be redirected.

I have a record:

Here @ sign means basic address: ladby.ru in this case. So when somebody wants to open ladby.ru, he is redirected to the 78.47.91.3 IP address. A-record returns a 32-bit IPv4 address, most commonly used to map hostnames to an IP address of the host.

Also I have added an important record, which is the core of the trick:

So, when somebody wants to open www subdomain, he is redirected to basic address or ladby.ru.

In my case the final result looks like this:

Also, you should edit your Apache configuration file this way:

It should not be like this:

Hosting multiple web sites on a single Hetzner VPS using Apache virtual hosts

This article is for those, who want to get some understanding of a Web, VPS, Apache. And for those, who want to solve a problem of registering domain names outside Hetzner and hosting multiple web sites on a single Hetzner VPS using Apache virtual hosts, that I solved in some days with a help of lots of experienced people.

Hetzner is a popular German hosting company. They provide, for instance, virtual private servers (VPS). Some hosting companies provide an easy and straightforward way to register any domain names and host them instantly. But Hetzner has some problems with this, since they register only .com, .org and similar domains and do not register .ru, for instance. Also they force you to buy a NameServer Robot for about 30 Euros, that will allow you to edit DNS entries. It is a little bit strange, however, I had to work with this hosting. So, here I will tell you, how I did solve my problems with hosting two different web sites with separate domain names in a Ru zone on a single VPS.

I will describe here, what I did to register a .ru domain name and point it to a folder on the VPS. VPS was already serving for another web site and I had to create another site, which would be working on the same VPS but have a domain name like “http://ladby.ru“.

It is important to understand the architecture of the Web. Domain name is a string like google.com, that corresponds to a single IP address. DNS are servers, that contain these entries of correspondence. They exchange between each other this info. When you register your domain name, you provide registrator with the information, on which DNS you will provide entries for your IP address. When browser tries to open google.com, it goes to a DNS and determines IP address, where it should ask for the site. On this IP address there is a web server like Apache or NGinx, that handles further process.

dns-rev-1

First of all, I registered on a web site http://2domains.ru to register my domain name “http://ladby.ru”, since Hetzner allows you, as I told, to register only .com domains and similar. Then, I registered there this domain name for 1 year and paid about 3$ for this. I had to fill a lot of information about myself including passport data, since Russian government wants to know everything about .ru domain name owners. Nevertheless, I had this domain name available for me in about 10 minutes. What this did allow to me is the possibility to edit DNS for this domain name. What does a DNS (domain name system)? It contains data about correspondence between domain names and IP addresses.

So, the next step was to determine DNS names and their IP addresses on a Hetzner DNS Robot. I just created a new DNS entry using Robot admin panel and got a list of 3 DNS. Then, I determined their IP address using web tools found in Google and filled data on 2domains.ru about these DNS. This is my filled form, but be aware that you will have absolutely different DNS at Hetzner – you should not copy this, you should take your own addresses from your Robot admin panel.

Снимок экрана 2014-06-24 в 16.38.52

The last thing I had to do is to setup Apache virtual hosts to make a single VPS host two web sites. For this purpose, I created a new .conf file in Apache2 folder and a link to it.

Virtual-Host-Multiple-Websites-Ubuntu-13.10-and-Rackspace-Cloud-Server

I did access to the VPS using SSH:

To create conf files in a proper folder I used this snippet:

Apache works this way: it looks at all *.conf files in this folder and uses them to point corresponding web addresses to corresponding folders, where your index.php or index.html is located.

To edit conf file I used Vim:

To reload Apache after editing conf files I used this snippet:

This is my conf file, it can be used as a template:

Notice that UseCanonicalName should be Off.

To create a link to a conf file I used this snippet:

Notice, that a web site is located in a folder /var/www/ladby.ru/public, it is opened also using a proper domain name that I want: http://ladby.ru.

It is important to notice, that a configuration file for Apache should have .conf extension. Also, you have to point ServerName in each config file in this folder, because if you don’t do it, your server will not see your second web site. VirtualDocumentRoot must be correct also.

So, finally what is the result?
1. http://ladby.ru and

This is the second site, that was hosted on the same VPS:
2. http://lovecakes.ru