Where technology and gadgets come together and play

Apache Administration on Linux

By on in Linux

398 words, estimated reading time 2 minutes.

Introduction to Linux Series
  1. Linux Tips for Beginners
  2. Beginners guide to Reading and Finding Files in Linux
  3. Using Grep to Search for Text in Linux
  4. Understanding Linux File Permissions
  5. How to Archive, Compress and Extract files in Linux
  6. Linux Piping and Redirection
  7. Linux Hardlinks and Softlinks
  8. Basic Data Recovery in Linux
  9. Essential Guide to Working with Files in Linux
  10. Apache Administration on Linux
  11. MySql Administration on Linux

A few quick tips and cheat sheets for administering apache on a Linux server.

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.

Last updated on: Saturday 17th June 2017



Have a question or suggestion? Please leave a comment to start the discussion.


Leave a Reply

Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Your email address will not be published.