Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Feb 042010
 

Turn on content compression in Apache

Answer:

By turning on content compression in Apache, content's transfer size can be reduced for users and hence a faster loading time. However, not all content types can be compressed, e.g. images, videos, we usually only compress text content types, e.g. html, xml, css & js.

Steps:

Add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/xml application/xml application/javascript application/json text/css text/plain
    header set Vary Accept-Encoding

    # Don't compress images - Important for IE caching bug
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    header unset Vary env=dont-vary

</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_deflate is enabled

Feb 022010
 

Check the exit status of a command

Answer:

You can check the exit status of a command by checking the special variable $?

E.g.

# ls
# echo $?
0

# foo
-bash: foo: command not found

# echo $?
127

Non zero (e.g. 127) exit status mean the command failed to execute.