Apache Web Server Administration Cheat Sheet for LinuxA few quick tips and a cheat sheet for Apache web server administration on a Linux based server. Restart services and setup virtual hosts.
This article is part of a series of articles. Please use the links below to navigate between the articles.
- How to Download and Installing Linux Step by Step For Beginners
- Essential Guide to Working with Files in Linux
- Understanding Linux File Permissions and Permission Calculator
- How to Archive, Compress and Extract Files in Linux
- Linux Piping and Redirection Explained
- Hardlinks and Softlinks in Linux Explained With Examples
- How to Create and Use Bash Scripts in Linux
- Data Recovery in Linux - How To Recover Your Data after Drive Failures
- Apache Web Server Administration Cheat Sheet for Linux
- Essential MariaDB and MySql Administration Tips on Linux
- How to Switching from Windows to Linux - A Complete Guide
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:
<VirtualHost 192.168.0.5>>
ServerName virtual.hostname.com
DocumentRoot /usr/www/path/to/files
</VirtualHost>
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 debug 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.