Setup localhost site in apache?

89,224

Solution 1

I solved this by following this guide. A really neat solution which enables you to create a folder in your specified "Sites"-folder and then access it without having to add a sites-available for every new site.

THE guide -> http://css.dzone.com/articles/drop-folder-directory-and-have

Solution 2

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

Solution 3

Just to add to the other answers here, the way I have configured such behaviour is with symlinks... Seems to work fine. It is very easy to do, and does not require any configuration files.

sudo ln -s ~/path/to/yoursite/ /var/www/html/yoursite

The last portion of the above may be different for you. The above is what I use in Linux Mint 17. The '/var/www/html/' directory is the default apache "site" folder.

So yeah, for anyone who is looking for a clean, easy method to map a site without actually placing their site's directory in the default apache folder, there ya go.

Note: I am not sure if the above is appropriate for production environments, but for local development, it seems to be okay. The reason I am unsure is because the symlink carries the permissions of the folder in the home directory, which is (most likely) "owned" by the user. If you need to, you can obviously change that to the more secure 'root' like the apache directory, but I leave mine alone as I am just using this in a development environment.

Share:
89,224

Related videos on Youtube

Pewter
Author by

Pewter

Updated on September 18, 2022

Comments

  • Pewter
    Pewter over 1 year

    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!

  • Pewter
    Pewter over 10 years
    Thank you for your answer. I used som illegal chars in my question which resulted in som text falling out. I have updated my question now. Please refer to it again and see if there is something else I have to do to get it to work. Regards!
  • Evenbit GmbH
    Evenbit GmbH over 10 years
    Well basically it stays the same. I have edited the answer to mach your wishes :)
  • arqam
    arqam over 4 years
    Worked for me!!