Configure VirtualHost with Bitnami Lamp Stack on localhost


Bitnami Lamp Stack Apache Server Configuration with VirtualHost on Ubuntu

Published on by nick

Tags: lampstack, virtualhost, bitnami

As is the case with many of my endeavors, I ran into some trouble setting up Virtual Hosts on my Apache server. I know, I know, most web server configurations are slightly different; but it seems mine are always much different. I thought using a simple server package like Lamp Stack from Bitnami would be a straight forward setup. I may have been wrong... Let's explore a little of what I'm talking about. Thanks to the author of this article for starting points.

This process can be broken down into three sections:

If you aren't using a basic Lampstack setup, I would consider the article referenced above and following those instructions, which take you through additional steps: configuring ports.conf, sites-available, and running the a2ensite utility.

The first thing you will need to do is edit your httpd.conf file. This can found in your Lampstack directory, eg, /opt/lampstack/apache2. You will want to check a few things in this file. First, look over the ServerRoot, ServerName, the Listen port, the DocumentRoot and any other settings you might need to confirm or become familiar with. In many cases, the port your server listens on will be 80, but if you are running another server or web application, this port might be in use. In my case, I usually configure Apache to listen on another port, so it's out of the way. My bits that might be of concern are as follows (note that they appear in different locations in the file and aren't listed like this next to one another):

ServerRoot /opt/lampstack/apache2
. . .
Listen 8080
. . .
ServerName localhost:8080
. . .
DocumentRoot /opt/lampstack/apache2/htdocs

Finally, before moving on to the next section, be sure to uncomment this line towards the bottom of your httpd.conf file:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Next we'll need to actually edit the file we are including in the main configuration file. Using your favorite editor, open up the virtual hosts file httpd-vhosts.conf and begin your configuration:

sudo vim /opt/lampstack/apache2/conf/extra/httpd-vhosts.conf

This is where you'll need to add your <VirtualHost> directive configuration. Note that I've used some of the fields but not others. They aren't all required, so the ones I've decided to not use are commented out:

#NameVirtualHost *:9090 # this is deprecated in newer versions of apache

# VirtualHost configuration:

<VirtualHost *:8080>
    #ServerAdmin
    DocumentRoot "/opt/lampstack/apache2/htdocs"
    ServerName localhost
    #ServerAlias
    #ErrorLog
    #CustomLog
</VirtualHost>

Listen 9090

<VirtualHost *:9090>
    #ServerAdmin
    DocumentRoot "/home/user/dev/mysite"
    ServerName mysite

    <Directory "/home/user/dev/mysite">
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        #for newer versions of Apache, see note below
        Order allow,deny
        Allow from all
    </Directory>
    #ErrorLog
    #CustomLog
</VirtualHost>

Please note: In Apache 2.4 and newer, Require all granted should be used instead of Order allow,deny and Allow from all.

Also note that I've added the default configuration here, as well. This part is not, in my opinion, trivial and tripped me up a bit until I read an article indicating that it was required.

Finally, the third piece of this puzzle is to tell your machine that localhost or 127.0.0.1 also points to your virtual host, mysite. To do this, you must edit your hosts file. In Windows this can be found in the system32/etc directory and in Linux, etc directory:

127.0.0.1 mysite

Restart Apache and you should be good to go. Check out mysite:9090 in your browser and you should see you files hosted from the DocumentRoot location.

Comments

Comments powered by Disqus

 Blog Search

  Popular Tags

django, ubuntu, mod_wsgi, apache, authentication, python, tls, linux, forms, ssl, virtualenv, dell, uwsgi, bash, nginx, raid, customer-service, centurylink, ux, software-companies, rais, form, centos, password, certificates, tinymce, mdadm, dual-boot, file-server, virtualhost, gluster, IT, blog, get, networking, piplight, distributed-file-system, big companies, bitnami, cygwin, windows, samba, scripting, pygments, post, programming-language, ui, lampstack, outsourcing, isp, security, usabillity, provision, php, shared-hosting, netflix, git, flatpages, syntax-highlighting, virtualbox, hg, redirect, usability, prg, acls, change-password, complex, view tags...

 Questions/Comments?

Drop me a line... [email protected]
Follow me on Twitter... @nicorellius
Share on Facebook...