Jump to content

[SOLVED] change varwww to homeuserfolder


sylvertwst

Recommended Posts

hello all. i found this on the internet, that allows the apache server to folders in the home folder as domains.

 

# Based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT!  READ ME!
# In the VirtualDocumentRoot below, change USER to match YOUR USERNAME
#
# What this file does:
# Configure Apache so that when you browse the local URL http://DOMAIN.localhost/
# Apache will use the siteroot path /home/USER/workspace/DOMAIN/
# Remember to add your new DOMAIN.localhost domain to /etc/hosts for 127.0.0.1

<VirtualHost *>
        ServerName localhost
        ServerAlias localhost *.localhost
        VirtualDocumentRoot /home/USER/workspace/%1/
</VirtualHost>

 

I put a index.php file just to test in /workspace/folder/  and went to folder.localhost/index.php in firefox, but it fails to show the right document. i understand that by default it is the /var/www/ folder that is parsed by the server, is there any way to change it and add the /home/user/workspace/folder path to be parsed?

 

tyvm

Sylvertwyst (first post ...yea, i'm new here!)

 

EDIT: i just thought i'd mention i'm new to linux and new to php as a whole as well. i just set up my lamp about 30 mins ago

Link to comment
Share on other sites

My settings for a vhost:

<VirtualHost *>
    DocumentRoot /Apache/htdocs/CI163/
    ErrorLog /Apache/htdocs/CI163/error_log

ServerName ci.localhost
ServerAlias ci
ServerAdmin blah@myblah.com

<Directory />
	Options FollowSymLinks
	AllowOverride None
</Directory>
</VirtualHost>

this lets me access (my codeignitor site) using "ci.localhost".  Not sure if you need VirtualDocumentRoot....  I just use DocumentRoot as you can see.

Link to comment
Share on other sites

I put a index.php file just to test in /workspace/folder/  and went to folder.localhost/index.php in firefox, but it fails to show the right document.

 

/workspace refers to a directory called workspace within your root / directory, is this where you placed the file? This isn't the location you defined within the VirtualDocumentRoot directive.

 

If not....

 

Did you replace USER with your username?

Did you add an entry to your /etc/hosts file as suggested?

Did you restart apache after making these changes?

 

On a side note:

 

Do you really need to be using VirtualDocumentRoot? This isn't usually required unless you are hosting many multiple websites that need to be added / removed without restarting apache. ie; Your a hosting provider. Most people (as developers) will get by with a few simple virtual hosts.

Link to comment
Share on other sites

i did replace USER and i did the suggested changes to /etc/hosts . what i get when surfing to folder.localhost is the html file "it works" also found in my /var/www/ folder. but thats not what i was expecting :P

 

this is a script/config/ whatever you wanna call it i found on the internet as is. i have no experience with configuring apache whatsoever. This just made me realise that i might be able to parse documents from a path in my home folder, instead of getting root acces to /var/www/ all the time.

 

if you have a better solution in mind, i'm all ears! :D. all i really need is an easily accesible path to place my php documents in while working on a project in <insert your php IDE of preference>.

 

@CroNix i tried replacing VirtualDocumentRoot with DocumentRoot, but i dont have any visible results  ???

 

thanks for all responses

 

EDIT: looking a lil further, i notice many users coming up with questions regarding the user permissions, and you suggest adding priviliges to read/write in /var/www/ . if my own solution is not found or not possible i will indeed do that, but i would like to attempt doing it my way still. it just seems much more convenient to just place a projet you are working on in your home folder. am i missing a key element why it is *supposesd* to go in /va/www/ ? scripts will not run? etc. i cant imagine what can go wrong if i just let the parser know to parse another directory path too. but then again, given my experience in php there's not many things i can imagine :P

Link to comment
Share on other sites

If all your looking to do is be able to have your document root within a sub-directory of your home then you really do not need to be playing around with virtualdocumentroot.

 

This virtualhost file should get you going.

 

NameVirtualHost *

<VirtualHost *>
    ServerName bar.localhost
    DocumentRoot /home/YOURUSERNAME/workspace/bar.localhost
    <Directory /home/YOURUSERNAME/workspace/bar.localhost>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/YOURUSERNAME/workspace/bar.localhost>
        Options FollowSymLinks MultiViews
        AllowOverride All 
        Order allow,deny
        allow from all 
        DirectoryIndex index.php
    </Directory>
    ErrorLog /var/log/apache/bar.localhost-error.log
    LogLevel warn
    CustomLog /var/log/apache/bar.localhost-access.log combined
</VirtualHost>

 

Now, if you want to add another host (eg, foo.localhost) you would simply add another

virtualhost directive. eg;

 

[code]
NameVirtualHost *

<VirtualHost *>
    ServerName bar.localhost
    DocumentRoot /home/YOURUSERNAME/workspace/bar.localhost
    <Directory /home/YOURUSERNAME/workspace/bar.localhost>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/YOURUSERNAME/workspace/bar.localhost>
        Options FollowSymLinks MultiViews
        AllowOverride All 
        Order allow,deny
        allow from all 
        DirectoryIndex index.php
    </Directory>
    ErrorLog /var/log/apache/bar.localhost-error.log
    LogLevel warn
    CustomLog /var/log/apache/bar.localhost-access.log combined
</VirtualHost>

<VirtualHost *>
    ServerName foo.localhost
    DocumentRoot /home/YOURUSERNAME/workspace/foo.localhost
    <Directory /home/YOURUSERNAME/workspace/foo.localhost>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/YOURUSERNAME/workspace/foo.localhost>
        Options FollowSymLinks MultiViews
        AllowOverride All 
        Order allow,deny
        allow from all 
        DirectoryIndex index.php
    </Directory>
    ErrorLog /var/log/apache/foo.localhost-error.log
    LogLevel warn
    CustomLog /var/log/apache/foo.localhost-access.log combined
</VirtualHost>

 

Note that your /home/YOURUSERNAME/workspace directory will need another directory for each domain.

 

These directories (and any leading to them) need to have the following permissions....

 

chmod o+rx /directory/path

 

If this doesn't get you going please let us know what distro you are using and where this file is being included into the apache configurations. Remember to restart apache after ANY config changes.

Link to comment
Share on other sites

where this file is being included into the apache configurations

 

... right lol.. i can see how this is important. right now i have the following in httpd.conf:

 

NameVirtualHost *

<VirtualHost *>
    ServerName kb.localhost
    DocumentRoot /home/chaitanya/workspace/kb.localhost
    <Directory /home/chaitanya/workspace/kb.localhost>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/chaitanya/workspace/kb.localhost>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        DirectoryIndex index.php
    </Directory>
    ErrorLog /var/log/apache/kb.localhost-error.log
    LogLevel warn
    CustomLog /var/log/apache/kb.localhost-access.log combined
</VirtualHost>

 

<chaitanya> being my username and </home/chaitanya/workspace/kb.localhost> being a folder that i made.

 

i'm not even sure this all is supposed to go in httpd.conf.

 

this is an error output i get when restarting in terminal:

chaitanya@chaitanya:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2                                               
[Wed Oct 08 20:37:31 2008] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias.
[Wed Oct 08 20:37:31 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
[Wed Oct 08 20:37:41 2008] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias.
[Wed Oct 08 20:37:41 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
                                                                         [ OK ]
chaitanya@chaitanya:~$ 

i am running on ubuntu 8.04 :)

Link to comment
Share on other sites

sudo tail /etc/apache2/apache.conf doesnt exist. lol.

 

output for the other ocmmand is

chaitanya@VoUBU-chaitanya:~$ ls -l /etc/apache2/sites-enabled
total 0
lrwxrwxrwx 1 root root 36 2008-10-09 16:20 000-default -> /etc/apache2/sites-available/default
chaitanya@VoUBU-chaitanya:~$ 

 

 

i just removed everything with --purge and reinstalled. just to have something clean running.

Link to comment
Share on other sites

Thorpe, it's actually just /etc/apache2/apache2.conf

 

Hehe, thats funny, Ive never noticed it on Debian before (thanks to tab completion) but it the same too. Ah well, this should be easy.

 

sylvertwst, heres what you need to do once you've installed everything again.

 

Disable the current default page.

sudo a2dissite default

 

Now, open your /etc/apache2/apache2.conf file and on the line before (which is likely the last line):

 

Include /etc/apache2/sites-enabled/*

 

insert NameVirtualHost, so it will become...

 

NameVirtualHost *
Include /etc/apache2/sites-enabled/*

 

Now create a file called kb.localhost and place it within /etc/apache2/sites-available/ (this all needs to be done as root). Within that file you need to put the VirtualHost config you posted above. eg;

 

<VirtualHost *>
    ServerName kb.localhost
    DocumentRoot /home/chaitanya/workspace/kb.localhost
    <Directory /home/chaitanya/workspace/kb.localhost>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/chaitanya/workspace/kb.localhost>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        DirectoryIndex index.php
    </Directory>
    ErrorLog /var/log/apache/kb.localhost-error.log
    LogLevel warn
    CustomLog /var/log/apache/kb.localhost-access.log combined
</VirtualHost>

 

Now, enable that site.

 

sudo a2ensite kb.localhost
sudo /etc/init.d/apache2 force-reload

 

Add the site to your hosts file:

 

echo "127.0.0.1 kb.localhost" | sudo tee -a /etc/hosts

 

That should be about it. Now, whenever you need to add a new site simply create a new vhost config within /etc/apache2/sites-available/ and repeat the last 3 commands.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.