Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a development machine with lamp setup. Now to add virtual hosts this is what I do currently:

  1. add a virtual host file <virtualhost> ... </virtualhost> in the /etc/apache2/sites-available
  2. add the virtual host using sudo a2ensite <host-file>
  3. sudo service apache2 restart

This works fine and I get the desired site up and running on my localhost.

Now the problem is that every time I have to make some change to the configuration file for a site, I have to sudo to edit the configuration file.

What I was wondering is if it is possible to specify some directory in my home folder where apache can look for configuration files for the sites instead of the default sites-enabled directory.

share|improve this question
    
What exactly is your problem? Is it that you want the vhost configs to be loaded from a different directory or that you have to use sudo to edit the config files? The latter is because of file permissions for security reasons. If it's a development machine, and you're not concerned with file system security, then you can just change the permissions so you don't need to use sudo. If you just want easier access to the sites-available folder, then just create a symbolic link. –  Lèse majesté Dec 26 '11 at 14:04
    
will creating a symbolic link remove the need for sudo access? (i am a linux newbie) :P –  Ankit Dec 26 '11 at 14:41
add comment

migrated from webmasters.stackexchange.com Dec 26 '11 at 19:38

This question came from our site for pro webmasters.

2 Answers

up vote 2 down vote accepted

You can create a directory wherever you want and make the permissions to fit like you want.

In Apache conf (/etc/apache2/apache2.conf) you can include the config files in that directory

Include /path/to/dir/*.conf

Apache will have to be restarted when a configuration change has occured even if you choose this solution.

Also note, that the files in there will be included when apache is restarted - there is no need for a2ensite, and nor can you disable the config files with a2dissite. The way to disable a config file included this way would be to remove or change the extension to something else than .conf.

Remember to take the possible risks into account. You will need to give sudo access, but you can give sudo access to "/etc/init.d/apache2 reload" - the reload parameter will do a configtest before restarting the httpd. If the configtest fails, it will not restart Apache.

I am assuming you run Debian or Ubunbu.

share|improve this answer
    
thanks fbh. It did what I wanted. I just need to configure the sudo access restriction to the service apache thing. Thanks a lot. –  Ankit Dec 27 '11 at 5:22
    
This probably doesn't matter as much on a dev server, but Apache has a graceful restart method that will delay restart of each thread until it finishes its current request. If you have other stuff running on Apache and other users to consider, it may be preferable to use the graceful restart function. –  Lèse majesté Dec 27 '11 at 5:40
    
reload does a config test, if it fails it does nothing, if it is OK it invokes graceful restart. –  Frands Hansen Dec 27 '11 at 9:04
add comment

You COULD change the directory where Apache looks for its configuration files in httpd.conf file or you COULD change the permissions of the file. But the question is do you really want to do that??

It is protected for a reason you know. And you being so lazy (i.e. not willing to sudo) is not a very good reason :P

Or do you have to pay for every character you enter on your keyboard?

share|improve this answer
    
hehe :P, no i am not being lazy. its just that the development machine is used by several people. Sometimes I get someone from outside to work on the machine. I don't want to give them the sudo access –  Ankit Dec 26 '11 at 14:43
    
If you change the directory in httpd.conf, will a2ensite/a2dissite still work? –  Lèse majesté Dec 26 '11 at 14:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.