Category Archives: apache web development virtual server

Google PageSpeed Apache Module on Ubuntu Server

From Adminbuntu, Everything for the Ubuntu Server Administrator

This is an excerpt from Adminbuntu, a site for Ubuntu Server administrators:

PageSpeed speeds up your website and reduces page load time. The PageSpeed Apache module automatically applies web performance best practices to pages and assets like CSS, JavaScript and images, without requiring site modification.

PageSpeed Project Page:


Determine Whether 32-bit or 64-bit Ubuntu Server is Installed

if [[ `uname -a` == *_64* ]] ; then echo '64-bit' ; else echo '32-bit' ; fi

Download the PageSpeed Apache Module

  • Using your web browser, navigate to
  • Look on the right side of the page, under Latest Stable Version and right-click on either the 32-bit or 64-bit .deb package (based on whether you are running 32-bit or 64-bit Ubuntu Server. Select Copy Link Address to get the download link in your clipboard.
    In your server’s terminal use wget to download the module.

This this example, the link for the 32-bit .deb file is


Install the PageSpeed Apache Module

sudo dpkg -i mod-pagespeed-*.deb
sudo apt-get -f install
sudo service apache2 restart

Test Installation

You can verify that the PageSpeed module is installed and enabled with:

[[ -a '/etc/apache2/mods-enabled/pagespeed.conf' ]] ; then echo 'pagespeed is enabled' ; else echo 'pagespeed is not enabled' ; fi

Flushing PageSpeed Server-Side Cache

When developing web pages with PageSpeed enabled, it is sometimes necessary to flush the server’s PageSpeed cache to get the system to reload CSS or JavaScript files that have been updated before the cache lifetime expires.

To do this, touch the file cache.flush:

sudo touch /var/cache/mod_pagespeed/cache.flush

XAMPP on Mac OSX with Virtual Hosts

XAMPP is an all-in-one LAMP development solution for multiple platforms. I use Linux on my main computer and OSX for my laptop.

I’ve selected XAMPP to provide the LAMP environment on my Mac. It is free, in on-going development and works well.

Because I have several projects in development at once, I need to be able to quickly update my Mac with the current state of a project and then develop and test. Subversion is part of that equation and Komodo IDE is too. Setting up LAMP on Linux is a snap, but installing everything on the Mac, even with MacPorts would be tedious. There are a few pre-packaged solutions, including XAMPP, MAMP and Zend Server. I chose XAMPP after a little research and it has worked well for me.

The Apache virtual server does not come enabled by default, so a little setup is needed.

Folder for virtual websites

Create the folder “www” in your home directory, this example is in Terminal:

cd ~
mkdir www

This is the folder where you will place each of the virtual site directories. You could just as well put this somewhere else, but a “www” directory here makes sense to me.


Add the following to /Applications/XAMPP/etc/httpd.conf

	Options Indexes FollowSymLinks ExecCGI Includes
	AllowOverride All
	Order allow,deny
	Allow from all

In the above you will need to substitute your username for “yourusername”. This simply sets some Apache settings for the folder where your virtual sites will be.

In this same file find:

# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

…and un-rem out the Include line. This enables virtual hosting. Yay!


For each website, add a code block to /Applications/XAMPP/etc/extra/http-vhosts.conf

    DocumentRoot "/Users/yourusername/www/"
    ErrorLog "/Users/yourusername/www/"
    CustomLog "/Users/yourusername/www/" common

In the above, just follow the same pattern I’ve shown for this example site. Don’t vary from this unless you want to do some research and testing. You can see I place a “public” folder insite the top directory for a particular virtual site – put your web documents to serve here.

hosts file

Edit your /etc/hosts file to add “” (your version of this) to a line starting with “” like this:

Restart Apache

Using the XAMPP control stop and re-start Apache.


Setting up multiple virtual servers on Apache for web development

I like to develop and test on my local machine and then to upload to the live website server when testing is completed. A little problem I’ve experienced is that my local Apache server only has one IP address and one website root. I guess this is not so much a “problem” but a typical condition.

With only one web server, I cannot test more than one website at a time unless I put each site in a sub directory in the web root. This actually works fine except that I am then forced to use relative path names in the files on the site, which can make for more convoluted logic in some cases and make it more difficult to share common code throughout the site.

In any case, I’d like multiple web servers to test with. I could use separate machines, but that would be a waste of resources and be awkward. It is possible to run multiple instances of Apache, but that would not solve name resolution and would not gain any benefits. I’d like the system to be logical and easily extensible so I can add more sites as required.

The solution I found is to keep a single IP address and a single Apache web server. I just need to resolve more than one URL to my single existing IP address and then have Apache (listening on port 80 as usual) have multiple virtual servers and take use the correct directory for a given web site name.

There are two steps to this solution. Name resolution and creating virtual servers.

Step One: Name Resolution

Usually name resolution is done by a DNS server. This server takes a URL like “” and returns an IP number (the Internet Protocol address is actually a number, but we humans find numbers more difficult to remember than text addresses). In addition to the DNS server, the operating system has a text file that can be used to resolve URLs.

I need my operating system (Linux in my case) to resolve URLs that I specify to my machine’s IP number. This is very easy. I just need to edit the file called “/etc/hosts” to add the names I want to resolve. In this file I found an entry for “localhost” which is standard name for the default Apache web server on a local machine. The entry was: localhost

As my machine came, typing “http://localhost” into a web browser would serve up documents in the standard web server on the machine. So I added a couple of lines to the hosts file so this part of it no read: localhost

I needed to be root to be able to edit and save the hosts file.

Step Two: Setting up a Virtual Server

I found that Apache will handle virtual servers easily. You just need to modify one setup file called “\etc\apache2\httpd.conf”.

I found the section for virtual hosts in httpd.conf and added a few more lines. I read about virtual hosting on the Apache site. I learned that the first virtual host that is specified is used by default in case the URL is not resolved by Apache. I wanted to use the existing directory in this case. I added the following lines to the httpd.conf file:

DocumentRoot /home/andrewault/public_html/

DocumentRoot /home/andrewault/public_html/

DocumentRoot /home/andrewault/public_html/

The first block of code makes the existing server the default virtual server. The next two blocks each add a new virtual server. Note that I use the target URL except that instead of “www” I use”my”. This allows be to keep the same name and keep my system organized.

Notes: You have to restart Apache for these changes to be effected. I just stopped and restarted the Apache daemon, but you could just restart the computer. Also, as with the hosts file, you need to be root to edit the httpd.conf file.


Apache Documentation for Name-based Virtural Servers