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.

Remove default Debian/Ubuntu default Apache welcome page

Answer:

To remove the Apache default welcome page under Debian/Ubuntu,

1. Remove the welcome page configuration

# a2dissite default

2. Restart Apache

# sudo /etc/init.d/apache2 restart 

That's all.

How to prevent PHP script from running in Apache

Answer:

If you have a PHP script and want it run under in command line only, not in the web server context, you can use the following method.

<?php

if ( php_sapi_name() != "cli" ) {
    print "This script must be run from the command line\n";
    exit();
}

Enable Server Side Includes in Apache

Answer:

Server Side Includes (SSI) is a simple mechanism that allow you to add dynamic elements into your HTML file without playing with complicated scripting languages such as PHP or Perl.

To enable it under Apache, add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_include.c>

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Now all yout .shtml files be will parsed and SSI related tags will be evaluated.

To see what SSI directives you can use, check out the following document:

http://httpd.apache.org/docs/2.2/mod/mod_include.html

How to check which mime types are supported by your Debian/Ubuntu

Answer:

The /etc/mime.types file is the system-wide rules which defined for mapping filename suffices to mime types. Your Apache on Debian based Linux will read this file and set the correct Content-type header for these files when serving to users.

# cat /etc/mime.types

Turn on expire headers in Apache

Answer:

By turning on the expire headers, browser will cache the files serving from Apache more aggressively, so as to reduce traffic loading to the Apache web server.

Steps:

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

<IfModule mod_expires.c>
    ExpiresActive On

    # Cache all files for 2 weeks after access (A).
    ExpiresDefault A1209600

    # Do not cache dynamically generated pages.
    ExpiresByType text/html A1
</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_expires is enabled