Apache2 Web Development – Setup Localhost Site in Apache

Apache2web-development

I've been searching for weeks on how to setup the localhost enviroment on ubuntu without any good solutions.

This is what I want to achieve:

I want to have My root folder as such /home/'username'/Sites/'projectname.pl' or /home/'username'/Sites/pl/'projectname'/public (or simular)

When accessing my localhost i don't wanna have to write localhost/'projectname'/public (or whatnot) I would like to be able to access the project just by typing http://'projectname'.pl

I know this is achievable on the apache server on OSX but I haven't been able to find any guides to achieve this on my Ubuntu-machine.

I would really be grateful of any help, and I really hope it's possible.

Regards!

Best Answer

You can set up your vhosts in

/etc/apache2/sites-available

For every vhost you like to have make a conf file in this directory. In the vhost configuration you can set your document root. The name of the file must end with .conf

So for example: /etc/apache2/sites-available/projectname.conf:

<VirtualHost *:80>
  ServerName projectname.pl

  DocumentRoot "/home/Sites/projectname/public"

</VirtualHost>

Now enable your site with:

sudo a2ensite projectname

And restart apache:

sudo /etc/init.d/apache2 restart

Then edit your /etc/hosts file.

Just paste the line:

127.0.0.1 projectname.pl

on the end.

Now you can access your site with http://projectname.pl