sylvertwst Posted October 7, 2008 Share Posted October 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/ Share on other sites More sharing options...
CroNiX Posted October 7, 2008 Share Posted October 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-659475 Share on other sites More sharing options...
trq Posted October 7, 2008 Share Posted October 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-659482 Share on other sites More sharing options...
sylvertwst Posted October 8, 2008 Author Share Posted October 8, 2008 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 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! . 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 Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-659783 Share on other sites More sharing options...
trq Posted October 8, 2008 Share Posted October 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-659838 Share on other sites More sharing options...
steviewdr Posted October 8, 2008 Share Posted October 8, 2008 You can also enable mod_userdir (userdir.conf). -steve Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-659863 Share on other sites More sharing options...
sylvertwst Posted October 8, 2008 Author Share Posted October 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-660100 Share on other sites More sharing options...
trq Posted October 8, 2008 Share Posted October 8, 2008 Ok. Ubuntu should be easy to setup but not as we've done. Firstly, can I see the output of the following two commands? sudo tail /etc/apache2/apache.conf ls -l /etc/apache2/sites-enabled/ Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-660278 Share on other sites More sharing options...
sylvertwst Posted October 9, 2008 Author Share Posted October 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-661076 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 Hmmm, maybe Ubuntu is more different to Debian than I thought. what is the output of.... tail /etc/apache2/httpd.conf ? Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-661335 Share on other sites More sharing options...
DarkWater Posted October 9, 2008 Share Posted October 9, 2008 Thorpe, it's actually just /etc/apache2/apache2.conf Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-661336 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-661346 Share on other sites More sharing options...
sylvertwst Posted October 10, 2008 Author Share Posted October 10, 2008 \o/ thorpe is our king ! ty very much, it works now:D i can finallly start on php. i'm gonna do a stupid guestbook project first, to get the hang of it Quote Link to comment https://forums.phpfreaks.com/topic/127467-solved-change-varwww-to-homeuserfolder/#findComment-661905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.