Sunday, November 3, 2013

Apache errors after upgrade from 2.2 to 2.4, or upgrading ubuntu 13.04 to ubuntu 13.10

Today I upgraded my laptop ubuntu from raring ringtail to saucy salamander. After setting the desktop to the salamander wallpaper, I moved to my http://localhost, but alas! the apache configuration was not working. I was getting the default "It works" page from /var/www/index.html . During the upload process, I was asked whether I want to update the configurations in /etc/apache2/envvars and /etc/php5/apache2/php.ini. I had selected to upgrade both of them while noting down the previous customizations that will be lost. So, I set out to correct this new after upgrade error :

1. Bring back the customization removed during the upgrade process. I usually run the apache2 process by the normal user instead of www-data. Edited the /etc/apache2/envvars file to bring back old users.
Then changed the error reporting on php.ini files. Apache restart with sudo service apache2 restart. Check http://localhost/ , still getting  the default "It works" page. Moving on..

2. The vhosts not working :
The first obvious error was that none of the virtual hosts were working. After looking through the apache.conf file in /etc/apache2 I found the line :
Include sites-enabled/*.conf
This made it mandatory for virtual hosts files to have *.conf ending to be read as legit files. To correct this error, it is better to delete all links in sites-enabled/ folder. Then append .conf to the vhosts file inside sites-available/. Then enable each site one by one. Apache reload with sudo service apache2 reload Check http://localhost/ . New error : 403 permission denied. But I corrected the run user to the file owner, let's check the logs

3. The authz issue :
Going through the logs, error coming up was
[Sun Nov 03 18:02:27.790498 2013] [authz_core:error] [pid 5530] [client 127.0.0.1:50046] AH01630: client denied by server configuration: /home/vibhav/public_html/
So apparently, the line "allow from all" in vhosts was not working as it was working before. I went to the upgrading document of apache and found that some things have changed her. Instead of
order allow, deny
allow from all
The new configuration needed
Require all granted
 Do a sudo service apache2 reload again and head to http://localhost/ . It's all working.

This worked for me. If this is not all, please check out http://httpd.apache.org/docs/2.4/upgrading.html for the official upgrade documentation. If you are still having problems, please mention it in comments below.

Friday, June 21, 2013

Consciousness after resurrection

What if a dead person actually comes alive? What if some day a scientist is able to reboot the human body after it is dead. Will the resurrected person be like the normal person he was? What shall be the consequences on his physical and mental condition? Let's delve into the mind of a resurrected person.
Resurrection is an existing concept in movies and TV serials. In the practical world, however, it is simply impossible just because it has not been done ever. There might be a scientific theory behind that. For now, I decide not to believe in this statement. Let's consider a scenario where the technology is advanced enough to be able to resurrect a dead man. The concept is no longer far-fetched given that complex brain surgery is already done on animals. Stem cells and genetic research are taking us into a domain which was earlier attributed to the meta-physical. I have a belief it is not long when doctors shall be able to resurrect a dead man after creating the damaged or missing organs.

The human body is called alive when the brain (nervous system) and the heart (circulatory system) is in sync relying on each other for their functioning. A healthy person shall be one in which this relationship of heart and brain is able to drive the respiratory, digestive and excretory systems. The nervous system makes sure that the involuntary actions of lungs, heart and kidneys go on while it is these systems that keep the nervous system alive. When a person dies, this dependence breaks due to damage on one these parts, rest of the systems break down and the human is declared dead. In our situation, doctors shall have to repair the damages body parts that resulted in death (Almost every organ but brain can now be transplanted). They shall be able to then restart the symbiotic process of circulatory and nervous systems. The person now comes alive!
The brain that solves mysteries of the universe fails to understand itself.
Note that the person was dead a moment ago. Will he retain the memories? No, a brain is a set of neurons which are saving memories in electrical impulses. It needs continuous energy to sustain the memories even for the most basic system tasks. Much like a computer RAM, all it's data are gone the moment power goes off. The electrical impulses die away and the brain is mostly static. The brain memories are not like the magnetic dipoles on a magnetic disk. It won't retain any memory of the previous 'life session'. Here we make an assumption, we hereafter belief that upon resurrection, the brain shall still be able to sustain the involuntary life actions of respiration, blood circulation and digestion. Or we can assume that these actions are still being controlled by an artificial life support system. Now that the blood circulation restarted, the brain started functioning. But, there are no memories. I do not mean the memory loss as in the fictions and movies but a simple brain format (like the formatting of a computer disk). We just assume that the BIOS (involuntary life tasks) of this computer (brain) is separately installed.
PSM V26 D764 Longitudinal section through the center of the brainAt t=0, reboot finished, blood circulation in brain is normal and reached a steady state.
The brain is static, no neuron activities, and extremely low level of feelings. Consciousness does not exist now. By consciousness, I mean a state of 'brain' when one part of it is able to assess its existence, or it is able to generate impulses in response to another set of impulses. This way it think what kind of thought is going on. This state of consciousness, or a general term called feeling, is completely absent in the subject. All over the bodies, neuron sensors have just come alive and have started responding to the external environment. These shall send electrical signals to the brain and enliven the static neurons of the brain. The brain shall now start 'working'. What will it be thinking?

The model of the brain we shall be using in this discussion: Let us consider the brain as a neural network, the one from computer science, a vast array of independent neurons sending each other signals based on the signals they receive. The only difference is that this one is sending analog signals instead of binary and the back-propagation mechanism is much more multi-directional giving a much faster computing power (It is worth noting that a neural network in comp. science does not compute, it receives values as signals and tries to adapt itself to the signal thus recognizing patterns and then it starts predicting the next value).
Neuron in tissue cultureWhenever this neural network receives a signal, it processes it and stores it. The next signal might be of a similar nature. Then the pattern has been recognized and is running in the cache (the currently active thought). Now, when the third signal arrives, the brain predicts the signal. If the received pattern is similar to what the predicted pattern, it releases some chemical to feel good and another part of the brain might start a small impulse to record this feeling, As an example, on touching four parts on the wall, a brain can recognize the fact that it is a plain two-dimensional rigid obstruction, it predicts the sense of touch when the fingers touch new part of the wall and this further strengthens the belief or the recording impulse that it is indeed a wall. This is how the predicting and object creating operates in our model of the human brain. The feeling of curiosity is propelled by the fact that brain loves repeated signals. The feel-good chemical released during the formation of a new memory has already taught the brain to learn new things. Over time, this feeling is often suppressed by thoughts more relevant to the new memory in question or just that this feeling becomes far less than many other feelings.
Back to the subject: So our neural network has just started receiving the starting signals. They shall start storing it in the neuron impulses. A few of these signals shall remain on the brain as a memory of these patterns. The person will start to decipher the signals. Based on the signals, he shall start to construct a model of the world around him. He may take time to open his eyes. He shall perhaps keep his eyes closed with no reason to open his eyes.

The person's back can sense the feel of the soft thing he is lying on, he can feel the heat of the atmosphere, the eyes has not yet opened but the light beyond has already struck chords on the cones of neurons on the retina. The fingers of his hand seem to come I contact with something. The sensitive fingertips are never late to send the sense of touch. After creating a mind model of the material in hand, the curious brain wants to get hold of this texture which is soft. If only he could just grab a little more of the material, he could discover this new pattern, this new thing, a new entity in his brain. And then something weird happens, a sense goes through his arm and the hand moves, the fingers curl on the object. Fingers move by his will, yes he can move, he has a hand which moves at his will. The feeling part of the brain gets excited, it releases the feel-good chemical into the nearby blood-vessels which makes the whole brain get excited, it makes the whole brain take an extra effort in their work. The fingers have sent a new signal, he is now holding a piece of his own bed-sheet in his hand. It feels good!! I have an arm with wrist and fingers at my command, it feels good. The excitement chemical is high in the blood around the brain, This is specially high in the area around the part which controls the hand and the finger tips. It no longer wants to restrain itself. The response from the brain is high this time. The consciousness has still not fully understood the idea of a limb. It has no control over it. The brain at his free will commands the hand to move in a random direction. The person flings his arm. This is useful as it helps him understand himself.
You might be thinking the subject is much like a baby who has just came out of womb, swinging arms and legs around, looking around curiously amazed, innocence and curiosity are visible on the face. The situation must be actually quite similar. The difference however, is more interesting. Our subject is a grown up man. His needs might be limited to food and warmth like an infant but his limbs and body are better formed. His unpredictable curious activities can be destructive like a child with a larger scale. The subject might need to be kept in constraint, may be hand-cuffed. I am quite sure when a grown up behaves like a child literally, the scene is hardly as cute as in the case of babies.
There is one more difference, our subject is a grown up man/woman. This person shall have fully developed sexual organs and thus have the capability to sense sexual feelings. His/her organs will be capable of the sense of arousal. The subject will not take time in discovering a body part with such an intense sense. The curious brain will like to discover the organs. The person will touch his/her organs and try to understand the mystery of intense sense of touch. It is safe to assume the person had not seen or observed the existence of two types of human body. He might just be too busy with his existence and understanding the new and varied stimuli he is suddenly exposed to. He shall understand more when he gains mental age and observe human society.
The person shall slowly learn to stay calm, feel hungry and understand his surroundings. The mental age of this person is equal to a new born. Unable to speak and communicate, the person shall just lie down and get active on feelings of thirst, hunger, pain etc. To further develop his mental age, he can be forced to situation where he need to be learn to communicate, he shall start to learn to speak like a little child in perhaps the same time period. In a way, it can be really embarrassing for a person to be a grown up with a mental age of a child. Being exposed to conditions where a lot shall be expected of him being a grown up might give him embarrassment or compel him to increase his mental age depending on the view of the world he would had upto that moment.
For the person, the life would be like being born in a grown body without a childhood. The language and analytical skills shall develop with time. It's hard to say the time required for a person to bring his mental age to his chronological age.
What if this is actually possible?
I think that in such an event the person must not be exposed to the plethora of senses around him. To control his senses, he should be kept under a sedative and he should be exposed to a slow and mild surroundings. The person might be kept with his eye covered. Sedatives can be used to keep a large part of his body unconscious. The exposure to senses must be slow like a baby developing in the womb. Like a fetus, he shall slowly embrace the senses and develop a stable life sustaining nervous system before actually feeling his limbs and looking with his eyes.
The exposure to the visible world must be even slower, this grown up man is more powerful than a child and his senses might be a little more developed. The person can be allowed to see the world while a greater part of his body should lay unconscious

Da Vinci Vitruve Luc Viatour colouradjusted crop240Ethics, Morals, religion and stuff!! : If possible, the process shall be the subject of a fierce controversy. The person who is resurrected is no longer the person who died. He is just a new life, a new person. This stuff is way more than sufficient to blow any medical-ethical person out his minds. Personally, I don't think it should be done even for one single time. For first reason, the person is not the same. He is a new born with the body of the dead. Second, the person shall be resurrected for no reason but for scientific experiments. Consciousness, I think is nothing but a collection of neuron impulses, is still the most sacred thing in the universe. It's the thing that drives a lot of species on earth. It gives us the feelings that we live for. It is the sole purpose of a species life. It should not be for experiments. Thirdly, the person shall come alive being the object of an experiment. I cannot even think of the thoughts in the dead person's relatives but the idea of a new person in the body of the dead is itself creepy. The new person without any relationships cannot have a happy life. Perhaps I believe in the epicurean philosophy, the thought itself is very repelling to me.

Friday, May 10, 2013

Displaying PHP file as it is executed, creating data streams in PHP

PHP allows you to display data as it is generated on the server, so while your PHP file is still being executed, the display begins and this feature can be put to some real dynamic uses. I shall cover a few of these applications and let you make more ingenious things.

Here is the code for generating PHP data stream using the flush buffer command.




1. Creating continuous data streams

2. Making synced chat

Tuesday, February 26, 2013

Preventing upstart service from starting on every boot - Things I learned today

Being a curious linux user I have installed a lot of things, server on my system. Apache, tor, ssh, mysql, postgresql are all installed. Due to this reason there were so many ports open on my system that many of them I could't understand. This situation has serious security concerns. Take for example ssh, given the laptop password, anybody on the web can login and access my data without any notification to me. (I am looking for a software which notifies me of any incoming ssh connection. Leave that for some other time.) Today, I found a way to prevent so many daemon to start with the boot up.
PS: I hate installing even a small software for doing the same job as a simple terminal command.

To stop upstart jobs from initialization during boot, one need to override the starting configuration file store in /etc/init/ . In this folder , the specific run level at which these jobs are to be started is specified in their respective ****.conf files. To override any of these jobs , simply create a file with content "manual"  and give it an extension .override.

Example : To prevent mysql server to start :

cd /etc/init       #go to the folder containing start scripts
$ ls - l             # take time to look into the folder
$ sudo echo "manual" > mysql.override  #create a file mysql.override with content "manual"

Done !!

Restart the system and do a quick nmap/nc/telnet to find if the mysql port (3306) is running.
Now, to start the stopped service manually use the service command :

sudo service mysql start       #the service command to start mysql manually

Rollback : If you have disabled your upstart job, but now want to roll back simply delete the file .override (e.g. apache2.override) from the folder /etc/init/ .

System information : The above instructions are tested upon Ubuntu 12.10 but shall be valid for most of the linux distros. If this does not work on your system, mention your system info in the comments as it shall help others.

Tuesday, January 15, 2013

Why upgrade to Gimp 2.8

After a rather long wait, Gimp has finally rolled out the new version 2.8 . This version comes with most of the features I was missing in the previous version. The new Gimp 2.8 has

Single window mode : I am out of words how much I was waiting for this.

Multi-column dialogs : It's just so useful when you are doing some complex designs. and have to use two dialogs at the same time without letting yourself bogged down with multiple windows.

Group Layers: Anybody who worked on Photoshop was missing this here. Thanks to the developers for this nice update.

Detailed release notes : http://www.gimp.org/release-notes/gimp-2.8.html

Monday, January 14, 2013

.htaccess in apache2.2/2.4 on Ubuntu LAMP setup

.htaccess not working after installing Apache

htaccess files don't work on Apache server server by default and anybody who moved from using wamp/xampp to apache encounter this problem.

htaccess is a file which can be placed in the folders of document root and is meant to override apache configurations for that particular folder. It is loaded by apache while serving request i.e. during runtime. htaccess being located inside the document root can be accessed by anybody editing the application and thus pose a security risk by it's ability to override server configuration. Hence, an Apache installation installed with default virtual hosts in /etc/apache2/sites_available/ have htaccess disallowed.

But wait! I have used wamp without any such configuration. Why this mess? If you have any experience with XAMPP or WAMP, you might have noted they allow the htaccess files by default. The reason is that while these two are for development purposes only, Apache on Linux is built for production environments. Hence, it has most of the security arrangements in place by default.

So what should you do?

It is therefore recommended to add the htaccess commands inside a directive tag in the apache configurations. Edit the virtual host file under
/etc/apache2/sites-available/
and replace
Allowoverride None with Allowoverride all . Save the file and reload apache server with

sudo service apache2 reload

Now the .htacces files located in the document folder should start working.

Why not to use .htaccess? What could be problems with .htaccess?

On a production environment, if you have access to the apache configuration files, it's always better to edit apache.conf or virtual-hosts file instead of allowing .htaccess. Why?
It decreases server load, decreases page load time resulting in better user experience. If htaccess is set to allowed and you are serving a request for /scripts/js/jslib/myjavascript.js, the server searches for a .htaccess at each folder i.e. it first searches for /.htaccess, then /scripts/.htaccess ,then /scripts/js/.htaccess ,then /scripts/js/js-lib/.htaccess . This has a direct effect on server load.

How to edit apache configuration instead of allowing .htaccess?

Case: You need to put a .htaccess file in the folder /var/www/master/ to redirect users from example.com to www.example.com. Thus, the contents of your .htaccess should be roughly the following
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

Alternative: Edit the apache virtual host file corresponding to your site and add the following directive instead inside the virtual host tags

<VirtualHost *:80>
 ......
 <Directory /var/www/master/>
  RewriteEngine on
  # if a directory or a file exists, use it directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # otherwise forward it to index.php
  RewriteRule . index.php
 </Directory>
 .....
</VirtualHost>

Reference :
1. http://httpd.apache.org/docs/2.2/howto/htaccess.html#when