Learning never exhausts the mind
Home >  Technology > Linux > Apache Administration on Linux

Published 20th July 2010 by

A few quick tips and cheat sheets for administering apache on a Linux server.
Introduction to Linux Series
  1. Installing Linux Step by Step
  2. Linux Tips for Beginners
  3. Beginners guide to Reading and Finding Files in Linux
  4. Using Grep to Search for Text in Linux
  5. Understanding Linux File Permissions
  6. How to Archive, Compress and Extract files in Linux
  7. Linux Piping and Redirection
  8. Linux Hardlinks and Softlinks
  9. How to Create and Use Bash Scripts
  10. Basic Data Recovery in Linux
  11. Apache Administration on Linux
  12. MySql Administration on Linux
  13. Switching from Windows to Linux

Restart Apache on Linux

You can restart the Apache web server by entering the following command:

sudo /etc/init.d/apache2 restart

Change the Apache DocumentRoot

Website configs are stored within /etc/apache2/sites-available/ and a symbolic link is created within /etc/apache2/sites-enabled. Generally you store all your website configs in sites-available and create/remove links in sites-enabled as required.

sudo pico /etc/apache2/sites-available/default

Change the document root (default is /var/www)

Restart Apache for changes to take effect.

Adding Virtual Hosts

To add virtual hosts to Apache, all you need to do is create a config in /etc/apache2/sites-available/.

The config files should look similar to this:

        ServerName virtual.hostname.com
        DocumentRoot /usr/www/path/to/files

To enable the new site run:

sudo a2ensite <config name>

To disable a site run:

sudo a2dissite <config name>

The next thing to do is to enable virtual hosts in your Apache configuration. The simplest way to do this is to create a file called /etc/apache2/conf.d/virtual.conf and include the following content in it:

#  We're running multiple virtual hosts.
NameVirtualHost *

Enable mod_headers on Apache

For customization of HTTP request and response headers, you should enable mod_headers on Apache.

sudo a2enmod headers

Increase PHP File Upload Size

The default PHP installation will restrict you to a maximum of 2 MB however there are many instances this needs to be increased. This can be done by modifying the PHP.ini file.

sudo pico /etc/php5/apache2/php.ini

There are two settings to be changed. Locate and modify the following lines.

upload_max_filesize = 2M
post_max_size = 8M

You will need to restart Apache for changes to take effect.

Installing Xdebug

The Xdebug extension helps you debugging your script by providing a lot of valuable debug information.

This can be quickly installed in Ubuntu using the following command:

sudo aptitude install php5-xdebug

You can verify successful installation by calling:

php -v

If successful you should see something like the following:

PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans

For more information, please see this article which also covers using XDebug to analyse PHP performance.

Tutorial Series

This post is part of the series Introduction to Linux. Use the links below to advance to the next tutorial in the couse, or go back and see the previous in the tutorial series.

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.