I'm working on a site locally that's just sitting in a folder:


How can I route, with Apache2, that to be like:


Or just something so it's not a sub directory? It's making local development very frustrating.

  • we understand your feeling. But in a site like this it is advised to use good language. – aneeshep Dec 18 '10 at 5:55
  • What if you don't have access to change your apache config files (like shared hosting)? – user11424 Feb 24 '11 at 20:29

You need to do two things, the first is to make an apache2 virtual host that will respond to the domain name given and the port used; so in /etc/apache2/sites-available/tempplace.conf which should be symlinked to /etc/apache2/sites-enabled/000-tempplace you should have something like this:

<VirtualHost tempplace.localhost:80>
    DocumentRoot /www/example1
    ServerName tempplace.localhost

    # Other directives here

Once you have that part you can restart your apache2 server. Next you have to enable a localhost hostname, to do this you edit the file /etc/hosts and add as follows:   localhost.localdomain localhost tempplace.localhost

This effectively adds the tempplace.localhost resolve to your local dns and means that browsing to it will point to localhost. You should then be able to browse your Apache virtual server on your localhost without resorting to different ports.


Let me add some points to In Protest's answer.

1). enable the apache userdir module.

sudo  a2enmod userdir

this will enable apache userdir module. Now you can put the contents of website in ~/public_html/ or whatever inside your home directory.

Note: The default folder is ~/public_html

2). Make necessary changes to /etc/apache2/mods-enabled/userdir.conf.

3). Restart the apache

sudo /etc/init.d/apache2 restart

Now you can access the site by navigating your browser to http://ip-address/~username.

4) Set a virtual host for this site as in In Protest'answer

If you are looking to run php files you need to do one more step

edit the /etc/apache2/mods-enabled/php5.conf and comment the following lines:

<IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off

Then restart the apache.

Thats it. You are done.


Hope this helps. If you face any difficulties feel free to post it here.

  • -1 , This doesn't seem to answer his question at all, which is how to run the site without a leading prefix. I suspect his app could be rewritten to use relative links, but thats another matter. – SpamapS Apr 29 '11 at 15:53
  • yea. That what i said . But this time the the document root will be inside in home directory so that you don't want to give permission to the user to edit /var/www – aneeshep May 2 '11 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.