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.
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 </VirtualHost>
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:
127.0.0.1 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
2). Make necessary changes to
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
/etc/apache2/mods-enabled/php5.conf and comment the following lines:
<IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule>
Then restart the apache.
Thats it. You are done.
Hope this helps. If you face any difficulties feel free to post it here.