How To Configure Apache2 on Linux and Host Your Own Website


Virtual Hosting allows Apache to host more than one website on a single server. This is how sharing hosting works. It’s an ideal way to develop multiple web projects on the same machine.

This exercise assumes you have Apache2 running on Linux. I’m currently running Apache/2.2.17 on Ubuntu 11.04. To see what version of Apache you have installed, run apache2 -v from your terminal.

Configure Apache2 virtual hosting

Your web root folder is /var/www/, which is protected, so for development purposes, let’s move it to where you won’t need root privileges to access it, e.g., /home/matt/www/ (In this example, I’m using matt—replace this with your user directory)

In order to tell apache where we want /www/, we’ll need to edit the read-only file default in /etc/apache2/sites-available/:

  1. Open your terminal and run gksudo
  2. In the ‘Run program’ dialog box that opens, enter nautilus
  3. In the window that opens, navigate to /etc/apache2/sites-available in the file system, and edit the default file with a text editor like Gedit.
  4. Replace the 2 instances of /var/www/ with /home/matt/www/ and save.
  5. Reload the Apache configurations from your terminal by running sudo service apache2 reload
  6. http://localhost/ should now point to your new /www/ directory. Test this with a simple index.html or .php file.

Host a new site in Apache2

  1. Open your terminal and run cd /etc/apache2/.
  2. Then run cd sites-available.
  3. Create a new file called ‘mynewsite’: run sudo cp default mynewsite.
  4. Edit mynewsite as root and run: sudo nano mynewsite. If you prefer another text editor such as Gedit, you can run  sudo gedit mynewsite.
  5. When mynewsite opens in your text editor, replace what’s there with:<VirtualHost *:80>
    Options -MultiViews
    DocumentRoot /home/matt/www/projects/mynewsite/public_html
    <Directory /home/matt/www/projects/mynewsite/public_html/ >
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    allow from all

    Be sure to edit the path /home/matt/www/projects/mynewsite/public_html/ both for DocumentRoot and for Directory to point to where you’d like to keep your projects.

  6. Save and close mynewsite – your new website configuration is ready.
  7. To set up the directories and subdirectories for your projects all at once, return to your home directory by running cd . Then run mkdir -p www/projects/mynewsite/public_html .
  8. Now, enable the configuration we created earlier by running: sudo a2ensite mynewsite . (a2 = Apache2 and en = enable).
  9. Tell your machine to listen for the address we chose for your site by running: sudo gedit /etc/hosts . When your text editor opens the file, add the name of the address next to localhost on the same line, like so:    localhost 
  10. Save the file and exit your text editor.
  11. Reload the Apache configuration: sudo service apache2 reload .
  12. Load in your browser.

You now run Apache shared hosting!


Installing the LAMP Stack on Ubuntu 11.04 – Natty Narwhal

How to install the LAMP stack

Once you’ve installed Ubuntu, you’ll need Apache MySQL, and PHP to complete the stack. We’ll install phpmyadmin while we’re at it.

For this example I installed LAMP using Ubuntu 11.04 (Natty Narwhal), but this example  should work on many previous releases; I can’t say how far back.

  1. Open your terminal.
  2. Run sudo apt-get install apache2 mysql-server php5 phpmyadmin .
  3. Set passwords when prompted.
  4. Run sudo service apache2 restart.
  5. Go to http://localhost/ in your favorite browser. When you see Apache’s “It works” page, Apache is installed. If you get the following error:
    ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName

    simply edit the httpd.conf file by

    1. running: sudo gedit /etc/apache2/httpd.conf
    2. Add the following line to the file (which will be blank be default):
      ServerName localhost
  6. Go to http://localhost/phpmyadmin. If you don’t see phpMyAdmin’s welcome page, create a symlink by running: sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf and then reload Apache: sudo service apache2 reload . You should now see phpMyAdmin’s Welcome page.
  7. Have a sandwich.

Once LAMP is installed and running, you’ll probably want to configure Apache virtual hosting so you can begin using your new development server.

Goodbye Windows, Hello Linux.

Well I finally did it.

Sure, it’s a dual-boot, but I’m committed to using Linux only on my main laptop.

Once I get Photoshop working through VirtualBox—which might require a bit more RAM—I’ll kiss the windows partition goodbye. I don’t have time to shift to GIMP right now, so I’ll be keeping Photoshop in my toolkit for now.

The recent version of Ubuntu, 11.04 (Natty Narwhal) loads the Unity user interface instead of GNOME Shell as default, which was a bit of a turn off for me. Ubuntu 10,10 (Maverick Meerkat) using GNOME was a nice introduction to Linux for me last year; I find GNOME to be much more intuitive.

Thankfully, reverting to the Gnome environment in Natty is as simple as logging out and selecting it as your GUI.

Aside from the Photoshop inconvenience, it looks like I’ll also need to load Magic Jack through VirtualBox as well.

Hey Adobe: 2011 called, they want their Photoshop back.

Goodbye Gates, hello Torvalds.